Setting Capabilities for WebDriver-Based Browsers

If you are testing a web application on a WebDriver-based browser, you can customize and configure the browser session by setting the capabilities.

In Silk4NET, you can specify WebDriver capabilities in the connection string for the following browser types:
  • Google Chrome
  • Mozilla Firefox

For information on the available options and capabilities for Mozilla Firefox 48 or later, see https://github.com/mozilla/geckodriver. For information on the available options and capabilities for Google Chrome, see Capabilities & ChromeOptions.

To set the capabilities in Silk4NET:

  1. Select the project which corresponds to the web application for which you want to change the capabilities.
  2. Edit the connection string in the base state of the project. You can edit the connection string in the following ways:
    • By using the Edit Application Configurations dialog, for example if you want to record actions against a customized browser.
    • In a script, if you only want to execute the tests in the script against the customized browser.

    For additional information, see Base State.

  3. Execute the script to start the browser with the specified options and capabilities.

Examples

You can add the following code to the base state in a script to automatically download executables from Mozilla Firefox:
' VB .NET code - No linebreaks, this is a single line of code.
 baseState.ConnectionString = "moz:firefoxOptions={\"prefs\": { \"browser.download.folderList\": 2, \"browser.helperApps.neverAsk.saveToDisk\": \"application/octet-stream\"}};"
// C# code - No linebreaks, this is a single line of code.
 baseState.ConnectionString = "moz:firefoxOptions={\"prefs\": { \"browser.download.folderList\": 2, \"browser.helperApps.neverAsk.saveToDisk\": \"application/octet-stream\"}};";
You can add the following code to the base state in a script to specify the download folder for Mozilla Firefox:
' VB .NET code
baseState.ConnectionString = "moz:firefoxOptions={\"prefs\": { \"browser.download.dir\" : \"C:/Download\"}};"
// C# code
baseState.ConnectionString = "moz:firefoxOptions={\"prefs\": { \"browser.download.dir\" : \"C:/Download\"}};";
You can add the following code to the base state in a script to set a command line argument for Mozilla Firefox:
' VB .NET code
baseState.ConnectionString = "moz:firefoxOptions={\"args\":[\"--devtools\"]};"
// C# code
baseState.ConnectionString = "moz:firefoxOptions={\"args\":[\"--devtools\"]};";
You can add the following code to test on Mozilla Firefox with a proxy server:
' VB .NET code
baseState.ConnectionString = "moz:firefoxOptions={\"prefs\": { \"network.proxy.http\": \"" + PROXY_HOST + "\", \"network.proxy.http_port\": " + PROXY_PORT + ", \"network.proxy.type\": 1 }};"
// C# code
baseState.ConnectionString = "moz:firefoxOptions={\"prefs\": { \"network.proxy.http\": \"" + PROXY_HOST + "\", \"network.proxy.http_port\": " + PROXY_PORT + ", \"network.proxy.type\": 1 }};";
You can add the following code to the base state in a script to automatically download executables from Google Chrome to a specific folder:
' VB .NET code - No linebreaks, this is a single line of code.
baseState.ConnectionString = "chromeOptions={\"prefs\": {\"profile.default_content_setting_values.automatic_downloads\":1, \"download.default_directory\":\"c:/Download\", \"download.prompt_for_download\":false}};"
// C# - No linebreaks, this is a single line of code.
baseState.ConnectionString = "chromeOptions={\"prefs\": {\"profile.default_content_setting_values.automatic_downloads\":1, \"download.default_directory\":\"c:/Download\", \"download.prompt_for_download\":false}};";
You can add the following code to the base state in a script to disable the password manager from showing messages in Google Chrome:
' VB .NET code - No linebreaks, this is a single line of code.
baseState.ConnectionString = "chromeOptions={\"args\": [\"--disable-save-password-bubble\"], \"prefs\": {\"profile.password_manager_enabled\":false, \"credentials_enable_service\":false}};"
// C# code - No linebreaks, this is a single line of code.
baseState.ConnectionString = "chromeOptions={\"args\": [\"--disable-save-password-bubble\"], \"prefs\": {\"profile.password_manager_enabled\":false, \"credentials_enable_service\":false}};";