From 018b24f508301ce11eb9db6088329886a5892d9f Mon Sep 17 00:00:00 2001 From: Marcin Mierzejewski Date: Mon, 1 Jun 2015 12:05:17 +0200 Subject: [PATCH 1/4] Fix ncbi/robotframework-pageobjects#40 --- robotpageobjects/page.py | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/robotpageobjects/page.py b/robotpageobjects/page.py index fa54078..8c188d3 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 grid_cap in self._Capabilities: + grid_new_cap = self._option_handler.get(grid_cap) + if grid_new_cap is not None: + self._Capabilities[grid_cap] = grid_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.set_window_size(1920, 1080) From 0570864179430e8e9796e21226357a5217a0dec4 Mon Sep 17 00:00:00 2001 From: s4int Date: Mon, 1 Jun 2015 18:14:29 +0200 Subject: [PATCH 2/4] Remove grid from var names --- robotpageobjects/page.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/robotpageobjects/page.py b/robotpageobjects/page.py index 8c188d3..d593e6e 100755 --- a/robotpageobjects/page.py +++ b/robotpageobjects/page.py @@ -156,10 +156,10 @@ def __init__(self): self._attempt_sauce = self._validate_sauce_options() self._Capabilities = getattr(webdriver.DesiredCapabilities, self.browser.upper()) - for grid_cap in self._Capabilities: - grid_new_cap = self._option_handler.get(grid_cap) - if grid_new_cap is not None: - self._Capabilities[grid_cap] = grid_new_cap + 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 From 56071d11a7418d1a852e8bf2a3d3cf739045c7d5 Mon Sep 17 00:00:00 2001 From: Marcin Mierzejewski Date: Fri, 5 Jun 2015 22:36:10 +0200 Subject: [PATCH 3/4] Selenium Grid description --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 77f5444..aad140d 100755 --- a/README.md +++ b/README.md @@ -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. @@ -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 From acadbbd150dd7344245be5897c65c5722dbaf675 Mon Sep 17 00:00:00 2001 From: cohenaa Date: Tue, 9 Jun 2015 11:51:44 -0400 Subject: [PATCH 4/4] README edits --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 84a44e5..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,9 +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 -- `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. +- `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.