Skip to content
This repository has been archived by the owner on Jan 23, 2024. It is now read-only.

BrowserStack Integration

gdreed31 edited this page Jan 12, 2016 · 3 revisions

Running in BrowserStack

BrowserStack can provide you with a remote WebDriver. The primary benefit is that you can access WebDrivers that are not installed on your local machines consisting of pretty much any combination of OS and browser you can imagine. If you need to test on XP running IE6, BrowserStack has you covered without the need to maintain an XP VM or to keep around an old laptop.

Within the egat_example_project, we are getting a reference to our WebDriver in the browser_helper.get_browser() function. We are passing this function an environment dictionary that was built from the specifications in our JSON config file.

    if environment.get('browser_location', '') == "browserstack":
        desired_cap = {'browserstack.local': True,
                       'os': environment.get('os', ''),
                       'os_version': environment.get('os_version', ''),
                       'browser': environment.get('browser', ''),
                       'browser_version': environment.get('browser_version', '')
        }
 
        return webdriver.Remote(
            command_executor="http://" + environment.get('userName', '') + ":" + 
                  environment.get('key', '') + "@hub.browserstack.com:80/wd/hub",
                  desired_capabilities=desired_cap)
        ...

Notice we are pulling the BrowserStack username and key from our JSON config as well. Associating the username/key with each browser feels a little redundant, but it allows you to use multiple BrowserStack accounts.

However, if the browser_location key is set to local, you will return an instance of the local WebDriver that was specified in the JSON config.

Setting up Local Testing

If you are using a remote browser to test a local development environment, you will need to provide a secure way for BrowserStack to reach the local environment. In order to do this, you need to download a binary from BrowserStack, run it, and configure your remote WebDriver to use it.

Once the binary is downloaded, you can run it with the ./BrowserStackLocal binary passing it your BrowserStack key.

In order to setup your tests, you will need to set the browserstack.local dictionary key to true in the desired_cap dictionary.

Other Help

BrowserStack has excellent documentation on their website. They have code snippets to help you with Self-signed certificates, Enabling and Disabling Flash, Enable and Disable Pop-ups and many other topics.

BrowserStack