Skip to main content

saucectl with GitHub Actions

These examples can apply to virtually any GitHub deployment, provided that you already have some existing automated tests, and are either the maintainer or an admin of the target repository.

What You'll Need

Create GitHub Secrets

The first order of business is to export your Sauce Labs account credentials and store them as GitHub Secrets.

  1. Navigate to your project repository and select the settings icon.

    GitHub Settings
  2. Select Secrets.

  3. Click the New secret button.

  4. Add the following:

    • Name: SAUCE_USERNAME
    • Value: 'your-sauce-username'
  5. Click Add secret to finish.

  6. Repeat the same steps above for your SAUCE_ACCESS_KEY.

Configure the GitHub Action

In your root project directory, create the following directory tree: .github/workflows. In the workflows directory create a file called actions.yml.

Add the following to the top of your file:

note

Setting env at the top of the file enables it globally in this workflow, so all jobs have access to these variables.

.github/workflows/test.yml
loading...

Create the Test Job

In the examples below, we illustrate the two different saucectl run modes, which will determine where your tests will execute:

  • Docker mode refers to executing tests locally in a container
  • Sauce Cloud mode refers to executing tests on Sauce Cloud (i.e., Sauce Labs infrastructure)
    • If you're testing on the Sauce Cloud, you will likely require a tunnel back to where your app is running. A tunnel enables the remote browser to access your local network. For this, you'll need to use Sauce Connect.
note

For more detailed information on setting event-driven actions and jobs, please visit the GitHub Action documentation.

.github/workflows/test.yml
loading...
note

You can reference our example workflows here.

Now when you commit these files, GitHub will detect the new workflow actions and launch saucectl to run your tests.

To see the output:

  1. Log in to GitHub.

  2. Navigate to your repository page.

  3. Click on Actions.

    GitHub Actions

Your output may look something like this:

GitHub Workflow