Solution Blog

Leveraging Sauce Labs with GitLab

  • 4 April 2021
  • 0 replies
  • 112 views

Badge

GitLab, Meet Sauce Labs!

This is a high level guide intended for anyone who is curious about how Gitlab’s Continuous Integration platform works with Sauce Labs.

  1. What is Gitlab

  2. How Sauce Labs fits in with Gitlab

  3. Sauce Connect and Gitlab

  4. Additional Resources

 

What is Gitlab:

Gitlab is a collaboration platform that allows you to build a Continuous Integration (CI) pipeline as a series of steps in a .yml file. Steps can include things like launching a containerized test environment and starting your tests using your preferred test runner. 

Building a Gitlab .yml file to set up your pipeline is easy because Gitlab allows you to configure your environment the same way you would to run a shell script. Gitlab also has a simple way of launching docker images as “services”. This may be something to consider or explore when building your pipeline. 

 

How Sauce Labs fits in with Gitlab

Mostly, seamlessly.  There may be a few adjustments needed if you use Sauce Connect, or wish to run different tests in different CI Stages.

If your tests are running locally they may currently point to your internal selenium grid or local simulators. When you configure your tests to run on the Sauce Labs platform you will change your tests to point to a Sauce Labs data center and our VMs/Real Devices/Emulators/Simulators. 

Since this code change is within your test scripts which would then be run with a command like “mvn test” or “npm run test” in your Gitlab .yml file, there is no Gitlab specific Sauce Labs integration needed! However the way in which you set up your Gitlab pipeline, may determine how you would like to initiate the Sauce Connect Proxy which we will cover in the next section.

If you are newer to building a CI pipeline one of the things you’ll notice they have in common is repeatable steps/phases that make them adaptable to your business needs. Your tests that run on the Sauce Labs platform may be included in one of those steps. In the Gitlab example below we’ve used step 3 to run our end-to-end suite. We’ve named it e2e-Sauce to indicate that it runs on Sauce Labs, but you can name yours anything. 

 

Sauce Connect and Gitlab

We recommend using a High Availability setup for Sauce Connect

Sauce Connect Proxy is a built-in HTTP proxy server that opens a secure "tunnel" connection for testing between a Sauce Labs virtual machine or real device and a website or mobile app hosted on your local computer ("localhost") or behind a corporate firewall. It provides a means for Sauce Labs to access your application or website. 

Sauce Connect can be downloaded and managed a few different ways. Some of which lend themselves better to Gitlab, but all are do-able. 

  1. Users download the Sauce Connect Binary and run it as a service on a dedicated machine (VM/server) that is available 24/7. This instance of Sauce Connect is shared by the organization and utilized by the tests running in the CI pipeline. This is the recommended method of running the Sauce Connect Proxy which we call “High Availability”. 

  2. Using bash or equivalent within the gitlab .yml file, users can download Sauce Connect to a container and run it as a set up step in their CI. Below is an example of what this might look like. This method may be helpful for users who are experienced with shell scripting and gitlab. 

u5gDag6hyYtjvr6kkZrsfzp5EiUAU_IWbuaqjRik0txebTze_eRpow9wIahvLsSByjA7Zxf-ND2vmAeDjkmkJcrX1Kh7LprDjqFDtkRU_ypE58eI7IC-TmStGLCvoYz0MAZenajP

  1. Users download the Sauce Connect binary and start it using their CLI. In their tests they add a configuration option to ensure the tests run through the tunnel so that the Sauce Labs VM or Device can reach the application under test or website. This is not the preferred method using Gitlab because users will have to ensure that their Sauce Connect Proxy is running prior to their pipeline kicking off, which adds a manual step to an automated process.

  2. (Coming Soon) Users may also have the option to call the Sauce Connect Docker image as “Service” in their .yml file. Currently this option does not have a way to configure Sauce Connect using any special flags. These are often necessary for troubleshooting and customization. 

 

Additional Resources 

Pointing your tests at the Sauce Labs Data Center 

Sauce Connect Proxy Security Overview


0 replies

Be the first to reply!

Reply