November 30, 2019

How to read run parameters from test settings and then map it with Azure library

  November 30, 2019
There comes scenario in any automation testing framework where we need to keep all the global test control variables in one place.
Some controls like Continue on error, create report or not, Global URL, Type of user,Use default credentials etc can be maintained like this.

Major advantages of keeping global control variables likes these are:

  • One point change for the whole framework
  • Even non technical people can also do the changes if it is a minor one
  • Can use the control file from any other tools
  • Easy to track
One important point is, we have keep this control file in mind while creating and framework or during writing tests.

These kind of global control files can be of any type and it better to use a key-value model file.
Some examples are:
  • XML files
  • Properties files
  • Text files written in Key-Value manner
  • Json files
If you are using visual studio, we have an inbuilt file to so these actions called .runsettings. This is basically a XML file which we can read and write using TestContext variable from tests.

In testsettings file we can keep the global control variable as run parameters.
An example is shown below .

    <Parameter name="isAzureHostedTest" value="True" />
    <Parameter name="isHostedSetupTest" value="True" />
    <Parameter name="Environment" value="Prod" />
    <Parameter name="Browser" value="chrome" />
    <Parameter name="GlobalURL" value="localhost:4444" />
<Parameter name="AdminUserName" value="Admin123" />
    <Parameter name="AdminPassword" value="Admin321" />
<Parameter name="UserType" value="Admin" />

Reading run parameter from test using MsTest testcontext

public TestContext TestContext { get; set; }
string BrowserType = testContextInstance.Properties["Browser"].ToString()

Writing to run parameter from test using MsTest testcontext

public TestContext TestContext { get; set; }
string BrowserType = testContextInstance.Properties["TempURL"]="localhost:5678";

We can write values in to run parameters and use it as a temporary global control variable for test instead of using any public static variable inside tests.

If we are using Azure to control tests, we can even use these as part of CI-CD pipelines.
We can see a similar variable section in Azure.

And we can map the library created here inside the release as below.


Thanks for reading How to read run parameters from test settings and then map it with Azure library

« Prev Post

No comments:

Post a Comment

Bookmark this website for more workarounds and issue fixes.

Verify Zip file contents without extracting using C# + Selenium

While doing automation testing, we may get a scenario where we need to download a zip file and to validate the contents inside it. One way t...