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

Enable selenium grid support#40 #42

Closed
wants to merge 3 commits into from
Closed
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 @@ -254,6 +254,9 @@ 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
- `remote_url` : Address of remote grid server eg.: http://127.0.0.1:4444/wd/hub
- `version` : Browser version to use on grid. Don't set if any.
- `platform` : Platform on which test should be executed eg.: ANY.

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

Expand Down Expand Up @@ -836,6 +839,18 @@ Your page objects will automatically tag your Robot Sauce jobs with their
associated test names and
test status.

## 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:%s@ondemand.saucelabs.com: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.set_window_size(1920, 1080)

Expand Down