|
| 1 | +--- |
| 2 | +title: Using BrowserStack with Travis CI |
| 3 | +layout: en |
| 4 | +permalink: /user/browserstack/ |
| 5 | +--- |
| 6 | +Travis CI integrates with [BrowserStack](https://www.browserstack.com), a cross browser and real device |
| 7 | +web-based testing platform. BrowserStack can be used for Live as well as automated testing through frameworks |
| 8 | +like Selenium, Karma and others. |
| 9 | + |
| 10 | +This add-on automatically sets up Local Testing which allows you to test your private servers, alongside public |
| 11 | +URLs, using the BrowserStack cloud. To do this it uses the BrowserStackLocal binary for your build platform. |
| 12 | + |
| 13 | +[BrowserStack Local Testing][local-testing] establishes a secure connection between your Travis build container/VM |
| 14 | +and BrowserStack servers. Local Testing also has support for firewalls, proxies and Active Directory. |
| 15 | +Once the secure connection is setup, all URLs work out of the box, including your webserver, local folders, as well as |
| 16 | +URLs with HTTPS. |
| 17 | + |
| 18 | +[local-testing]: https://www.browserstack.com/local-testing |
| 19 | +[open-source-browserstack]: https://www.browserstack.com/pricing |
| 20 | +[account-settings]: https://www.browserstack.com/accounts/settings |
| 21 | +[encryption-keys]: http://docs.travis-ci.com/user/encryption-keys/ |
| 22 | +[browserstack-ruby-bindings]: https://www.browserstack.com/automate/ruby |
| 23 | +[travis-matrix-builds]: https://docs.travis-ci.com/user/customizing-the-build/#Build-Matrix |
| 24 | + |
| 25 | +## Setting up BrowserStack |
| 26 | + |
| 27 | +Please sign up for a BrowserStack account if you haven't already; it's |
| 28 | +[free][open-source-browserstack] for Open Source projects. Once you have signed up get your username and access key from |
| 29 | +the [account settings][account-settings] page. Your username and access key are required to configure the `.travis.yml` |
| 30 | +file of your project. |
| 31 | + |
| 32 | +Choose whether you want to store your access key as plain text or in a secure/encrypted form. For open source projects we recommend |
| 33 | +storing the access key in a secure form so that pull requests cannot use the keys stored in your .travis.yml. |
| 34 | +For more information see the [pull requests page](http://docs.travis-ci.com/user/pull-requests/#Security-Restrictions-when-testing-Pull-Requests). |
| 35 | + |
| 36 | +### Encrypted Access Key |
| 37 | + |
| 38 | +To encrypt your access key for use in .travis.yml you can use `travis encrypt "your BrowserStack access key"`. |
| 39 | +You need to have the travis cli installed to be able to do this (see [Encryption Keys][encryption-keys] for more details). |
| 40 | +Once your access key is encrypted you can add the secure string: |
| 41 | + |
| 42 | + addons: |
| 43 | + browserstack: "Your BrowserStack username" |
| 44 | + access_key: |
| 45 | + secure: "The secure string output of `travis encrypt`" |
| 46 | + |
| 47 | + |
| 48 | +### Plain Text Access Key |
| 49 | + |
| 50 | +To store your access key in plain text format, add the following configuration to your .travis.yml file: |
| 51 | + |
| 52 | + addons: |
| 53 | + browserstack: |
| 54 | + username: "Your BrowserStack username" |
| 55 | + access_key: "Your BrowserStack access key" |
| 56 | + |
| 57 | +We **strongly** recommend storing your BrowserStack access keys in encrypted format, since other users that have access to your repository |
| 58 | +can read and use your plain text access keys to test on BrowserStack. |
| 59 | + |
| 60 | +### Local Identifier |
| 61 | + |
| 62 | +A Local Identifier is a unique identifier for each Local connection when multiple Local connections are connected. |
| 63 | +The add-on will **ALWAYS** create a Local Identifier for each local connection that is created. If you are using the Selenium |
| 64 | +testing framework, the Local Identifier must be added to the Selenium capabilities. |
| 65 | + |
| 66 | +The Local Identifier is exposed as an environment variable `BROWSERSTACK_LOCAL_IDENTIFIER`. You can use it to set |
| 67 | +the Selenium capability. See the following example which uses Ruby's [selenium-webdriver][browserstack-ruby-bindings]: |
| 68 | + |
| 69 | + require 'rubygems' |
| 70 | + require 'selenium-webdriver' |
| 71 | + |
| 72 | + # Input capabilities |
| 73 | + caps = Selenium::WebDriver::Remote::Capabilities.new |
| 74 | + caps['browserstack.local'] = 'true' |
| 75 | + caps['browserstack.localIdentifier'] = ENV['BROWSERSTACK_LOCAL_IDENTIFIER'] |
| 76 | + # Add other capabilities like browser name, version and os name, version |
| 77 | + ... |
| 78 | + |
| 79 | + driver = Selenium::WebDriver.for(:remote, |
| 80 | + :url => "http://USERNAME:[email protected]/wd/hub", |
| 81 | + :desired_capabilities => caps) |
| 82 | + |
| 83 | +Local identifiers are essential for [matrix builds][travis-matrix-builds]. Since matrix builds in travis can be run on |
| 84 | +the same VM, we need to add the Local Identifier when starting the connection to ensure that the correct local tunnel |
| 85 | +gets the right requests. |
| 86 | + |
| 87 | +## Additional Options |
| 88 | + |
| 89 | +### Proxy |
| 90 | + |
| 91 | +Local testing also allows you to set the proxy host, port, username and password |
| 92 | +through which all urls will be resolved: |
| 93 | + |
| 94 | + addons: |
| 95 | + browserstack: "Your BrowserStack username" |
| 96 | + access_key: |
| 97 | + secure: "The secure string output of `travis encrypt`" |
| 98 | + proxyHost: "Proxy server host" |
| 99 | + proxyPort: "Proxy server port" |
| 100 | + proxyUser: "User to use when accessing proxy server" |
| 101 | + proxyPass: "Password to use when accessing proxy server" |
| 102 | + |
| 103 | + |
| 104 | +### More Options |
| 105 | + |
| 106 | +Some other options that are supported by the add on - |
| 107 | + * **force_local**: If this is set to true then all URLs will be resolved via the Travis container that your build is running in. |
| 108 | + * **only**: restricts Local testing access to the specified local servers and/or folders. |
| 109 | + |
| 110 | +Sample usage, |
| 111 | + |
| 112 | + addons: |
| 113 | + browserstack: "Your BrowserStack username" |
| 114 | + access_key: |
| 115 | + secure: "The secure string output of `travis encrypt`" |
| 116 | + forcelocal: true |
| 117 | + only: dev.example.com,80,0,*.example.org,80,0 |
| 118 | + |
| 119 | +The format for the **only** flag is, `"Host pattern,Host Port,Flag for SSL True(1)/False(0)" and repeat. |
0 commit comments