Skip to content

Commit

Permalink
Merge branch 'master' into issue5
Browse files Browse the repository at this point in the history
  • Loading branch information
bubenkoff committed Sep 6, 2014
2 parents ffa9848 + c406f6f commit 1f28040
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 13 deletions.
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
Changelog
=========

1.0.5
-----

- added remote webdriver url command line argument (bubenkoff)


1.0.4
-----

- Fixed browser fixture to support splinter_browser_load_condition and splinter_browser_load_timeout by default. (markon)


1.0.3
-----

Expand Down
12 changes: 11 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ Install pytest-splinter
Features
========

The plugin provides many useful fixtures to be used if you’re using splinter for browser testing
The plugin provides a set of fixtures to use `splinter <http://splinter.cobrateam.info>`_
for browser testing with `pytest <http://pytest.org>`_


Fixtures
Expand All @@ -47,6 +48,10 @@ Fixtures
Splinter's webdriver name to use. Fixture gets the value from the command-line option
splinter-webdriver (see below)

* splinter_remote_url
Splinter's webdriver remote url to use (optional). Fixture gets the value from the command-line option
splinter-remote-url (see below). Will be used only if selected webdriver name is 'remote'.

* splinter_session_scoped_browser
pytest-splinter should use single browser instance per test session.
Fixture gets the value from the command-line option splinter-session-scoped-browser (see below)
Expand Down Expand Up @@ -104,6 +109,11 @@ Command-line options

For more details, refer to splinter and selenium documentation.

* `--splinter-remote-url`
Webdriver remote url to use. (default: None). Will be used only if selected webdriver name is 'remote'.

For more details, refer to splinter and selenium documentation.

* `--splinter-session-scoped-browser`
pytest-splinter should use single browser instance per test session. (set by default).

Expand Down
44 changes: 33 additions & 11 deletions pytest_splinter/plugin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Splinter plugin for pytest.
Provides easy interface for the browser from your tests providing the `browser` fixture
which is an object of splinter Browser class.
"""
Expand All @@ -17,6 +18,7 @@


class Browser(object):

"""Emulate splinter's Browser."""

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -56,9 +58,19 @@ def splinter_webdriver(request):
return request.config.option.splinter_webdriver


@pytest.fixture(scope='session') # pragma: no cover
def splinter_remote_url(request):
"""Remote webdriver url.
:return: URL of remote webdriver.
"""
return request.config.option.splinter_remote_url


@pytest.fixture(scope='session') # pragma: no cover
def splinter_selenium_socket_timeout(request):
"""Internal Selenium socket timeout (communication between webdriver and the browser).
:return: Seconds.
"""
return request.config.option.splinter_webdriver_socket_timeout
Expand All @@ -67,6 +79,7 @@ def splinter_selenium_socket_timeout(request):
@pytest.fixture(scope='session') # pragma: no cover
def splinter_selenium_implicit_wait(request):
"""Selenium implicit wait timeout.
:return: Seconds.
"""
return request.config.option.splinter_webdriver_implicit_wait
Expand All @@ -75,6 +88,7 @@ def splinter_selenium_implicit_wait(request):
@pytest.fixture(scope='session') # pragma: no cover
def splinter_selenium_speed(request):
"""Selenium speed.
:return: Seconds.
"""
return request.config.option.splinter_webdriver_speed
Expand All @@ -84,15 +98,15 @@ def splinter_selenium_speed(request):
def splinter_browser_load_condition():
"""The condition that has to be `True` to assume that the page is fully loaded.
One example is to wait for jQuery, then the condition could be::
One example is to wait for jQuery, then the condition could be::
@pytest.fixture
def splinter_browser_load_condition():
@pytest.fixture
def splinter_browser_load_condition():
def condition(browser):
return browser.evaluate_script('typeof $ === "undefined" || !$.active')
def condition(browser):
return browser.evaluate_script('typeof $ === "undefined" || !$.active')
return condition
return condition
"""
return lambda browser: True

Expand Down Expand Up @@ -152,6 +166,7 @@ def browser_instance_getter(
splinter_selenium_implicit_wait,
splinter_selenium_speed,
splinter_webdriver,
splinter_remote_url,
splinter_browser_load_condition,
splinter_browser_load_timeout,
splinter_file_download_dir,
Expand All @@ -176,6 +191,8 @@ def browser_instance_getter(
'browser.helperApps.neverAsk.saveToDisk': splinter_download_file_types,
'browser.helperApps.alwaysAsk.force': False,
}, **splinter_firefox_profile_preferences)
elif splinter_webdriver == 'remote':
kwargs['url'] = splinter_remote_url
if splinter_driver_kwargs:
kwargs.update(splinter_driver_kwargs)

Expand Down Expand Up @@ -226,6 +243,7 @@ def browser(
splinter_close_browser, splinter_browser_load_condition, splinter_browser_load_timeout,
browser_instance_getter):
"""Splinter browser wrapper instance. To be used for browser interaction.
Function scoped (cookies are clean for each test and on blank).
"""
if not splinter_session_scoped_browser:
Expand Down Expand Up @@ -257,25 +275,29 @@ def pytest_addoption(parser): # pragma: no cover
"""Pytest hook to add custom command line option(s)."""
parser.addoption(
"--splinter-webdriver",
help="pytest-splinter-splinter webdriver", type="choice", choices=list(splinter.browser._DRIVERS.keys()),
help="pytest-splinter webdriver", type="choice", choices=list(splinter.browser._DRIVERS.keys()),
dest='splinter_webdriver', default='firefox')

parser.addoption(
"--splinter-remote-url",
help="pytest-splinter remote webdriver url ", dest='splinter_remote_url', default=None)

parser.addoption(
"--splinter-implicit-wait",
help="pytest-splinter-splinter selenium implicit wait, seconds", type="int",
help="pytest-splinter selenium implicit wait, seconds", type="int",
dest='splinter_webdriver_implicit_wait', default=1)

parser.addoption(
"--splinter-speed",
help="pytest-splinter-splinter selenium speed, seconds", type="int",
help="pytest-splinter selenium speed, seconds", type="int",
dest='splinter_webdriver_speed', default=0)

parser.addoption(
"--splinter-socket-timeout",
help="pytest-splinter-splinter socket timeout, seconds", type="int",
help="pytest-splinter socket timeout, seconds", type="int",
dest='splinter_webdriver_socket_timeout', default=120)

parser.addoption(
"--splinter-session-scoped-browser",
help="pytest-splinter-splinter should use single browser instance per test session", action="store_true",
help="pytest-splinter should use single browser instance per test session", action="store_true",
dest='splinter_session_scoped_browser', default=True)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def run_tests(self):
author='Paylogic developers',
license='MIT license',
author_email='developers@paylogic.com',
version='1.0.4',
version='1.0.5',
cmdclass={'test': Tox},
url='https://github.com/paylogic/pytest-splinter',
install_requires=[
Expand Down

0 comments on commit 1f28040

Please sign in to comment.