November 17, 2019

What is the use of TestSettings file (.runsettings) in Visual Studio

  November 17, 2019
Test setting file can be the one-stop config file control various settings during the test automation.

We can find add the test settings file by right-clicking on Project -> Add-> New Item

TestSettings_img

We can update the test settings file with run parameters to read from Project or From Azure tasks

<TestRunParameters>
    <Parameter name="isAzureHostedTest" value="True" />
    <Parameter name="isHostedSetupTest" value="True" />
    <Parameter name="Environment" value="Dev" />
    <Parameter name="Browser" value="chrome+headless" />
  </TestRunParameters>

From the project, run parameters can read using the TestContext property of MsTest.

string sUserType = TestContext.Properties["UserType"].ToString();

In order to read run settings from the project, we have to map this file with Visual Studio.
Use can use the below option to do this.

SettingsMap_img

Passing Test parameters to run settings from Azure

For this, we have to select the test settings file from the build artifact created in Azure.
And this path has to be selected in the VsTest task.

AzureSettings_img
Override test run parameter will overwrite the existing values in test settings file with the file we pass from the VsTest task The following will be the order of execution from Azure.
  1. VsTest task will get the latest test settings file from the published artifact
  2. During execution, the current test settings will be read
  3. Now if there is any override test run parameter is mentioned in the task, the existing values in the repo will be replaced with the new value
We can use $(RunParameterName) to read the value from the Variable tab in the Pipeline/Release

-Environment $(TestEnvironment) -Browser $(TestBrowser)

And the values are in the Variable tab should be declared in the below format.

AzureVariable_img
logoblog

Thanks for reading What is the use of TestSettings file (.runsettings) in Visual Studio

Previous
« 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...