Author: jvloothuis
Date: Sun Feb 18 01:10:48 2007
New Revision: 39148

Added:
   kukit/kss.demo/trunk/kss/demo/tests/selenium_tests/createpythontests.py   
(contents, props changed)
Log:
Added a basic code generation script for creating the python test files from 
the selenium html


Added: kukit/kss.demo/trunk/kss/demo/tests/selenium_tests/createpythontests.py
==============================================================================
--- (empty file)
+++ kukit/kss.demo/trunk/kss/demo/tests/selenium_tests/createpythontests.py     
Sun Feb 18 01:10:48 2007
@@ -0,0 +1,48 @@
+#!/usr/bin/env python
+
+# Generate selenium test controller files from HTML selenium tests
+
+from elementtree import HTMLTreeBuilder, ElementTree
+import glob
+from string import Template
+import os
+
+template = Template('''
+from seleniumtestcase import SeleniumTestCase
+import unittest, time
+
+class seltest_$testname(SeleniumTestCase):
+
+    def test_seltest_$testname(self):
+        $testbody
+
+def test_suite():
+    return unittest.makeSuite($testname)
+
+if __name__ == "__main__":
+    unittest.main()
+''')
+
+def formatcommand(command, *args):
+    arguments = ['"%s"' % arg for arg in args if arg]
+    return 'self.%s(%s)' % (command, ', '.join(arguments))
+
+htmlparser = HTMLTreeBuilder.TreeBuilder()
+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'):
+        commands.append(formatcommand(*[td.text for td in row.findall('td')]))
+
+    testfilename = 'seltest_%s.py' % testname
+    f = open(testfilename, 'wb')
+    f.write(template.substitute(dict(
+        testname=testname,
+        testbody='\n        '.join(commands))))
+    f.close()
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins

Reply via email to