[Checkins] SVN: gocept.selenium/branches/jw-move-selenium-browser-to-testcasebase/src/gocept/selenium/ add utility method for creating multiple test cases for mutiple browsers from one test case

Jan-Wijbrand Kolman janwijbrand at gmail.com
Wed Jun 2 06:52:11 EDT 2010


Log message for revision 112899:
  add utility method for creating multiple test cases for mutiple browsers from one test case

Changed:
  A   gocept.selenium/branches/jw-move-selenium-browser-to-testcasebase/src/gocept/selenium/tests/test_util.py
  A   gocept.selenium/branches/jw-move-selenium-browser-to-testcasebase/src/gocept/selenium/util.py

-=-
Added: gocept.selenium/branches/jw-move-selenium-browser-to-testcasebase/src/gocept/selenium/tests/test_util.py
===================================================================
--- gocept.selenium/branches/jw-move-selenium-browser-to-testcasebase/src/gocept/selenium/tests/test_util.py	                        (rev 0)
+++ gocept.selenium/branches/jw-move-selenium-browser-to-testcasebase/src/gocept/selenium/tests/test_util.py	2010-06-02 10:52:11 UTC (rev 112899)
@@ -0,0 +1,70 @@
+#############################################################################
+#
+# Copyright (c) 2009 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+import unittest
+from gocept.selenium.base import Layer
+from gocept.selenium.util import make_testsuite
+
+class MakeTestSuiteTestCase(unittest.TestCase):
+    layer = Layer()
+
+    def test_one_two_three(self):
+        self.assert_(True)
+
+class Another(unittest.TestCase):
+    def test_four_five(self):
+        self.assert_(True)
+
+class SubFromMakeTestSuiteTestCase(MakeTestSuiteTestCase):
+    layer = Layer()
+
+class MakeTestSuite(unittest.TestCase):
+
+    def test_make_testsuite(self):
+        tests = make_testsuite(
+            (MakeTestSuiteTestCase,), ('*firefox', '*googlechrome'))
+        self.assertEquals(2, tests.countTestCases())
+
+        tests = make_testsuite(
+            (MakeTestSuiteTestCase, Another), ('*firefox', '*googlechrome'))
+        self.assertEquals(4, tests.countTestCases())
+
+        tests = make_testsuite(
+            (MakeTestSuiteTestCase, SubFromMakeTestSuiteTestCase, Another),
+            ('*firefox', '*googlechrome'))
+        self.assertEquals(6, tests.countTestCases())
+
+        tests = make_testsuite(
+            (MakeTestSuiteTestCase, SubFromMakeTestSuiteTestCase, Another),
+            ('*firefox', '*googlechrome', '*ie', '*epihany', '*safari'))
+        self.assertEquals(15, tests.countTestCases())
+
+    def test_override_app_host(self):
+        tests = make_testsuite(
+            (MakeTestSuiteTestCase,), ('*firefox', '*googlechrome'),
+            app_host='192.168.1.1')
+        for test in tests:
+            self.assertEquals('192.168.1.1', test.layer.host)
+
+    def test_override_selenium_server(self):
+        tests = make_testsuite(
+            (MakeTestSuiteTestCase,), ('*firefox', '*googlechrome'),
+            selenium_server='192.168.1.2')
+        for test in tests:
+            self.assertEquals('192.168.1.2', test._server)
+
+def test_suite():
+    suite = unittest.TestSuite()
+    suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(MakeTestSuite))
+    return suite

Added: gocept.selenium/branches/jw-move-selenium-browser-to-testcasebase/src/gocept/selenium/util.py
===================================================================
--- gocept.selenium/branches/jw-move-selenium-browser-to-testcasebase/src/gocept/selenium/util.py	                        (rev 0)
+++ gocept.selenium/branches/jw-move-selenium-browser-to-testcasebase/src/gocept/selenium/util.py	2010-06-02 10:52:11 UTC (rev 112899)
@@ -0,0 +1,47 @@
+#############################################################################
+#
+# Copyright (c) 2009-2010 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+import unittest
+
+def _testcases_for_browser(testcases, browser, app_host, selenium_server):
+    suite = unittest.TestSuite()
+    for testcase in testcases:
+        if app_host is not None:
+            testcase.layer.host = app_host
+        if selenium_server is not None:
+            testcase._server = selenium_server
+        # Create a new test class, subclassing the original test case. The
+        # name of this new class reflects what browser is used.
+        new_testcase = type(
+            testcase.__name__+'_'+browser, (testcase,), {'browser': browser})
+        suite.addTests(
+            unittest.defaultTestLoader.loadTestsFromTestCase(new_testcase))
+    return suite
+
+def make_testsuite(testcases, browsers, app_host=None, selenium_server=None):
+    """Creates a test suite, where each of the given test cases is replicated
+    for each of the given browser names.
+
+    Optionally pass in a selenium_server addresses for testing against a
+    Selenium Grid. Note that the application_host address should be accessible
+    from the Selenium Remote Control instances that have subscribed to the
+    Selenium Grid.
+
+    """
+    suite = unittest.TestSuite()
+    for browser in browsers:
+        suite.addTests(
+            _testcases_for_browser(
+                testcases, browser, app_host, selenium_server))
+    return suite



More information about the checkins mailing list