The Sauce Labs Cookbook

Sauce Headless

Front End Performance Testing

Analytics

External Resources

More Info


Page tree
Skip to end of metadata
Go to start of metadata

SOLUTION NOT RECOMMENDED

The Selenium Relay is a listener for Selenium commands built into Sauce Connect that enables all inbound and outbound test traffic to be sent through an encrypted tunnel. It is an optional configuration that specifies that all outbound Selenium commands be sent through the Selenium Relay to the Sauce Labs browser cloud, rather than over HTTP/HTTPS.

This solution is not recommended. The added traffic can impact performance of the server where Sauce Connect is running and Selenium Relay itself is an extra dependency that can impact test performance. Additionally, you won't be able to use the Sauce Connect High Availability Setup, which it is not compatible 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. 

See the following sections for more information:

Setting Up Your Tests to Use the Selenium Relay

There are a few situations in which you might want to use Sauce Connect as a Selenium Relay: 

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

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 would 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 – including test commands – through the tunnel. 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 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 Connect 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