Skip to content

Description of App.config file

Jakub Raczek edited this page Apr 25, 2019 · 41 revisions

App.config file should be added as a content to your project during installation of each Ocaramba.... 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 false in all App.config files, for Firefox 47 and lower set it to true, more details here

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

If you want to pass path to Firefox browser e.g. FirefoxPortable set Firefox as a browser and set proper FireFoxBrowserExecutableLocation full path e.g. C:\FirefoxPortable\FirefoxPortable.exe.

    <add key="browser" value="Firefox" />
    <add key="FireFoxBrowserExecutableLocation" value="C:\FirefoxPortable\FirefoxPortable.exe" /> 

If you want to pass full path to the directory containing geckodriver.exe set proper PathToFirefoxDriverDirectory full directory path e.g. C:\GeckoDriver.

    <add key="PathToFirefoxDriverDirectory" value="C:\GeckoDriver" /> 

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

    <add key="browser" value="RemoteWebDriver" />
    <add key="DriverCapabilities" value="Firefox" />
    <add key="RemoteWebDriverHub" value="http://localhost:4444/wd/hub" />

more details here

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 PathToFirefoxProfile if you want to use default FireFox profile instead of creating new one.

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

Set SynchronizationWithAngularEnabled to true if you want to enable synchronization with AngularJS.

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

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 Ocaramba.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); }
        }

You can update App.config file by powershell script before test execution, more details here

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="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>
  <appSettings>
    <!--mandatory keys-->
    <add key="protocol" value="https"/>
    <add key="host" value="github.com"/>
    <add key="url" value="/ObjectivityLTD/Test.Automation"/>
    <!--<add key="browser" value="Chrome" />-->
    <!--<add key="browser" value="InternetExplorer" />-->
    <!--<add key="browser" value="Firefox" />-->
    <!--<add key="browser" value="Safari" />-->
    <!--<add key="browser" value="Edge" />-->
    <!--<add key="browser" value="RemoteWebDriver" />-->
    <add key="browser" value="Firefox"/>
    <!--Set path to the directory containing Drivers, leave it empty for default locations \bin-->
    <add key="PathToChromeDriverDirectory" value=""/>
    <add key="PathToFirefoxDriverDirectory" value=""/>
    <add key="PathToInternetExplorerDriverDirectory" value=""/>
    <add key="PathToEdgeDriverDirectory" value=""/>
    <!--Set path and file name of the browsers executable, leave it empty for default locations-->
    <add key="ChromeBrowserExecutableLocation" value=""/>
    <add key="FireFoxBrowserExecutableLocation" value=""/>
    <add key="FirefoxUseLegacyImplementation" value="false"/>
    <!--Set path path to firefox profile, leave it empty for default-->
    <add key="PathToFirefoxProfile" value=""/>
    <!--Set RemoteWebDriverHub if using RemoteWebDriver as browser-->
    <add key="RemoteWebDriverHub" value="http://localhost:4444/wd/hub"/>
	<!--Set DriverCapabilities if using RemoteWebDriver as browser-->
    <add key="DriverCapabilities" value="Firefox"/>
    <!--<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="null"/>
    <add key="password" value="null"/>
	 <!--Downloading files-->
	 <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"/>
    <!--nlog trace level must be set to "trace" for at least one logger to see EventFiringWebDriver logs-->
    <add key="EnableEventFiringWebDriver" value="false"/>
    <add key="JavaScriptErrorLogging" value="true"/>
    <!--JavaScript errors type to be search on browser logs-->
    <add key="JavaScriptErrorTypes" value="SyntaxError,EvalError,ReferenceError,RangeError,TypeError,URIError,Refused to display,Internal Server Error,Cannot read property" />
	<!--Enable or disable synchronization with AngularJS, can be also set in source code this.Driver.SynchronizeWithAngular(true);-->    
    <add key="SynchronizationWithAngularEnabled" value="false"/>
  </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>
  <FirefoxArguments>
    <!--<add key="FirefoxArgument" value=""/>-->
  </FirefoxArguments>
  <ChromePreferences>
    <!--add key="PreferenceToBeOverride" value="NewValue" /-->
  </ChromePreferences>
  <ChromeExtensions>
    <!-->add key="ChromePluginName.crx" value=""/-->
  </ChromeExtensions>
  <DriverCapabilities>
    <!-->add key="CapabilityName" value=""/-->
  </DriverCapabilities>
  <ChromeArguments>
    <!--<add key="ChromeArgument" value=""/>-->
  </ChromeArguments>
  <InternetExplorerPreferences>
    <!--<add key="InternetExplorerArgument" value=""/>-->
  </InternetExplorerPreferences>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>
Clone this wiki locally