Skip to content

Description of App.config file

Jakub Raczek edited this page Dec 9, 2016 · 41 revisions

App.config file should be added as a content to your project during installation of each Objectivity.Test.Automation.Common.... nuget packages. Each of setting from that file is also available in your test project by using properties from BaseConfiguration class.

 this.Driver.IsElementPresent(this.downloadPageHeader, BaseConfiguration.ShortTimeout);

Change settings stored in App.config to target your application under tests.

Set proper <add key="protocol" value="http" /> or <add key="protocol" value="https" />, and name of server<add key="host" value="the-internet.herokuapp.com" />, optionally <add key="url" value="/home" />. Choose the browser for test execution <add key="browser" value="Firefox" />.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
...
    <add key="protocol" value="http" />
    <add key="host" value="the-internet.herokuapp.com" />
    <add key="url" value="" />
    <add key="browser" value="Firefox" />
...
</configuration>

Option FirefoxUseLegacyImplementation set as true in all App.config files, for Firefox 48 and higher set it to false, more details here

<add key="FirefoxUseLegacyImplementation" value="true" />

If you selected FirefoxPortable as a browser set proper FireFoxPath (relative).

    <add key="browser" value="FirefoxPortable" />
    <add key="FireFoxPath" value="\..\..\..\FirefoxPortable\FirefoxPortable.exe" /> 

If you selected PhantomJs as a browser set proper PhantomJsPath (relative).

    <add key="browser" value="PhantomJs" />
    <add key="PhantomJsPath" value="\..\..\..\packages\PhantomJS.2.1.1\tools\phantomjs\" /> 

If you selected RemoteWebDriver for Selenium Grid support as a browser set also DriverCapabilities.

    <add key="browser" value="RemoteWebDriver" />
    <add key="DriverCapabilities" value="Firefox" />

Uncomment proxy setting if you are going to use your tests with other tools like e.g. ZAP

    <add key="proxy" value="127.0.0.1:9999" />

Set timeouts to better fit performance of your web application under tests.

    <!--Timeouts-->
    <add key="longTimeout" value="30" />
    <add key="mediumTimeout" value="10" />
    <add key="shortTimeout" value="3" />

Click on links to find more details about settings for taking screen shots: full desktop, selenium, page source saving and downloading files.

    <!--Downloaded files, screenshots and page source location-->
    <add key="UseCurrentDirectory" value="true"/>
    <add key="DownloadFolder" value="\TestOutput"/>
    <add key="ScreenShotFolder" value="\TestOutput"/>
    <add key="PageSourceFolder" value="\TestOutput"/>
    <!--Screenshots and logging-->
    <add key="FullDesktopScreenShotEnabled" value="true"/>
    <add key="SeleniumScreenShotEnabled" value="true"/>
    <add key="GetPageSourceEnabled" value="true"/>

Set UseDefaultFirefoxProfile to true if you want to use default FireFox profile instead of creating new one.

    <!--Use default firefox profile?-->
    <add key="UseDefaultFirefoxProfile" value="true"/>
    <add key="PathToFirefoxProfile" value="C:\Users\username\AppData\Roaming\Mozilla\Firefox\Profiles" />

Description about nlog section can be found here.

Description about FirefoxPreferences, FirefoxExtensions and ChromePreferences, ChromeExtensions sections can be found here.

The DataDrivenFile setting in needed only in Objectivity.Test.Automation.Common.NUnit, more details here.

You can add new settings to App.config file and make them available in your test project by implementing similar methods in e.g. ProjectBaseConfiguration class.

    using System;
    using System.Configuration;
    using System.Globalization;

    public static class ProjectBaseConfiguration
    {
        public static bool MyNewBoolSetting
        {
            get
            {
                if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["MyNewBoolSetting"]))
                {
                    return false;
                }

                if (ConfigurationManager.AppSettings["MyNewBoolSetting"].ToLower(CultureInfo.CurrentCulture).Equals("true"))
                {
                    return true;
                }

                return false;
            }
        }

        public static string MyNewStringSetting
        {
            get { return ConfigurationManager.AppSettings["MyNewStringSetting"]; }
        }

        public static double MyNewDoubleSetting
        {
            get { return Convert.ToDouble(ConfigurationManager.AppSettings["MyNewDoubleSetting"], CultureInfo.CurrentCulture); }
        }

Full content of App.config file.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
    <section name="FirefoxPreferences" type="System.Configuration.NameValueSectionHandler"/>
    <section name="FirefoxExtensions" type="System.Configuration.NameValueSectionHandler"/>
    <section name="ChromePreferences" type="System.Configuration.NameValueSectionHandler"/>
    <section name="ChromeExtensions" type="System.Configuration.NameValueSectionHandler"/>
  </configSections>
  <appSettings>
    <!--mandatory keys-->
    <add key="protocol" value="http" />
    <add key="host" value="the-internet.herokuapp.com" />
    <add key="url" value="" />
    <!--<add key="browser" value="Chrome" />-->
    <!--<add key="browser" value="InternetExplorer" />-->
    <!--<add key="browser" value="Firefox" />-->
    <!--<add key="browser" value="FirefoxPortable" />-->
    <!--<add key="browser" value="PhantomJs" />-->
    <add key="browser" value="Firefox" />
    <add key="FirefoxUseLegacyImplementation" value="true" />
    <add key="FireFoxPath" value="\..\..\..\FirefoxPortable\FirefoxPortable.exe" />
    <add key="PhantomJsPath" value="\..\..\..\packages\PhantomJS.2.1.1\tools\phantomjs\" />
    <!--<add key="proxy" value="127.0.0.1:9999" />-->
    <!--Timeouts-->
    <add key="longTimeout" value="30" />
    <add key="mediumTimeout" value="10" />
    <add key="shortTimeout" value="3" />
    <add key="ImplicitlyWaitMilliseconds" value="200" />
    <!--User credentials-->
    <add key="username" value="admin" />
    <add key="password" value="admin" />
    <!--Downloaded files, screenshots and page source location-->
    <add key="UseCurrentDirectory" value="true"/>
    <add key="DownloadFolder" value="\TestOutput"/>
    <add key="ScreenShotFolder" value="\TestOutput"/>
    <add key="PageSourceFolder" value="\TestOutput"/>
    <!--Screenshots and logging-->
    <add key="FullDesktopScreenShotEnabled" value="true"/>
    <add key="SeleniumScreenShotEnabled" value="true"/>
    <add key="GetPageSourceEnabled" value="true"/>
    <!--DataDrivenFile-->
    <add key="DataDrivenFile" value="\DataDriven\DataDriven.xml" />
    <!--Use default firefox profile?-->
    <add key="UseDefaultFirefoxProfile" value="true"/>
    <add key="PathToFirefoxProfile" value="C:\Users\username\AppData\Roaming\Mozilla\Firefox\Profiles" />
  </appSettings>
  <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
      autoReload="true"
      throwExceptions="false"
      internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log" >
    <targets>
      <target name="logfile" xsi:type="File" fileName="${basedir}\Test.log" layout="${longdate}|${level}|${callsite}|${message}" />
      <target name="console" xsi:type="ColoredConsole" layout="${longdate}|${level}|${callsite}|${message}"/>
    </targets>
    <rules>
      <logger name="*" minlevel="Trace" writeTo="logfile" />
      <logger name="*" minlevel="Debug" writeTo="console" />
    </rules>
  </nlog>
  <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>
</configuration>
Clone this wiki locally