[Checkins] SVN: gocept.selenium/trunk/src/gocept/selenium/ Change Selenese tests to use StaticLayer instead of ZTK (which they don't have any business with)

Wolfgang Schnerring wosc at wosc.de
Sun Dec 26 11:53:38 EST 2010


Log message for revision 119142:
  Change Selenese tests to use StaticLayer instead of ZTK (which they don't have any business with)
  

Changed:
  U   gocept.selenium/trunk/src/gocept/selenium/static/__init__.py
  A   gocept.selenium/trunk/src/gocept/selenium/tests/fixture/alert.html
  D   gocept.selenium/trunk/src/gocept/selenium/tests/fixture/alert.pt
  D   gocept.selenium/trunk/src/gocept/selenium/tests/fixture/configure.zcml
  A   gocept.selenium/trunk/src/gocept/selenium/tests/fixture/display-delay.html
  D   gocept.selenium/trunk/src/gocept/selenium/tests/fixture/display-delay.pt
  A   gocept.selenium/trunk/src/gocept/selenium/tests/fixture/divs.html
  D   gocept.selenium/trunk/src/gocept/selenium/tests/fixture/divs.pt
  A   gocept.selenium/trunk/src/gocept/selenium/tests/fixture/launch-popup.html
  D   gocept.selenium/trunk/src/gocept/selenium/tests/fixture/launch-popup.pt
  A   gocept.selenium/trunk/src/gocept/selenium/tests/fixture/popup.html
  D   gocept.selenium/trunk/src/gocept/selenium/tests/fixture/popup.pt
  A   gocept.selenium/trunk/src/gocept/selenium/tests/test_selenese.py
  U   gocept.selenium/trunk/src/gocept/selenium/ztk/tests/ftesting.zcml
  D   gocept.selenium/trunk/src/gocept/selenium/ztk/tests/test_selenese.py

-=-
Modified: gocept.selenium/trunk/src/gocept/selenium/static/__init__.py
===================================================================
--- gocept.selenium/trunk/src/gocept/selenium/static/__init__.py	2010-12-26 16:46:58 UTC (rev 119141)
+++ gocept.selenium/trunk/src/gocept/selenium/static/__init__.py	2010-12-26 16:53:37 UTC (rev 119142)
@@ -131,6 +131,8 @@
                 shutil.rmtree(fullpath)
                 continue
             os.remove(fullpath)
+        # silence annoying 404s
+        open(os.path.join(self.documentroot, 'favicon.ico'), 'w').close()
 
 
 static_files_layer = StaticFilesLayer()

Copied: gocept.selenium/trunk/src/gocept/selenium/tests/fixture/alert.html (from rev 119132, gocept.selenium/trunk/src/gocept/selenium/tests/fixture/alert.pt)
===================================================================
--- gocept.selenium/trunk/src/gocept/selenium/tests/fixture/alert.html	                        (rev 0)
+++ gocept.selenium/trunk/src/gocept/selenium/tests/fixture/alert.html	2010-12-26 16:53:37 UTC (rev 119142)
@@ -0,0 +1,10 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
+<head>
+</head>
+
+<body onload="window.setTimeout(function(){alert('foo');}, 500)">
+</body>
+</html>

Deleted: gocept.selenium/trunk/src/gocept/selenium/tests/fixture/alert.pt
===================================================================
--- gocept.selenium/trunk/src/gocept/selenium/tests/fixture/alert.pt	2010-12-26 16:46:58 UTC (rev 119141)
+++ gocept.selenium/trunk/src/gocept/selenium/tests/fixture/alert.pt	2010-12-26 16:53:37 UTC (rev 119142)
@@ -1,10 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
-"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
-<head>
-</head>
-
-<body onload="window.setTimeout(function(){alert('foo');}, 500)">
-</body>
-</html>

Deleted: gocept.selenium/trunk/src/gocept/selenium/tests/fixture/configure.zcml
===================================================================
--- gocept.selenium/trunk/src/gocept/selenium/tests/fixture/configure.zcml	2010-12-26 16:46:58 UTC (rev 119141)
+++ gocept.selenium/trunk/src/gocept/selenium/tests/fixture/configure.zcml	2010-12-26 16:53:37 UTC (rev 119142)
@@ -1,41 +0,0 @@
-<configure
-  xmlns="http://namespaces.zope.org/zope"
-  xmlns:browser="http://namespaces.zope.org/browser"
-  >
-
-  <browser:page
-    for="*"
-    name="display-delay.html"
-    template="display-delay.pt"
-    permission="zope.Public"
-    />
-
-  <browser:page
-     for="*"
-     name="launch-popup.html"
-     template="launch-popup.pt"
-     permission="zope.Public"
-     />
-
-  <browser:page
-     for="*"
-     name="popup.html"
-     template="popup.pt"
-     permission="zope.Public"
-     />
-
-  <browser:page
-     for="*"
-     name="alert.html"
-     template="alert.pt"
-     permission="zope.Public"
-     />
-
-  <browser:page
-     for="*"
-     name="divs.html"
-     template="divs.pt"
-     permission="zope.Public"
-     />
-
-</configure>

Copied: gocept.selenium/trunk/src/gocept/selenium/tests/fixture/display-delay.html (from rev 119132, gocept.selenium/trunk/src/gocept/selenium/tests/fixture/display-delay.pt)
===================================================================
--- gocept.selenium/trunk/src/gocept/selenium/tests/fixture/display-delay.html	                        (rev 0)
+++ gocept.selenium/trunk/src/gocept/selenium/tests/fixture/display-delay.html	2010-12-26 16:53:37 UTC (rev 119142)
@@ -0,0 +1,18 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
+<head>
+<script type="text/javascript">
+function display() {
+    var div = document.createElement('div');
+    div.appendChild(document.createTextNode('Hello, world'));
+    document.body.appendChild(div);
+}
+</script>
+</head>
+
+<body onload="window.setTimeout(display, 5000)">
+
+</body>
+</html>

Deleted: gocept.selenium/trunk/src/gocept/selenium/tests/fixture/display-delay.pt
===================================================================
--- gocept.selenium/trunk/src/gocept/selenium/tests/fixture/display-delay.pt	2010-12-26 16:46:58 UTC (rev 119141)
+++ gocept.selenium/trunk/src/gocept/selenium/tests/fixture/display-delay.pt	2010-12-26 16:53:37 UTC (rev 119142)
@@ -1,18 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
-"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
-<head>
-<script type="text/javascript">
-function display() {
-    var div = document.createElement('div');
-    div.appendChild(document.createTextNode('Hello, world'));
-    document.body.appendChild(div);
-}
-</script>
-</head>
-
-<body onload="window.setTimeout(display, 5000)">
-
-</body>
-</html>

Copied: gocept.selenium/trunk/src/gocept/selenium/tests/fixture/divs.html (from rev 119132, gocept.selenium/trunk/src/gocept/selenium/tests/fixture/divs.pt)
===================================================================
--- gocept.selenium/trunk/src/gocept/selenium/tests/fixture/divs.html	                        (rev 0)
+++ gocept.selenium/trunk/src/gocept/selenium/tests/fixture/divs.html	2010-12-26 16:53:37 UTC (rev 119142)
@@ -0,0 +1,14 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
+<head>
+</head>
+
+<body>
+  <div class="countable"></div>
+  <div></div>
+  <div class="countable"></div>
+  <div class="countable"></div>
+</body>
+</html>

Deleted: gocept.selenium/trunk/src/gocept/selenium/tests/fixture/divs.pt
===================================================================
--- gocept.selenium/trunk/src/gocept/selenium/tests/fixture/divs.pt	2010-12-26 16:46:58 UTC (rev 119141)
+++ gocept.selenium/trunk/src/gocept/selenium/tests/fixture/divs.pt	2010-12-26 16:53:37 UTC (rev 119142)
@@ -1,14 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
-"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
-<head>
-</head>
-
-<body>
-  <div class="countable"></div>
-  <div></div>
-  <div class="countable"></div>
-  <div class="countable"></div>
-</body>
-</html>

Copied: gocept.selenium/trunk/src/gocept/selenium/tests/fixture/launch-popup.html (from rev 119132, gocept.selenium/trunk/src/gocept/selenium/tests/fixture/launch-popup.pt)
===================================================================
--- gocept.selenium/trunk/src/gocept/selenium/tests/fixture/launch-popup.html	                        (rev 0)
+++ gocept.selenium/trunk/src/gocept/selenium/tests/fixture/launch-popup.html	2010-12-26 16:53:37 UTC (rev 119142)
@@ -0,0 +1,16 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
+<head>
+<script type="text/javascript">
+function launch_popup() {
+    window.open('popup.html', 'gocept.selenium-popup');
+}
+</script>
+</head>
+
+<body onload="window.setTimeout(launch_popup, 1000)">
+<div id="parent">This is the parent window.</div>
+</body>
+</html>

Deleted: gocept.selenium/trunk/src/gocept/selenium/tests/fixture/launch-popup.pt
===================================================================
--- gocept.selenium/trunk/src/gocept/selenium/tests/fixture/launch-popup.pt	2010-12-26 16:46:58 UTC (rev 119141)
+++ gocept.selenium/trunk/src/gocept/selenium/tests/fixture/launch-popup.pt	2010-12-26 16:53:37 UTC (rev 119142)
@@ -1,16 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
-"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
-<head>
-<script type="text/javascript">
-function launch_popup() {
-    window.open('popup.html', 'gocept.selenium-popup');
-}
-</script>
-</head>
-
-<body onload="window.setTimeout(launch_popup, 1000)">
-<div id="parent">This is the parent window.</div>
-</body>
-</html>

Copied: gocept.selenium/trunk/src/gocept/selenium/tests/fixture/popup.html (from rev 119132, gocept.selenium/trunk/src/gocept/selenium/tests/fixture/popup.pt)
===================================================================
--- gocept.selenium/trunk/src/gocept/selenium/tests/fixture/popup.html	                        (rev 0)
+++ gocept.selenium/trunk/src/gocept/selenium/tests/fixture/popup.html	2010-12-26 16:53:37 UTC (rev 119142)
@@ -0,0 +1,11 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
+<head>
+</head>
+
+<body>
+<div id="popup">This is a pop-up window.</div>
+</body>
+</html>

Deleted: gocept.selenium/trunk/src/gocept/selenium/tests/fixture/popup.pt
===================================================================
--- gocept.selenium/trunk/src/gocept/selenium/tests/fixture/popup.pt	2010-12-26 16:46:58 UTC (rev 119141)
+++ gocept.selenium/trunk/src/gocept/selenium/tests/fixture/popup.pt	2010-12-26 16:53:37 UTC (rev 119142)
@@ -1,11 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
-"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
-<head>
-</head>
-
-<body>
-<div id="popup">This is a pop-up window.</div>
-</body>
-</html>

Copied: gocept.selenium/trunk/src/gocept/selenium/tests/test_selenese.py (from rev 119132, gocept.selenium/trunk/src/gocept/selenium/ztk/tests/test_selenese.py)
===================================================================
--- gocept.selenium/trunk/src/gocept/selenium/tests/test_selenese.py	                        (rev 0)
+++ gocept.selenium/trunk/src/gocept/selenium/tests/test_selenese.py	2010-12-26 16:53:37 UTC (rev 119142)
@@ -0,0 +1,260 @@
+#############################################################################
+#
+# 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.
+#
+##############################################################################
+
+from gocept.selenium.selenese import camelcase_to_underscore
+from gocept.selenium.selenese import selenese_pattern_equals as match
+import glob
+import gocept.selenium.selenese
+import gocept.selenium.static
+import os
+import pkg_resources
+import shutil
+import time
+import unittest
+
+
+class PatternTest(unittest.TestCase):
+
+    def test_no_prefix(self):
+        self.assert_(match('foo', 'foo'))
+        self.assert_(not match('foo', 'bar'))
+        self.assert_(match('foo:bar', 'foo:bar'))
+
+    def test_exact(self):
+        self.assert_(match('foo', 'exact:foo'))
+        self.assert_(not match('foo', 'exact:bar'))
+
+    def test_glob(self):
+        self.assert_(match('foo', 'glob:f*'))
+        self.assert_(match('foo', 'glob:fo?'))
+        self.assert_(not match('foo', 'glob:'))
+
+        self.assert_(not match('foo', 'glob:b*'))
+        self.assert_(not match('foo', 'glob:?ar'))
+
+    def test_glob_with_regex_chars_should_work(self):
+        self.assert_(match('(foo)', 'glob:(foo)'))
+        self.assert_(match('[foo]', 'glob:[foo]'))
+
+    def test_regex(self):
+        self.assert_(match('foo', 'regex:^fo+$'))
+        self.assert_(not match('foo', 'regex:^f+$'))
+
+    def test_multiline_strings(self):
+        self.assert_(match('foo\nbar', 'glob:foo*'))
+        self.assert_(match('foo\nbar', 'regex:^foo.*$'))
+
+
+class UtilsTest(unittest.TestCase):
+
+    def test_camelcaseconvert(self):
+        self.assertEquals('asdf', camelcase_to_underscore('asdf'))
+        self.assertEquals('foo_bar', camelcase_to_underscore('fooBar'))
+
+
+class NonexistentNameTest(unittest.TestCase):
+
+    def setUp(self):
+        class TestCase(object):
+            failureException = None
+
+        class Selenese(gocept.selenium.selenese.Selenese):
+            def get_without_assert_type(self):
+                pass
+
+            @gocept.selenium.selenese.assert_type('wrong_type')
+            def get_with_wrong_assert_type(self):
+                pass
+
+        self.selenese = Selenese(None, None, None)
+
+    def assertError(self, error, name, expected_msg):
+        try:
+            getattr(self.selenese, name)
+        except error, e:
+            msg = e.args[0]
+        self.assertEquals(expected_msg, msg)
+
+    def assertAttributeError(self, name):
+        self.assertError(AttributeError, name, name)
+
+    def test_nonexistent_name(self):
+        self.assertAttributeError('a_nonexistent_name')
+        self.assertAttributeError('assert_a_nonexistent_name')
+
+    def test_waitfor_verify(self):
+        self.assertAttributeError('waitFor_a_nonexistent_name')
+        self.assertAttributeError('verify_a_nonexistent_name')
+
+    def test_not(self):
+        self.assertAttributeError('a_Notexistent_name')
+        self.assertAttributeError('assert_a_Notexistent_name')
+        self.assertAttributeError('waitFor_a_Notexistent_name')
+        self.assertAttributeError('verify_a_Notexistent_name')
+
+    def test_broken_assert_type(self):
+        self.assertError(AttributeError,
+                         'assert_without_assert_type',
+                         "'function' object has no attribute 'assert_type'")
+        self.assertError(ValueError,
+                         'assert_with_wrong_assert_type',
+                         "Unknown assert type 'wrong_type' for "
+                         "selenese method 'assert_with_wrong_assert_type'.")
+
+
+class HTMLTestCase(gocept.selenium.static.TestCase):
+
+    def setUp(self):
+        super(HTMLTestCase, self).setUp()
+        directory = pkg_resources.resource_filename(
+            'gocept.selenium.tests.fixture', '')
+        for name in glob.glob(os.path.join(directory, '*.html')):
+            shutil.copy(os.path.join(directory, name), self.documentroot)
+
+
+class AssertionTest(HTMLTestCase):
+
+    def test_wait_for(self):
+        self.selenium.open('/display-delay.html')
+        self.selenium.assertElementNotPresent('css=div')
+        self.selenium.waitForElementPresent('css=div')
+
+    def test_wait_for_timeout(self):
+        self.selenium.open('/display-delay.html')
+        self.selenium.assertElementNotPresent('css=div')
+        try:
+            self.selenium.setTimeout(10)
+            self.selenium.waitForElementPresent('css=div')
+        except AssertionError:
+            pass
+        else:
+            self.fail('Timeout did not raise')
+
+    def test_assert_element_present_failure(self):
+        self.selenium.open('/display-delay.html')
+        try:
+            self.selenium.assertElementNotPresent('css=body')
+        except AssertionError:
+            pass
+        else:
+            self.fail('assertion should have failed')
+
+    def test_pause(self):
+        start = time.time()
+        self.selenium.pause(5000)
+        if time.time() - start < 4:
+            self.fail('Pause did not pause long enough')
+
+    def test_deleteCookie_smoke(self):
+        # Smoke test: just check that we don't break
+        self.selenium.deleteCookie('foo', '/')
+
+    def test_selectFrame_frame_doesnt_exist(self):
+        self.assertRaises(Exception, self.selenium.selectFrame, 'foo')
+
+    def test_waitForCondition_timeout(self):
+        self.selenium.setTimeout(100)
+        self.assertRaises(
+            AssertionError, self.selenium.waitForCondition, 'false')
+
+    def test_fireEvent_smoke(self):
+        self.selenium.fireEvent('css=body', 'click')
+
+    def test_location(self):
+        self.selenium.open('/')
+        self.assertEquals(
+            'http://%s:%s/' % (self.layer.host, self.layer.port),
+            self.selenium.getLocation())
+
+    def test_alert_not_present(self):
+        self.selenium.open('/')
+        self.selenium.verifyAlertNotPresent()
+
+    def test_alert_present(self):
+        self.selenium.open('/alert.html')
+        time.sleep(0.6)
+        self.selenium.verifyAlertPresent()
+        self.selenium.getAlert()
+
+    def test_wait_for_alert(self):
+        self.selenium.open('/alert.html')
+        self.selenium.verifyAlertNotPresent()
+        self.selenium.waitForAlertPresent()
+        self.selenium.getAlert()
+
+    def test_xpathcount_should_convert_to_ints(self):
+        self.selenium.open('/divs.html')
+        self.selenium.assertXpathCount("//div[@class='countable']", 3)
+        self.selenium.assertXpathCount("//div[@class='countable']", '3')
+        self.selenium.assertXpathCount("//div", 4)
+        self.selenium.assertXpathCount("//div", '4')
+
+
+class PopUpTest(HTMLTestCase):
+
+    def setUp(self):
+        super(PopUpTest, self).setUp()
+        self.selenium.open('/launch-popup.html')
+
+    def tearDown(self):
+        try:
+            self.selenium.selectPopUp(wait=False)
+        except Exception:
+            pass
+        if self.selenium.getLocation().endswith('/popup.html'):
+            self.selenium.close()
+            self.selenium.deselectPopUp()
+        self.selenium.setTimeout(30)
+        super(PopUpTest, self).tearDown()
+
+    def test_wait_for_and_select_popup(self):
+        # smoke tests for calls not otherwise used in this test class
+        self.selenium.waitForPopUp('gocept.selenium-popup')
+        self.selenium.waitForPopUp()
+        self.selenium.selectPopUp()
+
+    def test_wait_for_popup_times_out(self):
+        self.selenium.selectPopUp('gocept.selenium-popup')
+        self.selenium.close()
+        self.selenium.deselectPopUp()
+        self.selenium.setTimeout(0)
+        self.assertRaises(Exception, self.selenium.waitForPopUp,
+                          'gocept.selenium-popup')
+        self.assertRaises(Exception, self.selenium.waitForPopUp)
+        self.selenium.setTimeout(1)
+        self.assertRaises(Exception, self.selenium.waitForPopUp,
+                          'gocept.selenium-popup')
+        self.assertRaises(Exception, self.selenium.waitForPopUp)
+
+    def test_select_popup(self):
+        self.assertRaises(Exception,
+                          self.selenium.selectPopUp,
+                          'gocept.selenium-popup', wait=False)
+        self.selenium.selectPopUp('gocept.selenium-popup')
+        self.selenium.verifyElementPresent('css=div#popup')
+
+    def test_deselect_popup(self):
+        self.selenium.selectPopUp('gocept.selenium-popup')
+        self.selenium.deselectPopUp()
+        self.selenium.verifyElementNotPresent('css=div#popup')
+        self.selenium.verifyElementPresent('css=div#parent')
+
+    def test_close(self):
+        self.selenium.selectPopUp('gocept.selenium-popup')
+        self.selenium.verifyElementPresent('css=div#popup')
+        self.selenium.close()
+        self.assertRaises(Exception,
+                          self.selenium.verifyElementPresent, 'css=div#popup')
+        self.selenium.deselectPopUp()
+        self.selenium.verifyElementPresent('css=div#parent')

Modified: gocept.selenium/trunk/src/gocept/selenium/ztk/tests/ftesting.zcml
===================================================================
--- gocept.selenium/trunk/src/gocept/selenium/ztk/tests/ftesting.zcml	2010-12-26 16:46:58 UTC (rev 119141)
+++ gocept.selenium/trunk/src/gocept/selenium/ztk/tests/ftesting.zcml	2010-12-26 16:53:37 UTC (rev 119142)
@@ -4,7 +4,6 @@
 
   <include package="zope.app.zcmlfiles"/>
   <include package="gocept.selenium.tests.isolation" />
-  <include package="gocept.selenium.tests.fixture" />
 
   <!-- typical functional testing security setup -->
   <include package="zope.securitypolicy" file="meta.zcml"/>

Deleted: gocept.selenium/trunk/src/gocept/selenium/ztk/tests/test_selenese.py
===================================================================
--- gocept.selenium/trunk/src/gocept/selenium/ztk/tests/test_selenese.py	2010-12-26 16:46:58 UTC (rev 119141)
+++ gocept.selenium/trunk/src/gocept/selenium/ztk/tests/test_selenese.py	2010-12-26 16:53:37 UTC (rev 119142)
@@ -1,246 +0,0 @@
-#############################################################################
-#
-# 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.
-#
-##############################################################################
-
-from gocept.selenium.selenese import selenese_pattern_equals as match
-from gocept.selenium.selenese import camelcase_to_underscore
-import gocept.selenium.selenese
-import gocept.selenium.ztk.testing
-import unittest
-import time
-
-
-class PatternTest(unittest.TestCase):
-
-    def test_no_prefix(self):
-        self.assert_(match('foo', 'foo'))
-        self.assert_(not match('foo', 'bar'))
-        self.assert_(match('foo:bar', 'foo:bar'))
-
-    def test_exact(self):
-        self.assert_(match('foo', 'exact:foo'))
-        self.assert_(not match('foo', 'exact:bar'))
-
-    def test_glob(self):
-        self.assert_(match('foo', 'glob:f*'))
-        self.assert_(match('foo', 'glob:fo?'))
-        self.assert_(not match('foo', 'glob:'))
-
-        self.assert_(not match('foo', 'glob:b*'))
-        self.assert_(not match('foo', 'glob:?ar'))
-
-    def test_glob_with_regex_chars_should_work(self):
-        self.assert_(match('(foo)', 'glob:(foo)'))
-        self.assert_(match('[foo]', 'glob:[foo]'))
-
-    def test_regex(self):
-        self.assert_(match('foo', 'regex:^fo+$'))
-        self.assert_(not match('foo', 'regex:^f+$'))
-
-    def test_multiline_strings(self):
-        self.assert_(match('foo\nbar', 'glob:foo*'))
-        self.assert_(match('foo\nbar', 'regex:^foo.*$'))
-
-
-class UtilsTest(unittest.TestCase):
-
-    def test_camelcaseconvert(self):
-        self.assertEquals('asdf', camelcase_to_underscore('asdf'))
-        self.assertEquals('foo_bar', camelcase_to_underscore('fooBar'))
-
-
-class NonexistentNameTest(unittest.TestCase):
-
-    def setUp(self):
-        class TestCase(object):
-            failureException = None
-
-        class Selenese(gocept.selenium.selenese.Selenese):
-            def get_without_assert_type(self):
-                pass
-
-            @gocept.selenium.selenese.assert_type('wrong_type')
-            def get_with_wrong_assert_type(self):
-                pass
-
-        self.selenese = Selenese(None, None, None)
-
-    def assertError(self, error, name, expected_msg):
-        try:
-            getattr(self.selenese, name)
-        except error, e:
-            msg = e.args[0]
-        self.assertEquals(expected_msg, msg)
-
-    def assertAttributeError(self, name):
-        self.assertError(AttributeError, name, name)
-
-    def test_nonexistent_name(self):
-        self.assertAttributeError('a_nonexistent_name')
-        self.assertAttributeError('assert_a_nonexistent_name')
-
-    def test_waitfor_verify(self):
-        self.assertAttributeError('waitFor_a_nonexistent_name')
-        self.assertAttributeError('verify_a_nonexistent_name')
-
-    def test_not(self):
-        self.assertAttributeError('a_Notexistent_name')
-        self.assertAttributeError('assert_a_Notexistent_name')
-        self.assertAttributeError('waitFor_a_Notexistent_name')
-        self.assertAttributeError('verify_a_Notexistent_name')
-
-    def test_broken_assert_type(self):
-        self.assertError(AttributeError,
-                         'assert_without_assert_type',
-                         "'function' object has no attribute 'assert_type'")
-        self.assertError(ValueError,
-                         'assert_with_wrong_assert_type',
-                         "Unknown assert type 'wrong_type' for "
-                         "selenese method 'assert_with_wrong_assert_type'.")
-
-
-class AssertionTest(gocept.selenium.ztk.testing.TestCase):
-
-    def test_wait_for(self):
-        self.selenium.open('/display-delay.html')
-        self.selenium.assertElementNotPresent('css=div')
-        self.selenium.waitForElementPresent('css=div')
-
-    def test_wait_for_timeout(self):
-        self.selenium.open('/display-delay.html')
-        self.selenium.assertElementNotPresent('css=div')
-        try:
-            self.selenium.setTimeout(10)
-            self.selenium.waitForElementPresent('css=div')
-        except AssertionError:
-            pass
-        else:
-            self.fail('Timeout did not raise')
-
-    def test_assert_element_present_failure(self):
-        self.selenium.open('/display-delay.html')
-        try:
-            self.selenium.assertElementNotPresent('css=body')
-        except AssertionError:
-            pass
-        else:
-            self.fail('assertion should have failed')
-
-    def test_pause(self):
-        start = time.time()
-        self.selenium.pause(5000)
-        if time.time() - start < 4:
-            self.fail('Pause did not pause long enough')
-
-    def test_deleteCookie_smoke(self):
-        # Smoke test: just check that we don't break
-        self.selenium.deleteCookie('foo', '/')
-
-    def test_selectFrame_frame_doesnt_exist(self):
-        self.assertRaises(Exception, self.selenium.selectFrame, 'foo')
-
-    def test_waitForCondition_timeout(self):
-        self.selenium.setTimeout(100)
-        self.assertRaises(
-            AssertionError, self.selenium.waitForCondition, 'false')
-
-    def test_fireEvent_smoke(self):
-        self.selenium.fireEvent('css=body', 'click')
-
-    def test_location(self):
-        self.selenium.open('/')
-        self.assertEquals(
-            'http://%s:%s/' % (self.layer.host, self.layer.port),
-            self.selenium.getLocation())
-
-    def test_alert_not_present(self):
-        self.selenium.open('/')
-        self.selenium.verifyAlertNotPresent()
-
-    def test_alert_present(self):
-        self.selenium.open('/alert.html')
-        time.sleep(0.6)
-        self.selenium.verifyAlertPresent()
-        self.selenium.getAlert()
-
-    def test_wait_for_alert(self):
-        self.selenium.open('/alert.html')
-        self.selenium.verifyAlertNotPresent()
-        self.selenium.waitForAlertPresent()
-        self.selenium.getAlert()
-
-    def test_xpathcount_should_convert_to_ints(self):
-        self.selenium.open('/divs.html')
-        self.selenium.assertXpathCount("//div[@class='countable']", 3)
-        self.selenium.assertXpathCount("//div[@class='countable']", '3')
-        self.selenium.assertXpathCount("//div", 4)
-        self.selenium.assertXpathCount("//div", '4')
-
-
-class PopUpTest(gocept.selenium.ztk.testing.TestCase):
-
-    def setUp(self):
-        super(PopUpTest, self).setUp()
-        self.selenium.open('/launch-popup.html')
-
-    def tearDown(self):
-        try:
-            self.selenium.selectPopUp(wait=False)
-        except Exception:
-            pass
-        if self.selenium.getLocation().endswith('/popup.html'):
-            self.selenium.close()
-            self.selenium.deselectPopUp()
-        self.selenium.setTimeout(30)
-        super(PopUpTest, self).tearDown()
-
-    def test_wait_for_and_select_popup(self):
-        # smoke tests for calls not otherwise used in this test class
-        self.selenium.waitForPopUp('gocept.selenium-popup')
-        self.selenium.waitForPopUp()
-        self.selenium.selectPopUp()
-
-    def test_wait_for_popup_times_out(self):
-        self.selenium.selectPopUp('gocept.selenium-popup')
-        self.selenium.close()
-        self.selenium.deselectPopUp()
-        self.selenium.setTimeout(0)
-        self.assertRaises(Exception, self.selenium.waitForPopUp,
-                          'gocept.selenium-popup')
-        self.assertRaises(Exception, self.selenium.waitForPopUp)
-        self.selenium.setTimeout(1)
-        self.assertRaises(Exception, self.selenium.waitForPopUp,
-                          'gocept.selenium-popup')
-        self.assertRaises(Exception, self.selenium.waitForPopUp)
-
-    def test_select_popup(self):
-        self.assertRaises(Exception,
-                          self.selenium.selectPopUp,
-                          'gocept.selenium-popup', wait=False)
-        self.selenium.selectPopUp('gocept.selenium-popup')
-        self.selenium.verifyElementPresent('css=div#popup')
-
-    def test_deselect_popup(self):
-        self.selenium.selectPopUp('gocept.selenium-popup')
-        self.selenium.deselectPopUp()
-        self.selenium.verifyElementNotPresent('css=div#popup')
-        self.selenium.verifyElementPresent('css=div#parent')
-
-    def test_close(self):
-        self.selenium.selectPopUp('gocept.selenium-popup')
-        self.selenium.verifyElementPresent('css=div#popup')
-        self.selenium.close()
-        self.assertRaises(Exception,
-                          self.selenium.verifyElementPresent, 'css=div#popup')
-        self.selenium.deselectPopUp()
-        self.selenium.verifyElementPresent('css=div#parent')



More information about the checkins mailing list