Thursday, 7 April 2016

Using a App.config file to have different Sections in CodedUI project

To make coded UI tests to work in different environments, or to have different configuration values for different test methods to override the source of data file, a config file can be setup rather than a data source. 

Things to be done to achieve this
  1. You’ll need to add a reference to the System.Configuration assembly for the solution
  2. Then add the custom elements to app.config file (which is added to test project) TestSiteConfigurationData section name in the app.config file
  3. Create configuration data class for a custom section in App.Config TestSiteConfigurationData.cs
  4. Create the Helper class file for reading the data from configuration data class TestSiteConfigurationHelper.cs
  5. Call the helper class in the Codedui Project and read the values from config file under your custom section

You might face an issue with some wrong value entered for the type of section in the app.config file

 <configSections>
    <section name="TestSiteConfigurationData"
             type="Configuring_Sections.TestSiteConfigurationData,Configuring Sections"/>
  </configSections>
   
Configuring_Sections.TestSiteConfigurationData - <ProjectNamespace>.<ConfigurationDataClassName>

Configuring Sections - the solution dll name i.e your CodedUI project name

Find the sample project implementing the above attached


Happy coding :)