diff --git a/README.md b/README.md index 421ba6e..91d8ec1 100755 --- a/README.md +++ b/README.md @@ -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. @@ -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. @@ -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 diff --git a/robotpageobjects/page.py b/robotpageobjects/page.py index a5fd85a..139b723 100755 --- a/robotpageobjects/page.py +++ b/robotpageobjects/page.py @@ -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", @@ -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, @@ -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) @@ -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" @@ -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)