I have a requirement to run Coded UI test that is data driven from console application. If I run the Coded UI test as a standalone, then [DataSource] can access the values from the CSV file. Whereas if I call Coded UI from the console app, I get the unhandled exception: System.NullReferenceException: Object reference not set to an instance of an object. - since TestContext.DataRow is null.
Here’s snippet from the code
Program.cs (console app):
public class Program
{
static void Main(string[] args)
{
Playback.Initialize();
CodedUITestWarmup test = new CodedUITestWarmup();
test.WarmUp();
Playback.Cleanup();
}
}
CodedUITestWarmup.cs (coded ui test):
public class CodedUITestWarmup
{
[TestMethod]
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", @"|DataDirectory|\DataFiles\warmup.csv", "warmup#csv", DataAccessMethod.Sequential)]
public void WarmUp()
{
InitializeVendorTest();
...
}
private void InitializeVendorTest()
{
caseV = new CaseVariables(TestContext);
...
}
}
class CaseVariables
{
public string lastNameID;
...
public CaseVariables(TestContext TestContext)
{
lastNameID = TestContext.DataRow["lastNameID"].ToString();
...
}
}
Could you please provide some inputs what can be done in this regard?
TestContext.DeploymentDirectorydirectory as wanted by the|DataDirectory|part of theDataSourceattribute. You should examine the contents ofTestContext.DeploymentDirectoryin both the successful and the unsuccessful runs. - AdrianHHH