Skip to content

Commit

Permalink
Merge pull request #10 from paylogic/remote-url
Browse files Browse the repository at this point in the history
added remote url configuration support. closes #9
  • Loading branch information
bubenkoff committed Aug 18, 2014
2 parents 49ed5b7 + 4bff8f4 commit 2c39db8
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 11 deletions.
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
Changelog
=========

Unreleased
----------

- 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
9 changes: 9 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,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 @@ -105,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(
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 @@ -174,6 +189,8 @@ def browser_instance(
'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)
browser = Browser(
Expand Down Expand Up @@ -217,6 +234,7 @@ def browser(
request, browser_pool, splinter_webdriver, splinter_session_scoped_browser,
splinter_close_browser, splinter_browser_load_condition, splinter_browser_load_timeout):
"""Splinter browser wrapper instance. To be used for browser interaction.
Function scoped (cookies are clean for each test and on blank).
"""
get_browser = lambda: request.getfuncargvalue('browser_instance')
Expand Down Expand Up @@ -250,25 +268,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)

0 comments on commit 2c39db8

Please sign in to comment.