top of page

Selenium C# Tutorial: Developing App Configurations

Updated: Mar 5

In this tutorial, I will cover APP configurations as part of the automation framework. A configuration file is a single place to configure and control the test framework configuration. A configuration file should have the information required to manage the framework or add information that we can use as an audit for the test execution (which is very handy when working with large teams or complex automation projects).

A simple configuration file may include App settings such as:

  • Technology (e.g., Web, DB, UI, etc.)

  • Browser type used during tests

  • Log path

  • Test Type (e.g. integration, component, etc.)

Configurations using App.config

We can create our framework configuration using the inbuilt App.config, which is available in visual studio:

  1. Open Visual Studio

  2. Solution Explorer -> Add -> "Application Configuration File".

Now that we have created the config file, let's add some simple code to it to demonstrate how can we use it :

In the following code example, I will add App config that will replace the site URL I use in the framework:

        static string Url = "";

Here is the code if you need to copy it:

<?xml version="1.0" encoding="utf-8" ?>
  <appSettings> <add key="SiteUrl" value =""/></appSettings>  

Now let's add a new class, "ConfigReader," that we will use to read data from the App. Config file:

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Text;

namespace SeleniumExcel.AppConfiguration
    class ConfigurationReader
        public static string InitializeTest()
            return "";

And now we can call it from the Test class:

static string Url = ConfigurationReader.InitializeTest();

Configurations Development

We can also create a custom configuration and use it in our framework without using the built-in App.Config file. We will use a System.XML namespace and add Xpathltem and XpathDocument classes.

Step 1: Creating a Properties class

using System;
using System.Collections.Generic;
using System.Text;

namespace SeleniumExcel.AppConfiguration
    public class Settings
        public string TestType { get; set; }
        public string SiteUrl { get; set; }
        public string Build { get; set; }
        public string IsLog { get; set; }
        public string LogPath { get; set; }

Step 2: Add an XML file

and now add the following code:

<?xml version="1.0" encoding="utf-8" ?>
  <!--Available Flags Regression, Unit, integration, E2E-->
  <BuildName>SeleniumTraining </BuildName>
  <!--Available Flags Y,N-->

Step 3: Reading XML data

Create a new class "XMLReader" and add the following code:

using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.XPath;

namespace SeleniumExcel.AppConfiguration
public class XMLReader
public static void SetFrameSettings()
XPathItem siteUrl;
XPathItem testType;
XPathItem buidName;
XPathItem isLog;
XPathItem logPath;

string strFileName = Environment.CurrentDirectory.ToString() + "\\AppConfiguration\\FrameworkConfiguration.xml";

//Read File Content
FileStream stream = new FileStream(strFileName, FileMode.Open);
XPathDocument document = new XPathDocument(stream);
XPathNavigator Navigator = document.CreateNavigator();

siteUrl = Navigator.SelectSingleNode("SeleniumExcel/RunSettings/SiteUrl");
testType = Navigator.SelectSingleNode("SeleniumExcel/RunSettings/TestType");
buidName = Navigator.SelectSingleNode("SeleniumExcel/RunSettings/BuildName");
isLog = Navigator.SelectSingleNode("SeleniumExcel/RunSettings/IsLog");logPath = Navigator.SelectSingleNode("SeleniumExcel/RunSettings/LogPath");

Settings.SiteUrl = siteUrl.ToString();
Settings.TestType = testType.ToString();
Settings.BuildName = buidName.ToString();
Settings.IsLog = isLog.ToString();
Settings.LogPath = logPath.ToString();

Step 3: Using XML configuration in framework

        public void UsingConfigurationExample()
            Driver = new ChromeDriver(chromeOptions);

906 views0 comments

Recent Posts