Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selenium grid support #45

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ like `sauce_platform` etc. can be gotten from Sauce's [configuration app](https:
- `browser` : Default is phantomjs. Sets the type of browser used. Values can be: firefox, phantomjs (default). Eg: (ift-env) $ pybot -v browser:firefox mytest.robot, or any browser that Sauce Labs supports.

- `log_level` : Default is "INFO". Sets the logging threshold for what's logged from the log method. Currently you have to set -L or --loglevel in Robot, not -vloglevel:LEVEL. See and Logging, Reporting & Debugging.
- `platform`: If using Selenium Grid, platform on which tests should be executed.
- `remote_url`: If using Selenium Grid, address of remote grid server eg.: http://127.0.0.1:4444/wd/hub
- `sauce_apikey` : The API key (password) for your [Sauce](http://www.saucelabs.com) account. Never hard-code this in anything, and never commit the repository. If you need to store it somewhere, store it as an environment variable.
- `sauce_browserversion` : The version of the sauce browser. Defaults to the latest available version for the given browser.
- `sauce_device_orientation` : Defaults to "portrait". For mobile devices, tells the page object what orientation to run the test in.
Expand All @@ -254,6 +256,7 @@ like `sauce_platform` etc. can be gotten from Sauce's [configuration app](https:
- `selenium_implicit_wait` : A global setting that sets the maximum time to wait before raising an ValueError. Default is 10 seconds. For example, for a call to click_element, Selenium will poll the page for the existence of the passed element at an interval of 200 ms until 10 seconds before raising an ElementNotFoundException.
- `selenium_speed` : The time in seconds between each Selenium API call issued. This should only be used for debugging to slow down your tests so you can see what the browser is doing. Default is 0 seconds. eg. $ pybot -v selenium_speed:1 mytest.robot
- `service_args` : Additional command-line arguments (such as "--ignore-ssl-errors=yes") to pass to the browser (any browser) when it is run. Arguments are space-separated. Example: PO_SERVICE_ARGS="--ignore-ssl-errors=yes --ssl-protocol=TLSv1" python mytest.py
- `version`: Browser version to use on grid. Don't set if any.

Once set, these option values are available as attributes on the page object. For example, self.baseurl.

Expand Down Expand Up @@ -837,6 +840,18 @@ To use Sauce:
See the Built-in options section [above](#built-in-options-for-page) for options
related to running tests in Sauce.

## Selenium Grid Integration

Selenium-Grid allows you run multiple tests at the same time against different machines running different browsers and operating systems.

You can read more about Selenium Grid [here](http://www.seleniumhq.org/docs/07_selenium_grid.jsp).
You have to set up your own Selenium Grid environment as described [here](https://code.google.com/p/selenium/wiki/Grid2).

*** Variables ***
${remote_url} http://127.0.0.1:4444/wd/hub
${browser} Firefox
${platform} ANY

## Logging Reporting & Debugging

### Robot
Expand Down
28 changes: 19 additions & 9 deletions robotpageobjects/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def __init__(self):

self.browser = self._option_handler.get("browser") or "phantomjs"
self.service_args = self._parse_service_args(self._option_handler.get("service_args", ""))
self.remote_url = self._option_handler.get("remote_url")

self._sauce_options = [
"sauce_username",
Expand All @@ -154,7 +155,13 @@ def __init__(self):

self._attempt_sauce = self._validate_sauce_options()

# There's only a session ID when using a remote webdriver (Sauce, for example)
self._Capabilities = getattr(webdriver.DesiredCapabilities, self.browser.upper())
for cap in self._Capabilities:
new_cap = self._option_handler.get(cap)
if new_cap is not None:
self._Capabilities[cap] = new_cap

# There's only a session ID when using a remote webdriver (Sauce, for example)
self.session_id = None

# If a name is not explicitly set with the name attribute,
Expand Down Expand Up @@ -558,6 +565,8 @@ class MyPageObject(PageObject):
:type delete_cookies: Boolean
:returns: _BaseActions instance
"""
caps = None
remote_url = False
resolved_url = self._resolve_url(*args)
if self._attempt_sauce:
remote_url = "http://%s:%[email protected]:80/wd/hub" % (self.sauce_username, self.sauce_apikey)
Expand All @@ -570,9 +579,13 @@ class MyPageObject(PageObject):
if self.sauce_screenresolution:
caps["screenResolution"] = self.sauce_screenresolution

try:
self.open_browser(resolved_url, self.browser, remote_url=remote_url, desired_capabilities=caps)
except (urllib2.HTTPError, WebDriverException), e:
if self.remote_url is not None:
remote_url = self.remote_url
caps = self._Capabilities

try:
self.open_browser(resolved_url, self.browser, remote_url=remote_url, desired_capabilities=caps)
except (urllib2.HTTPError, WebDriverException), e:
raise exceptions.SauceConnectionError("Unable to run Sauce job.\n%s\n"
"Sauce variables were:\n"
"sauce_platform: %s\n"
Expand All @@ -585,11 +598,8 @@ class MyPageObject(PageObject):
self.sauce_screenresolution)
)

self.session_id = self.get_current_browser().session_id
self.log("session ID: %s" % self.session_id)

else:
self.open_browser(resolved_url, self.browser)
self.session_id = self.get_current_browser().session_id
self.log("session ID: %s" % self.session_id)

self.log("PO_BROWSER: %s" % (str(self.get_current_browser())), is_console=False)

Expand Down