Docs Code Examples

Integrating Jenkins

    Introduction

    The Jenkins Sauce OnDemand plugin enables you to easily configure your tests invoked via Jenkins Jobs to run in the cloud using Sauce.

    In addition, the plugin can be configured to launch Sauce Connect automatically. This allows your tests in OnDemand to access web sites residing behind a firewall or even in localhost.

    Installation

    The Sauce OnDemand plugin can be installed via the Jenkins Plugin Manager.

    install jenkins

    The plugin is dependent on the 'Copy to Slave' plugin, which is used to copy the files required to run Sauce Connect to Jenkins Slave nodes.

    install copy to slave

    Administration

    x

    After the plugin has been installed, the username and corresponding access key must be entered via the 'Manage Jenkins' - 'Configure System' page.

    admin settings

    The plugin can be configured to retrieve the authentication details from a .sauce-ondemand file residing in the home directory. This file is used by the SeleniumClientFactory and Sauce REST API libraries. The contents of the file must be in the following format:

    username=YOUR_SAUCE_USER_NAME
    key=YOUR_SAUCE_ACCESS_KEY

    The Test Connection button will connect to Sauce OnDemand to verify that the authentication details are valid.

    If a later version of the Sauce Connect library is available, then a message indicating this and a link allowing the administrator to download the latest version will appear on this page. This will update the plugin to include the latest version without affecting the specific version of the Jenkins Sauce OnDemand plugin currently being used, this doesn't require a restart of the Jenkins instance.

    Job setup

    The Sauce OnDemand settings for a Job can be set via the Configure link.

    job settings

    If the Enable Sauce Connect option is clicked, then a Sauce Connect instance is launched when the Job is run.

    If the Override authentication information option is clicked, then the Job can be configured to use a different username/access key than which has been set via the 'Configure System' link.

    If the Will Selenium 1 tests be run? option is clicked, then a text field allowing the storage of the Starting URL will be shown. The value stored in this field will be stored in a SELENIUM_STARTING_URL environment variable.

    By clicking on the Advanced button, text fields allowing the storage of the Sauce OnDemand Host and Port are displayed.

    Multi-configuration Jobs

    Multi-configuration Jobs can be setup to run against a series of browsers supported by Sauce OnDemand. To configure this, select the Add Axis button on a Multi-configuration Job, then click the Sauce OnDemand Cross-browser tests link.

    add axis

    This will present a list of the browser versions (grouped by operating system) which are supported by Sauce OnDemand. The browsers which are selected will be invoked by the Selenium tests when run against Sauce OnDemand.

    Environment Variables

    The plugin will set a series of environment variables based on the information provided on the Job Configuration. These environment variables can either be explicitly referenced by your unit tests, or through the use of the [selenium-client-factory] library.

    • SELENIUM_HOST - The hostname of the Selenium server
    • SELENIUM_PORT - The port of the Selenium server
    • SELENIUM_PLATFORM - The operating system of the selected browser
    • SELENIUM_VERSION - The version number of the selected browser
    • SELENIUM_BROWSER - The browser string.
    • SELENIUM_URL - The initial URL to load when the test begins
    • SAUCE_USER_NAME - The user name used to invoke Sauce OnDemand
    • SAUCE_API_KEY - The access key for the user used to invoke Sauce OnDemand

    Note: These values are set automatically by the Jenkins plugin. If you are using Sauce Connect, SELENIUM_HOST and SELENIUM_PORT are set to ondemand.saucelabs.com:4445, such that all communication with our browsers is encrypted.