[Checkins] SVN: gocept.selenium/branches/gotcha-generator/ * use gocept.selenium classes
Godefroid Chapelle
gotcha at bubblenet.be
Tue Jan 4 06:34:33 EST 2011
Log message for revision 119337:
* use gocept.selenium classes
* script asks for layer
* add converthtmltests script generation
* egg entry point
Changed:
U gocept.selenium/branches/gotcha-generator/plonetesting-plone3.cfg
A gocept.selenium/branches/gotcha-generator/scripts.cfg
U gocept.selenium/branches/gotcha-generator/setup.py
A gocept.selenium/branches/gotcha-generator/src/gocept/selenium/scripts/converthtmltests.py
D gocept.selenium/branches/gotcha-generator/src/gocept/selenium/scripts/generatetests.py
A gocept.selenium/branches/gotcha-generator/src/gocept/selenium/scripts/tests/
A gocept.selenium/branches/gotcha-generator/src/gocept/selenium/scripts/tests/__init__.py
A gocept.selenium/branches/gotcha-generator/src/gocept/selenium/scripts/tests/plone3login.html
-=-
Modified: gocept.selenium/branches/gotcha-generator/plonetesting-plone3.cfg
===================================================================
--- gocept.selenium/branches/gotcha-generator/plonetesting-plone3.cfg 2011-01-04 09:33:25 UTC (rev 119336)
+++ gocept.selenium/branches/gotcha-generator/plonetesting-plone3.cfg 2011-01-04 11:34:32 UTC (rev 119337)
@@ -1,10 +1,11 @@
[buildout]
extends = common.cfg
common-zope210.cfg
+ scripts.cfg
flavour = [plonetesting, test_plonetesting]
extensions = mr.developer
sources-dir = devel
-parts += omelette
+parts += omelette scripts
[sources]
plone.testing = svn https://svn.plone.org/svn/plone/plone.testing/branches/3.x
Added: gocept.selenium/branches/gotcha-generator/scripts.cfg
===================================================================
--- gocept.selenium/branches/gotcha-generator/scripts.cfg (rev 0)
+++ gocept.selenium/branches/gotcha-generator/scripts.cfg 2011-01-04 11:34:32 UTC (rev 119337)
@@ -0,0 +1,3 @@
+[scripts]
+recipe = zc.recipe.egg:scripts
+eggs = gocept.selenium [script]
Modified: gocept.selenium/branches/gotcha-generator/setup.py
===================================================================
--- gocept.selenium/branches/gotcha-generator/setup.py 2011-01-04 09:33:25 UTC (rev 119336)
+++ gocept.selenium/branches/gotcha-generator/setup.py 2011-01-04 11:34:32 UTC (rev 119337)
@@ -78,5 +78,13 @@
'PILwoTK',
'plone.app.testing',
],
+ script=[
+ 'elementtree',
+ ],
),
+ entry_points={
+ 'console_scripts': [
+ 'converthtmltests = gocept.selenium.scripts.converthtmltests:main',
+ ],
+ }
)
Copied: gocept.selenium/branches/gotcha-generator/src/gocept/selenium/scripts/converthtmltests.py (from rev 119335, gocept.selenium/branches/gotcha-generator/src/gocept/selenium/scripts/generatetests.py)
===================================================================
--- gocept.selenium/branches/gotcha-generator/src/gocept/selenium/scripts/converthtmltests.py (rev 0)
+++ gocept.selenium/branches/gotcha-generator/src/gocept/selenium/scripts/converthtmltests.py 2011-01-04 11:34:32 UTC (rev 119337)
@@ -0,0 +1,122 @@
+#!/usr/bin/env python
+"""
+Convert HTML selenium tests to gocept.selenium based test cases.
+"""
+
+import re
+import os
+import glob
+from elementtree import HTMLTreeBuilder
+from string import Template
+from optparse import OptionParser
+
+module_template = Template('''\
+import unittest
+
+import gocept.selenium.plonetesting
+import $layer_module
+
+
+class TestAll(gocept.selenium.plonetesting.TestCase):
+
+ layer = $layer
+
+$tests
+
+def test_suite():
+ return unittest.makeSuite(TestAll)
+''')
+
+variable_regexp = re.compile('\$\{(?P<varname>\w*)\}')
+
+method_body_template = Template('''\
+ def test_$testname(self):
+ selenium = self.selenium
+$commands
+''')
+
+
+def formatcommand(command, *args):
+ if not command:
+ return ''
+
+ arguments = []
+ for arg in args:
+ if not arg:
+ continue
+ matched = variable_regexp.match(arg)
+ if matched is None:
+ arguments.append('"%s"' % arg)
+ else:
+ arguments.append("self.getVar('%s')" % matched.group('varname'))
+ return ' selenium.%s(%s)' % (command, ', '.join(arguments))
+
+
+def parse_options():
+ parser = OptionParser(usage="generatetests -l LAYER [options] directory",
+ version="%prog 1.0")
+ parser.add_option("-f", "--file", dest="target",
+ default="tests_all_selenium.py",
+ help="write tests to OUTPUT", metavar="FILE")
+ parser.add_option("-l", "--layer", dest="layer",
+ help="full python import path to layer instance",
+ metavar="LAYER")
+ parser.add_option("-v", "--verbose",
+ action="store_true", dest="verbose",
+ help="print progress messages to stdout")
+ parser.add_option("-q", "--quiet",
+ action="store_false", dest="verbose", default=True,
+ help="do not print progress messages to stdout")
+
+ options, args = parser.parse_args()
+ if not args:
+ parser.error('source directory is required')
+ elif len(args) > 1:
+ parser.error('only one source directory should be provided')
+ if not options.layer:
+ parser.error('layer is required')
+ if len(options.layer.split('.')) <= 1:
+ parser.error('layer option should include the module')
+ directory = args[0]
+ return options, directory
+
+
+def main():
+ options, directory = parse_options()
+ tests = []
+ pattern = os.path.join(directory, '*.html')
+ for filename in glob.glob(pattern):
+ if options.verbose:
+ print "Parsing %s" % filename
+ tree = HTMLTreeBuilder.parse(filename)
+ root = tree.getroot()
+
+ try:
+ testname = root.find('.//title').text
+ except AttributeError:
+ continue
+ commands = []
+ for row in root.findall('.//tbody/tr'):
+ command = formatcommand(*[td.text for td in row.findall('td')])
+ commands.append(command)
+
+ method_body = method_body_template.substitute(dict(
+ testname=testname,
+ commands='\n'.join(commands)))
+ tests.append(method_body)
+
+ if options.verbose:
+ print "Generating %s" % options.target
+ f = open(options.target, 'wb')
+ layer = options.layer
+ layer_module = ".".join(layer.split('.')[:-1])
+ f.write(module_template.substitute(dict(
+ testname='all',
+ tests='\n'.join(tests),
+ layer=layer,
+ layer_module=layer_module,
+ )))
+ f.close()
+
+if __name__ == '__main__':
+ main()
Deleted: gocept.selenium/branches/gotcha-generator/src/gocept/selenium/scripts/generatetests.py
===================================================================
--- gocept.selenium/branches/gotcha-generator/src/gocept/selenium/scripts/generatetests.py 2011-01-04 09:33:25 UTC (rev 119336)
+++ gocept.selenium/branches/gotcha-generator/src/gocept/selenium/scripts/generatetests.py 2011-01-04 11:34:32 UTC (rev 119337)
@@ -1,72 +0,0 @@
-#!/usr/bin/env python
-"""
-Generate selenium test controller files from HTML selenium tests
-"""
-
-import re
-import glob
-from elementtree import HTMLTreeBuilder
-from string import Template
-
-template = Template('''
-from seleniumtestcase import SeleniumTestCase
-import unittest, time
-
-class seltest_$testname(SeleniumTestCase):
-
-$tests
-
-def test_suite():
- return unittest.makeSuite(seltest_$testname)
-
-if __name__ == "__main__":
- unittest.main()
-''')
-
-variable_regexp = re.compile('\$\{(?P<varname>\w*)\}')
-
-
-def formatcommand(command, *args):
- if not command:
- return '' # Change this to raise an exception?
-
- arguments = []
- for arg in args:
- if not arg:
- continue
- matched = variable_regexp.match(arg)
- if matched is None:
- arguments.append('"%s"' % arg)
- else:
- arguments.append("self.getVar('%s')" % matched.group('varname'))
- return 'self.%s(%s)' % (command, ', '.join(arguments))
-
-
-def main():
- tests = []
- for filename in glob.glob('*.html'):
- tree = HTMLTreeBuilder.parse(filename)
- root = tree.getroot()
-
- try:
- testname = root.find('.//title').text
- except AttributeError:
- continue
- commands = []
- for row in root.findall('.//tbody/tr'):
- command = formatcommand(*[td.text for td in row.findall('td')])
- commands.append(command)
-
- testbody = (' def test_%s(self):\n' % testname + ' ' * 8 +
- '\n '.join(commands) + '\n')
- tests.append(testbody)
-
- f = open('seltest_all.py', 'wb')
- f.write(template.substitute(dict(
- testname=testname,
- tests='\n'.join(tests),
- )))
- f.close()
-
-if __name__ == '__main__':
- main()
Added: gocept.selenium/branches/gotcha-generator/src/gocept/selenium/scripts/tests/plone3login.html
===================================================================
--- gocept.selenium/branches/gotcha-generator/src/gocept/selenium/scripts/tests/plone3login.html (rev 0)
+++ gocept.selenium/branches/gotcha-generator/src/gocept/selenium/scripts/tests/plone3login.html 2011-01-04 11:34:32 UTC (rev 119337)
@@ -0,0 +1,39 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<title>plone3login</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">plone3login</td></tr>
+</thead><tbody>
+<tr>
+ <td>open</td>
+ <td>/plone/login_form</td>
+ <td></td>
+</tr>
+<tr>
+ <td>type</td>
+ <td>__ac_name</td>
+ <td>admin</td>
+</tr>
+<tr>
+ <td>type</td>
+ <td>__ac_password</td>
+ <td>admin</td>
+</tr>
+<tr>
+ <td>clickAndWait</td>
+ <td>submit</td>
+ <td></td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>//a[@id='user-name']/span</td>
+ <td>admin</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
More information about the checkins
mailing list