Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TestContext TestRunParameters in Coded UI Test

Following the procedures outlines here and here I was able to set a TestRunParameter and access it at run time in a Unit test. I then repeated the exact same process in a coded UI test but am not able to access the Properties.

My .runsettings file:

<RunSettings>
  <TestRunParameters>
    <Parameter name="webAppUrl" value="http://localhost" />
  </TestRunParameters>
</RunSettings>

My Test Method:

[TestMethod]
public void MyTest1()
{
    // This throws an error because Properties["webAppUrl"] is null
    string webAppUrl = TestContext.Properties["webAppUrl"].ToString();

    // etc...
}

Does a Coded UI test need additional configuration to access these run time properties?

Edit: I notice that within the context of a Unit test, the TestContext is Microsoft.VisualStudio.TestPlatform.MSTestFramework.TestContextImplementation. In the Coded UI test, the TestContext is Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapterContext.

like image 425
Jonathan Eckman Avatar asked Sep 26 '22 17:09

Jonathan Eckman


1 Answers

The parameters defined in .runsettings TestRunParameter section can't be accessed in Coded UI test. When you debug the Coded UI test, you will find that TextContext.Properties contains some values, ResultsDirectory, AgentId and etc.

However, parameter defined in the TestRunParameter section can't be found.

enter image description here

Instead of setting parameters in TestRunParameter section, you can create a .cvs or .xml file, and access the data via data-driven. Check this article for the details:

https://msdn.microsoft.com/en-us/library/ee624082.aspx

like image 136
Vicky - MSFT Avatar answered Sep 30 '22 02:09

Vicky - MSFT