Docs integration

Results Integration

In Selenium, when a client requests a new browser session, the server returns a session ID, which is used to identify that session throughout the test. The session ID is stored as a member variable of the instantiated Selenium object and named "sessionId" or "session_id," depending on the client library. We use that session ID as the job id for accessing test results on our website.

To directly access a specific job, you will first need to note the session ID locally, usually by writing it to a log file. You can then use it to create a URL with the following format and replace <jobid> with the session ID.

http://saucelabs.com/jobs/<jobid>

Notice that links to jobs in this format will only work if you are logged in with the account that ran the job or if that account is a subaccount of yours. For generating public links, read the section below, no-login links to jobs.

Note: Selenium 1's Java client does not give public access to the session ID attribute of the DefaultSelenium object. However, we store a selenium.sessionId JavaScript variable that you can access using getEval.

The links generated in login required links to jobs can be made in a way that doesn't require anonymous viewers to login and use your credentials. This mechanism is based in authentication tokens.

Auth tokens are generated on per job basis and give the receiver access using an hmac-based algorithm. You can also find hmac implementations for the different programming languages.

The digest algorithm to use is MD5. The message and key used to generate the token should be the following:

Key: <username>:<access-key>
Message: <job-id>

Here's an example in Python for generating the token for a job with id: 5f9fef27854ca50a3c132ce331cb6034

  >>> import hmac
  >>> from hashlib import md5
  >>> hmac.new("example_user:123456-asdf-8dcf81f1fc71", "5f9fef27854ca50a3c132ce331cb6034", md5).hexdigest()
  '3fca4184e106622adf2d33d8023271c1'
  

Once the auth token has been obtained, it can be used to build a link in the following format:

https://saucelabs.com/jobs/<job-id>?auth=<token>

For our example job, the link would end up being:

https://saucelabs.com/jobs/5f9fef27854ca50a3c132ce331cb6034?auth=8859d634f5a51fea1a66e74708cf822a

Notice: the link won't work as this job doesn't really exist.

There's a way to extend the links generated in no-login links to jobs to make them work only temporarily.

The authentication token can be generated in a way that provides 1 hour or 1 day of access to the job by using the following information for the hmac generation:

Key: <username>:<access-key>:<date-range>
Message: <job-id>

The date range can take two formats: YYYY-MM-DD-HH and YYYY-MM-DD. These should be set in UTC time and will only work during the date or hour chosen and the following.

Downloading job assets

You can download every asset created after your test runs on Sauce through our REST API. These include the video recording, Selenium log, and screenshots taken on crucial steps. After a standard job execution, the following files are created:

  • selenium-server.log
  • video.flv
  • XXXXscreenshot.png (where XXXX is a number between 0000 and 9999)
  • final_screenshot.png

To pull them, make a request matching the following pattern:

  GET https://saucelabs.com/rest/v1/<username>/jobs/<job_id>/assets/<file_name>
  

Sauce uses HTTP Basic Authentication. Each request needs to include an authorization HTTP header with your username and access key.

Here's an example using curl to download selenium-server.log:

  $ curl -u jhuggins:763a23a1-91e1-4f6b-be79-oiu722855hvh https://saucelabs.com/rest/v1/jhuggins/jobs/2z234fd4c4006b1e73faf3fa3cdadc75/assets/selenium-server.log
  

Embedding Results in HTML Pages

Embedding full job pages

We offer a simple way to embed job pages in CI test results or other test reports. Using the format below, add the HTML to any page you need to embed job results on, replacing <job_id> with the ID of the job you want:

  <script type="text/javascript" src="https://saucelabs.com/job-embed/<job_id>.js"></script>
  

Note: this will only work for browsers logged in using your account, and authentication tokens can be used to make this work for anonymous viewers. Check out no-login links to jobs for directions on generating these tokens.

Embedding the video player

In addition to full job results, we offer a simple way to embed videos as well. Using the format below, add the HTML to any page you need to embed job videos on, replacing <job_id> with the ID of the job you want:

  <script type="text/javascript" src="https://saucelabs.com/video-embed/<job_id>.js"></script>
  

Note: this will only work for browsers logged in using your account, and authentication tokens can be used to make this work for anonymous viewers. Check out no-login links to jobs for directions on generating these tokens. Here's how such a script might look:

  <script src="https://saucelabs.com/video-embed/7dcb077bfcfd43a0a9d50011dd3bc01c.js?auth=6a7dcf9f2d8e7039699bd0280a7f4504"></script>
  

REST API

For more advanced usage and integrations, you should read our REST API documentation.