There are different ways to deal with these situations, depending on the type of browser you're testing against.
- Firefox includes a Profiles feature that lets you manage everything from passwords to security settings to site-specific settings, like which sites are allowed to display pop-ups. The Selenium driver for Firefox includes a
webdriver.firefox.profilesystem property that lets you select which profile you want to use in your testing.
- With Chrome, there is a long list of switches that you can set to change browser behavior, which you can pass as arguments to the Chrome WebDriver.
- Unfortunately, neither Safari or Internet Explorer have a built-in way to edit user settings, which is where pre-run executables come into play.
A pre-run executable is simply a script that you download to the Sauce Labs virtual machine and run prior to a test to change settings for Safari, Internet Explorer, or any other browser, or to configure the virtual machine that your tests will run on.
You can configure your Sauce testing jobs to use pre-run executables with the
prerun capability as described in Test Configuration Options.
Pre-run executables are commonly used to change browser settings and VM configurations before a test starts. This page provides a few examples of these scripts, and covers setting
prerun as a desired capability during test configuration.
Root and Administrative Permissions on Sauce Labs Virtual Machines
sudo access is not allowed on Linux/Mac virtual machines. Administrative access is not allowed on Windows VMs.
This example script disables the warning that Safari pops up when using basic HTTP authentication to access a website.
Match File Types to Your Operating System
When creating your executable file, take into account the operating system you'll use for your tests. For example, Bash commands won't work on Windows machines, which instead require a
This example sets
prerun to point to
myscriptstorage.com, which hosts the script
disable_fraud.sh used as an example in step 1.
This example accesses the same script from Sauce Storage:
One of the arguments that can be added to the
prerun capability in your test configuration options is
--silent, which can be abbreviated to
/S. This argument will "silently" install the executable without any modal dialogs or other installation processes showing up in your tests. Here's an example of how you would set the prerun capability to run in silent mode:
In Safari, when you try to navigate to a URL that uses basic HTTP authentication, a warning dialog pops up that will derail your automated tests unless you can resolve it. You can execute a short shell script as a pre-run executable to configure Safari to not show this message.
You can only use this for Safari versions up to and including 10.x.
This script clears the Warn when visiting a fraudulent website option in Safari's preferences, so that your automated tests that use basic authentication over HTTP will execute without triggering the warning.
The disable_fraud script used in the preceding examples is hosted as a Gist on GitHub.
You can use a pre-run executable script to download files from a public location to the Sauce Labs virtual machine running your tests. This topic contains example scripts for downloading remote files on different operating systems, and details configuring the prerun capability in your tests.
- Windows XP
This shell script will fetch the file at the URL and save it to /tmp/file.txt.
This batch file accomplishes the same thing as the OS X curl method, but using bitsadmin.exe since Windows doesn't ship with curl.
This batch file creates a VBScript file, dl.vbs, which will perform the download, and then runs it:
This shell script downloads file.txt at mywebsite.com to the /tmp directory.
After you've created the download script, use the prerun capability in your test script to point to its location.
If your script is in a publicly accessible location, you need to add the URL to the prerun capability.
Editing the Host file of the virtual machine will not work if Sauce Connect Proxy is in use because the Host file of the machine running Sauce Connect Proxy is referenced, so make the desired changes there, instead.
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 220.127.116.11 (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.
Here are examples of the host file script,
EditDNS, in both OS X/Linux and Windows versions.
If your test script is written in Java, you will need to create a JSON object if you want to include multiple arguments, such as
--silent, -a with the
The JSONObject Class/Library
Make sure your test script imports the
JSONObject class/library so you can create the JSON object.
If your test script is written in C#, you will need to create a Dictionary object with the
prerun capability as JSON Objects do not work well with C# projects.
The C# Dictionary Object
When creating the Dictionary object, make sure the TKey is of value "string" and the TValue is of value "object"
When you set the desired capabilities of your test, refer to the object you created as the path to the executable, as in this example:
When using Sauce Connect to run local tests on a Windows machine, you may encounter an Integrated Windows Authentication (IWA) dialog, also known as NTLM or Domain authentication. This is because the machine that Sauce Connect is running on is used to look up the host where the site or application under test is located. If the host has IWA enabled, the authentication request will be passed back through Sauce Connect to the Sauce Labs browser. Because there is no registry key available on our Windows virtual machines to disable this authentication, the solution is to create an AutoIT script to respond to the dialog.
You can use the AutoIT Script editor to write and save your script.
The script for handling the IWA dialog should look like this:
For Username and mysupersecretpassword, enter the authentication credentials required by the Windows host.
When you save the script, it will be an .au3 file, and you will need to compile it as an .exe file. Once compiled, you can use it as a pre-run executable with this desired capability call:
If using Sauce Storage for your pre-run executable send the following desired capability:
The 64bit version of AutoIT works on IE11, and not on IE9. The 32bit version works with both browser versions.