Override browser profile preferences, install browser extensions

Jakub Raczek edited this page Jun 26, 2018 · 10 revisions

Our framework supports overriding browser profile preferences set in DriverContext class or adding additional not included in our code, passing arguments to browsers and installing browser extensions. It can be done by adding settings in FirefoxPreferences, FirefoxArguments and FirefoxExtensions or ChromePreferences, ChromeArguments and ChromeExtensions sections of App.config file.

<?xml version="1.0" encoding="utf-8"?>
  <configSections>
    <section name="FirefoxPreferences" type="System.Configuration.NameValueSectionHandler"/>
    <section name="FirefoxExtensions" type="System.Configuration.NameValueSectionHandler"/>
    <section name="FirefoxArguments" type="System.Configuration.NameValueSectionHandler"/>
    <section name="ChromePreferences" type="System.Configuration.NameValueSectionHandler"/>
    <section name="ChromeExtensions" type="System.Configuration.NameValueSectionHandler"/>
    <section name="DriverCapabilities" type="System.Configuration.NameValueSectionHandler"/>
    <section name="ChromeArguments" type="System.Configuration.NameValueSectionHandler"/>
    <section name="InternetExplorerPreferences" type="System.Configuration.NameValueSectionHandler"/>
</configSections>
...
  <FirefoxPreferences>
    <add key="PreferenceToBeOverride" value="NewValue" />
  </FirefoxPreferences>
  <FirefoxExtensions>
    <add key="FirefoxPluginName.xpi" value=""/>
  </FirefoxExtensions>
  <ChromePreferences>
    <add key="PreferenceToBeOverride" value="NewValue" />
  </ChromePreferences>
  <ChromeExtensions>
    <add key="ChromePluginName.crx" value=""/>
  </ChromeExtensions>
  <ChromeArguments>
    <add key="--headless" value=""/>
  </ChromeArguments>
 <InternetExplorerPreferences>
+    <add key="EnsureCleanSession" value="false"/>
+  </InternetExplorerPreferences>
</configuration>

To pass arguments to Chrome browser to e.g. start in headless mode add this section to your App.config file

  <ChromeArguments>
    <add key="--headless" value=""/>
  </ChromeArguments>

To start e.g. FireFox with FireBug extension copy firebug-x.x.x-fx.xpi file to bin folder of your project and add this section to your App.config file

  <FirefoxExtensions>
    <add key="firebug-2.0.19-fx.xpi" value=""/>
  </FirefoxExtensions>

To overwrite any e.g. Firefox preferences or add new one add this section to your App.config file

 <FirefoxPreferences>
    <add key="network.automatic-ntlm-auth.trusted-uris" value="servername1,servername2" />
  </FirefoxPreferences>

With the InternetExplorer you can only override EnsureCleanSession and IgnoreZoomLevel preferences, by default both are set to true in DriverContext class.

In order to start FireFox with default firefox profile edit following section in your App.config file, set proper path to FireFox default profile.

<!--Use default firefox profile?-->
<add key="UseDefaultFirefoxProfile" value="true"/>
<add key="PathToFirefoxProfile" value="C:\Users\username\AppData\Roaming\Mozilla\Firefox\Profiles"/>
Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.