Skip to end of metadata
Go to start of metadata

The Selenium Relay is a listener for Selenium commands that's built into Sauce Connect. When you set up Sauce Connect, you can specify that all outbound Selenium commands be sent through the Selenium Relay to the Sauce Labs browser cloud, rather than over HTTP/HTTPS. This is an optional configuration, but there are a few situations in which you might want to use Sauce Connect as a Selenium Relay: 

  1. When you're running tests written in Python that can't use HTTPS because of the known issue with the Selenium Python bindings.
  2. When you only want to allow machines in a DMZ to have access to Sauce Labs.
  3. When you want to make sure all Selenium commands are routed through a Sauce Connect tunnel.

Using the Selenium Relay means all inbound and outbound test traffic is sent through an encrypted tunnel, but it has some downsides. The server where Sauce Connect is running will experience some performance impact because of the additional traffic, and the Selenium Relay itself is an extra dependency that can impact test performance. You also can't use the Sauce Connect High Availability feature with the Selenium Relay because all traffic must be routed through a specific listener. You'll have better test performance if you use HTTPS to connect with Sauce Labs, or if you use a corporate proxy to control outbound traffic. 

Setting Up Your Tests to Use the Selenium Relay

Connecting Directly to Sauce Labs Over HTTPS

This example shows how you would specify the connection to Sauce Labs over HTTPS in a Java test script:

public static final String URL = "https://" + USERNAME + ":" + ACCESS_KEY + "@ondemand.saucelabs.com:443/wd/hub";

Connecting to Sauce Labs through the Selenium Relay

To use the Selenium Relay, you substitute the name of the server where Sauce Connect is installed, and the listener port (default is 4445), for ondemand.saucelabs.com:

public static final String URL = "http://" + USERNAME + ":" + ACCESS_KEY + "@mymachine.mydomain.com:4445/wd/hub";

You can change the listener port with the -P, --se-port command as described in the Sauce Connect Command Line Reference.

If you have Sauce Connect installed on your local machine, you would use localhost for the name of the server:

public static final String URL = "http://" + USERNAME + ":" + ACCESS_KEY + "@localhost:4445/wd/hub";

Routing Protractor Traffic through Sauce Connect Proxy

One of the features of Sauce Connect is the ability to send all traffic through the tunnel, including test commands.  Typically, your Selenium commands are sent to Sauce's servers over the standard internet, and only browser requested traffic goes via Sauce Connect.  In some restricted networks, access to Sauce's servers isn't available over port 80 on the standard internet;  In these cases, sending all traffic through the Sauce Connect tunnel is the easiest way to get your tests running.

You achieve this by pointing your Remote WebDriver at the address and port of the Sauce Connect tunnel, instead of http://ondemand.saucelabs.com.  By default, Sauce Connect defaults to port 4445, so you'd use localhost:4445/wd/hub.  You can change this port by passing the --se-port option to Sauce Connect.

When using Protractor, the standard Sauce configuration doesn't allow for alternative endpoint addresses.  Instead, you can use the sauceSeleniumAddress config value to set a custom Selenium address: 

exports.config = {
      sauceSeleniumAddress: 'localhost:4445/wd/hub',
      sauceUser: process.env.SAUCE_USERNAME,
      sauceKey: process.env.SAUCE_ACCESS_KEY
    }

This feature  is available in Protractor 1.6.1 and up!

  • No labels