Skip to content

Commit

Permalink
Use the Selenium 2 web driver. This removes the need to download any jar
Browse files Browse the repository at this point in the history
files or run any Java since the web driver installs an extension into any
given browser to run tests.

svn path=/plone.app.testing/trunk/; revision=40956
  • Loading branch information
rpatterson committed Oct 30, 2010
1 parent e14df3a commit 7a8a9eb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 51 deletions.
6 changes: 6 additions & 0 deletions buildout.cfg
Expand Up @@ -10,6 +10,12 @@ eggs =
PILwoTk PILwoTk
plone.app.testing [test] plone.app.testing [test]
defaults = ['--auto-color', '--auto-progress', '--verbose'] defaults = ['--auto-color', '--auto-progress', '--verbose']
environment = testenv

[testenv]
## Uncomment one of the following to test against a browser other than firefox
#SELENIUM_DRIVER = ie
#SELENIUM_DRIVER = chrome


[coverage-report] [coverage-report]
recipe = zc.recipe.egg recipe = zc.recipe.egg
Expand Down
5 changes: 4 additions & 1 deletion plone/app/testing/selenium.txt
Expand Up @@ -104,4 +104,7 @@ When the layer is torn down, the Selenium browser is closed.
Tear down plone.testing.z2.Startup in ... seconds. Tear down plone.testing.z2.Startup in ... seconds.
Tear down plone.testing.zca.LayerCleanup in ... seconds. Tear down plone.testing.zca.LayerCleanup in ... seconds.


>>> case.selenium.sessionId >>> from selenium.remote.webdriver import WebDriver as RemoteWebDriver
>>> RemoteWebDriver._execute(case.selenium, 'quit')
Traceback (most recent call last):
URLError: <urlopen error [Errno 111] Connection refused>
29 changes: 7 additions & 22 deletions plone/app/testing/selenium_layers.py
@@ -1,10 +1,8 @@
import selenium
import os import os
import transaction import transaction
import unittest2 as unittest import unittest2 as unittest


from plone.app.testing import PloneSandboxLayer from plone.app.testing import PloneSandboxLayer
from plone.app.testing import PLONE_SITE_ID
from plone.app.testing import FunctionalTesting from plone.app.testing import FunctionalTesting
from plone.app.testing.layers import PLONE_FIXTURE from plone.app.testing.layers import PLONE_FIXTURE
from plone.testing import z2 from plone.testing import z2
Expand All @@ -13,20 +11,15 @@
class SeleniumLayer(PloneSandboxLayer): class SeleniumLayer(PloneSandboxLayer):
defaultBases = (z2.ZSERVER_FIXTURE, PLONE_FIXTURE) defaultBases = (z2.ZSERVER_FIXTURE, PLONE_FIXTURE)


# Connection parameters
seleniumHost = os.environ.get('SELENIUM_HOST', 'localhost')
seleniumPort = os.environ.get('SELENIUM_PORT', '4444')
seleniumBrowser = os.environ.get('SELENIUM_BROWSER', '*firefox')

def setUpPloneSite(self, portal): def setUpPloneSite(self, portal):
# Start up Selenium # Start up Selenium
url = "http://%s:%s/%s" % (self['host'], self['port'], PLONE_SITE_ID) driver = os.environ.get('SELENIUM_DRIVER', 'firefox')
self['selenium'] = selenium.selenium( webdriver = __import__(
self.seleniumHost, self.seleniumPort, self.seleniumBrowser, url) 'selenium.%s.webdriver' % driver, fromlist=['WebDriver'])
self['selenium'].start() self['selenium'] = webdriver.WebDriver()


def tearDownPloneSite(self, portal): def tearDownPloneSite(self, portal):
self['selenium'].stop() self['selenium'].quit()
del self['selenium'] del self['selenium']


SELENIUM_FIXTURE = SeleniumLayer() SELENIUM_FIXTURE = SeleniumLayer()
Expand All @@ -40,15 +33,7 @@ class SeleniumTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
self.selenium = self.layer['selenium'] self.selenium = self.layer['selenium']


def open(self, path="/", site_name=PLONE_SITE_ID): def open(self, url):
# ensure we have a clean starting point # ensure we have a clean starting point
transaction.commit() transaction.commit()
self.selenium.open("/%s/%s" % (site_name, path,)) self.selenium.get(url)

def wait(self, timeout="30000"):
self.selenium.wait_for_page_to_load(timeout)

def waitForElement(self, selector, timeout="30000"):
"""Continue checking for the element matching the provided CSS
selector."""
self.selenium.wait_for_condition("""css="%s" """ % selector, timeout)
28 changes: 0 additions & 28 deletions selenium.cfg

This file was deleted.

0 comments on commit 7a8a9eb

Please sign in to comment.