Editing the Host file of the virtual machine will not work if Sauce Connect Proxy is in use. If you are using Sauce Connect Proxy, the Host file of the machine running Sauce Connect Proxy will be referenced and you can make the desired changes there.
An example of configuring a Sauce Labs virtual machine with a pre-run executable is editing the host file in the virtual machine, so when the driver tries to access a particular domain, like google.com, it will be redirected to a new IP address, for example 22.214.171.124 (saucelabs.com). As with other prerun configurations, the basic steps are:
- Write a script with the URL redirect to the new IP address.
- Upload the script to a publicly accessible location, like GitHub or Sauce Storage
- Set the
preruncapability in your test script to load the script as host file in the Sauce Labs virtual machine.
The Host File Script
Here are examples of the host file script,
EditDNS,in both OS X/Linux and Windows versions.
Setting the prerun Capability in Your Test Script
Having created and uploaded your host file script, you now need to refer to it using the prerun capability in your script, as shown in this Python example.