What is Sauce Connect Proxy?
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 Proxy Benefits
Sauce Connect Proxy has some other uses in your testing network architecture:
Provides ability to monitor upstream traffic through a proxy like BrowserMob
Stabilizes network connections (e.g., detecting and re-sending dropped packets)
You can use WonderProxy to change the Geolocation of your test traffic
How Sauce Connect Proxy Works
Sauce Connect Proxy is based on a proprietary protocol that runs over TLS and is available for use by any Sauce Labs account. For information on downloading, setting up, and configuring Sauce Connect Proxy in your network architecture, please see the topics under Getting Started with Sauce Connect Proxy and Sauce Connect Proxy Setup and Configuration.
All requests and responses between the browsers running the Selenium test and the web servers pass through it. Since Sauce Connect Proxy is just being used internally in your Sauce Labs testing, it doesn't matter which port it uses. A free port is allocated dynamically when Sauce Connect Proxy is started.
Why Docker?
If you’re not sure where Docker fits, consider these use cases:
If you’re creating automation (or manual testing) for multiple applications that reside in different environments, say for example: Desktop Web and Headless. They need to create two different Sauce Connect tunnels in both environments. Keep in mind this is flexible so you could create a Sauce Connect tunnel in all the sauce environments using this approach as well.
If you’re creating multiple High Availability Sauce Connect tunnels on the same system, without having to manage or use different ports.
If you no longer want to manage Sauce Connect versions
If any of these apply to you, or are even in the neighborhood of your situation, keep reading.
Sauce Connect Docker Image
Supported Tags
How to Use Sauce Connect Docker Image
Before we can run the container you need to pull it from Docker Hub:
$ docker pull saucelabs/sauce-connect
This will pull the latest version of Sauce Connect which we recommend to use. You can always specify a specific tag. To run the image, execute:
$ export SAUCE_USERNAME="my-user"
$ export SAUCE_ACCESS_KEY="my-access-key"
docker run \
-e SAUCE_USERNAME=${SAUCE_USERNAME} \
-e SAUCE_ACCESS_KEY=${SAUCE_ACCESS_KEY} \
--network="host" \
-it saucelabs/sauce-connect
Additional arguments may be specified as you would normally do with Sauce Connect. Ensure you have --network="host" set as argument otherwise Sauce Connect within the Docker container can not access your local services in the host machine.
CI Example
If you want to run this Docker image as part of your CI/CD pipeline, you can run the following steps:
Create "wait-for-sc.sh" fileTo ensure we only continue our pipeline once Sauce Connect is fully connected, we need a simple shell script that waits for Sauce Connect to be ready:# wait-for-sc.sh
until [ -f /tmp/sc.ready ]
do
sleep 5
done
echo "SC ready"
exit
Pull docker image
$ docker pull saucelabs/sauce-connect
Start Sauce Connect. It is important that you mount a temp folder so that wait-for-sc.sh can detect when Sauce Connect has launched. Also make sure that you set --network="host" to allow Sauce Connect to access your application in the host machine.
$ docker run \
-e SAUCE_USERNAME=${SAUCE_USERNAME} \
-e SAUCE_ACCESS_KEY=${SAUCE_ACCESS_KEY} \
-v /tmp:/tmp \
--network="host" \
-t saucelabs/sauce-connect:latest \
-f /tmp/sc.ready \
-i some-identifier &
3. $ ./wait-for-sc.sh
Have a look into the GitHub Actions pipeline for this repository. If you use GitHub Actions you can just make use of our GitHub Actions Integration.