Permalink
Browse files

Test PageObject.

  • Loading branch information...
1 parent a74089a commit 722dca3fa72e2977840a64a0d370a3085009ab21 @jone jone committed Mar 22, 2013
Showing with 130 additions and 1 deletion.
  1. +1 −1 ftw/testing/pages.py
  2. +14 −0 ftw/testing/testing.py
  3. +113 −0 ftw/testing/tests/test_pages_pageobject.py
  4. +2 −0 setup.py
@@ -68,7 +68,7 @@ def find_one_by_xpath(self, selector):
'No element found with xpath: %s' % selector
assert len(elements) == 1, \
- 'More than one element found with xpath:%s\n%s' % (
+ 'More than one element found with xpath: %s\n%s' % (
selector,
str(map(lambda item: item.outer_html, elements)))
@@ -0,0 +1,14 @@
+from ftw.testing import FunctionalSplinterTesting
+from plone.app.testing import PLONE_FIXTURE
+from plone.app.testing import PloneSandboxLayer
+
+
+class PageObjectLayer(PloneSandboxLayer):
+
+ defaultBases = (PLONE_FIXTURE, )
+
+
+PAGE_OBJECT_FIXTURE = PageObjectLayer()
+PAGE_OBJECT_FUNCTIONAL = FunctionalSplinterTesting(
+ bases=(PAGE_OBJECT_FIXTURE, ),
+ name="ftw.testing:pageobject:functional")
@@ -0,0 +1,113 @@
+from ftw.testing import browser
+from ftw.testing import javascript
+from ftw.testing.pages import PageObject
+from ftw.testing.testing import PAGE_OBJECT_FUNCTIONAL
+from unittest2 import TestCase
+
+
+class TestPageObject(TestCase):
+
+ layer = PAGE_OBJECT_FUNCTIONAL
+
+ def test_portal_url__ZOPE_TESTBROWSER(self):
+ self.assertEquals(PageObject().portal_url, 'http://nohost/plone')
+
+ @javascript
+ def test_portal_url__JAVASCRIPT(self):
+ url = PageObject().portal_url
+
+ self.assertTrue(
+ url.endswith('/plone'),
+ 'Wrong plone site id in url "%s", should be /plone' % (
+ url))
+
+ self.assertNotIn(
+ 'nohost', url,
+ 'Javascript browser should not use internal hostname "nohost"')
+
+ def test_browser_driver__ZOPE_TESTBROWSER(self):
+ self.assertEquals(
+ 'zope.testbrowser',
+ PageObject().browser_driver,
+ 'Expected browser driver to be "zope.testbrowser"')
+
+ @javascript
+ def test_browser_driver__PHANTOMS(self):
+ self.assertEquals(
+ 'phantomjs',
+ PageObject().browser_driver,
+ 'Expected browser driver to be "phantomjs", because this'
+ ' is the default @javascript browser.')
+
+ def test_javascript_support__ZOPE_TESTBROWSER(self):
+ self.assertFalse(
+ PageObject().javascript_supported,
+ 'Expected zope.testbrowser to not support javascript'
+ ' (Current driver is %s)' % PageObject().browser_driver)
+
+ @javascript
+ def test_javascript_support__PHANTOMJS(self):
+ self.assertTrue(
+ PageObject().javascript_supported,
+ 'Expected phantomjs to support javascript'
+ ' (Current driver is %s)' % PageObject().browser_driver)
+
+ def test_iframes_supported__ZOPE_TESTBROWSER(self):
+ self.assertFalse(
+ PageObject().iframes_supported,
+ 'Expected zope.testbrowser to not support iframes'
+ ' (Current driver is %s)' % PageObject().browser_driver)
+
+ @javascript
+ def test_iframes_supported__PHANTOMS(self):
+ self.assertFalse(
+ PageObject().iframes_supported,
+ 'Expected phantomjs to not support iframes'
+ ' (Current driver is %s)' % PageObject().browser_driver)
+
+ def test_find_one_by_xpath__ZOPE_TESTBROWSER(self):
+ browser().visit(PageObject().portal_url)
+
+ with self.assertRaises(AssertionError) as cm:
+ PageObject().find_one_by_xpath('//novalidtag')
+ self.assertEquals('No element found with xpath: //novalidtag',
+ str(cm.exception))
+
+ with self.assertRaises(AssertionError) as cm:
+ PageObject().find_one_by_xpath('//a')
+
+ msg = str(cm.exception).split('\n')
+ self.assertEquals('More than one element found with xpath: //a',
+ msg[0])
+
+ element = PageObject().find_one_by_xpath('//a[text()="Plone"]')
+ self.assertEquals(
+ 'ZopeTestBrowserLinkElement',
+ type(element).__name__)
+
+ @javascript
+ def test_find_one_by_xpath__PHANTOMJS(self):
+ browser().visit(PageObject().portal_url)
+
+ with self.assertRaises(AssertionError) as cm:
+ PageObject().find_one_by_xpath('//novalidtag')
+ self.assertEquals('No element found with xpath: //novalidtag',
+ str(cm.exception))
+
+ with self.assertRaises(AssertionError) as cm:
+ PageObject().find_one_by_xpath('//a')
+
+ msg = str(cm.exception).split('\n')
+ self.assertEquals('More than one element found with xpath: //a',
+ msg[0])
+
+ element = PageObject().find_one_by_xpath('//a[text()="Plone"]')
+ self.assertEquals(
+ 'WebDriverElement',
+ type(element).__name__)
+
+ def test_normalize_whitespace(self):
+ self.assertEquals(
+ 'foo bar baz',
+ PageObject().normalize_whitespace(
+ ' foo\t \tbar \n baz\n\n'))
View
@@ -15,6 +15,8 @@
tests_require = [
'Acquisition<4.0a1',
'Products.PloneHotfix20121106',
+ 'Plone',
+ 'plone.app.testing',
] + extras_require['robot']
extras_require['tests'] = tests_require

0 comments on commit 722dca3

Please sign in to comment.