Use Sauce Labs with Travis CI
Travis CI integrates with Sauce Labs, a browser and mobile testing platform. It integrates well with Selenium, for instance.
The integration automatically sets up a tunnel required to get started testing with it. For that purpose, it uses Sauce Connect.
Note that due to security restrictions, the Sauce Labs addon is not available on pull request builds unless you use the JWT Addon.
Setup Sauce Connect #
Sauce Connect securely proxies browser traffic between Sauce Labs’ cloud-based VMs and your local servers. Sauce Connect uses ports 443 and 80 for communication with the Sauce Labs cloud. If you’re using Sauce Labs for your Selenium tests, this makes connecting to your web server a lot easier.
First, sign up with Sauce Labs if you haven’t already (it’s free for Open Source projects), and get your access key from your account page. Once you have that, add this to your .travis.yml file:
If you don’t want your access key publicly available in your repository, you
can encrypt it with travis encrypt "your-access-key"
(see Encryption Keys
for more information on encryption), and add the pull request safe secure (See JWT Addon.
string as such:
You can also add the username
and access_key
as environment variables if you
name them SAUCE_USERNAME
and SAUCE_ACCESS_KEY
, respectively. In that case,
all you need to add to your .travis.yml file is this:
To allow multiple tunnels to be open simultaneously, Travis CI opens a
Sauce Connect Tunnel Pool. Make sure you are sending
the TRAVIS_JOB_NUMBER
environment variable when you are opening the connection
to Sauce Labs’ selenium grid, as the desired tunnel-name
capability,
or it will not be able to connect to the server running on the VM.
How this looks will depend on the client library you’re using, in Ruby’s selenium-webdriver bindings:
caps = Selenium::WebDriver::Remote::Capabilities.firefox({
'tunnel-name' => ENV['TRAVIS_JOB_NUMBER']
})
driver = Selenium::WebDriver.for(:remote, {
url: 'http://username:access_key@ondemand.saucelabs.com/wd/hub',
desired_capabilities: caps
})
Additional Options #
Sometimes, you may need to pass additional options to Sauce Connect. Currently supported parameters are
direct_domains
no_ssl_bump_domains
tunnel_domains
As an example, you may need --direct-domains
option in case some HTTPS domains
fail to work with Sauce Connect:
Build Config Reference #
You can find more information on the build config format for Sauce Connect in our Travis CI Build Config Reference.