The Sauce Labs Cookbook

Sauce Headless

Front End Performance Testing

Insights

External Resources

More Info


Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Status badges and the Sauce Labs browser matrix widget help you keep track of the status of your latest test runs. All you have to do is add either markdown or HTML code to your GitHub README or project site that references your Sauce Labs username and access key, and annotate your jobstests with the REST or WebDriver API

Table of Contents

Status Badges and the Browser Matrix

There are three four status badges that correspond to the three states of a finished test: Passing, Failed, Error, and Unknown.

BadgeStatus
Image Removed
Image Added
Passing
Image Added
Failing
Image RemovedFailedImage RemovedUnkonwn
Image Added
This status is set if the build errors out due to an internal error (one or more sessions have crashed)
Image Added
This status is set if one or more jobs of the latest build haven't been reported as passed or failed. This state is equivalent to Finished.

With the browser matrix, you can keep track of the test status of your project for various browser/platform/operating system combinations.

Image Removed

Setting Up Status Badges for Test Results

  1. Choose a Sauce account to associate with your project. If you just have one project, you can use your main Sauce account name. If you have multiple projects, you will want to create a sub-account for each project.

  2. Run your tests for a given project on Sauce using that account's username and access key. If you are logged in as the account you want to use, you can find your credentials on the account page. If you are logged in as a parent account, you can see your sub-account usernames and access keys on the sub-accounts page.

    sauce-labs-browser-matrixImage Removed
  3. Make sure to set a build number a pass/fail status and a visibility (to either 'public', 'share' or 'public restricted') for every test that runs. You will be able to see that these are set correctly by seeing that your tests say "Pass" or "Failed" instead of "Finished" and that a build number is visible in the UI.

Note: If your tests don't have a build or pass/fail status, you'll get the "Unknown" image for security reasons.

 Adding the Standard Badge

sauce-badge-passingImage Removed sauce-badge-failImage Removed sauce-badge-unknownImage Removed


You can copy/paste the following Markdown into your GitHub README:Build Status Badge Example

Markdown
![Build Status](https://app.saucelabs.com/buildstatus/axios)


Browser Matrix Badge Example

Markdown
![Browser Matrix](https://app.saucelabs.com/browser-matrix/axios.svg)


Setting Up Status Badges for Test Results

  1. Copy this markdown code into your GitHub README.

    Code Block
    [![Sauce Test Status](https://app.saucelabs.com/buildstatus/

...

  1. YOUR_SAUCE_USERNAME)](https://app.saucelabs.com/u/

...

  1. YOUR_SAUCE_USERNAME)

...

...

  1. Alternatively, you can

...

  1. use this HTML code on your project site

...

  1. .

    Code Block
    languagexml
    <a href="https://app.saucelabs.com/u/

...

  1. YOUR_SAUCE_USERNAME">
      <img src="https://app.saucelabs.com/buildstatus/

...

  1. YOUR_SAUCE_USERNAME" alt="Sauce Test Status"/>
    </

...

  1. a> 
    Tip
    titleMultiple Projects, Multiple Accounts

    If you just have one project, you can use your main Sauce account name. If you have multiple projects, you will want to create a sub-account for each project. 

  2. Run your tests.

  3. Make sure to set a build number, a pass/fail status, and a public, share, or public restricted visibility for every test that runs using the Test Configuration Options.
    You'll know that these are set correctly if your tests have a status of Pass or Failed instead of Finished on your dashboard, and that a build number is also displayed.

Setting Up the Browser Matrix Widget

sauce-labs-browser-matrixImage Removed

You can copy/paste the following Markdown into your GitHub README:Copy this markdown code into your project's GitHub README.

Code Block
[![Sauce Test Status](https://app.saucelabs.com/browser-matrix/

...

YOUR_SAUCE_USERNAME.svg)](https://app.saucelabs.com/u/

...

YOUR_SAUCE_USERNAME)

...

Or Alternatively, you can add the following this HTML to your project site:.

Code Block
languagexml
<a href="https://app.saucelabs.com/u/

...

YOUR_SAUCE_USERNAME">
  <img src="https://app.saucelabs.com/browser-matrix/

...

YOUR_SAUCE_USERNAME.svg" alt="Sauce Test Status"/>
</

...

a> 


Note that the above information applies to Open Sauce accounts only. Open Sauce accounts are public, meaning tests and build status can be viewed without authentication. In order to use the above for any other type of account, read on.

Status Images for Private Accounts

To If you want to display the build status of a private Sauce account, you need to provide a Hash-based Message Authentication Code (HMAC) token generated from your username and access key. Here is how you could generate one in python:

Note: if you don't have python on your system, check out this link for HMAC http://en.wikipedia.org/wiki/HMAC#External_links

First start the python interpreter with the following command:

python

Then run the following code in the interpreter to generate a query param to add to badge image URLs:

This example shows how to generate an HMAC token using Python:

Code Block
python
from hashlib import md5
import hmac
"?auth=" + hmac.new("

...

YOUR_SAUCE_USERNAME:YOUR_SAUCE_ACCESSKEY", None, md5).hexdigest()

...

Once the auth token has been obtained, it can be appended to one of the above badge URLs as the value of the auth query like this:

...

This is an example to show that the HMAC token should be generated using your Sauce Labs username and access key. You can find many examples of how to accomplish this in other languages with a quick web search, such as here. As the above example shows, the HMAC token should be generated using the md5 cryptographic algorithm, and with no secret.

Once you have the token, append it to the badge URL:

Code Block
https://app.saucelabs.com/buildstatus/YOUR_SAUCE_USERNAME?auth=HMAC_TOKEN


Example Demo

Follow the instructions below to run the sample demo that exists in the saucelabs-training GitHub organization:

View Git file
pathREADME.md
lastline44
repository-id47
firstline19
branchrefs/remotes/origin/master