Reputation: 1002
I have a CodedUiTest which has several test methods. I want to be able to pass a different path to the test each time I execute it from the command line via MSTest. How can I achieve this?
This is how I execute the test now:
{
System.Diagnostics.Process codedUIProcess = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo codedUIStartInfo = new System.Diagnostics.ProcessStartInfo();
codedUIStartInfo.FileName = @"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe";
codedUIStartInfo.Arguments = @"/testcontainer:C:\DailyBuildAutoTest.dll /test:MyUITestAssembly\MyCodedUITest";
codedUIStartInfo.CreateNoWindow = true;
codedUIProcess.StartInfo = codedUIStartInfo;
codedUIProcess.Start();
}
Is there any way to pass parameters like a string to "MyCodedUITest"?
Upvotes: 5
Views: 6381
Reputation: 542
Yes. Right now there is no option in MSTest to pass parameter but there is work around which I have implemented in my project. Any parameter you need to pass that can be save in text file (or you can save in DB) and get the parameter value from text file when you execute the test case.
Upvotes: 0
Reputation: 1507
If you want to change the path of test container or mstest.exe you can use a bat file with the paths are arguments to the file and execute the bat file from a process.
string _myBatchFile = "batFileFullPath;
string _testContainer = "DllfileFullpath";
string _testMethodName = "testMethodName";
string _result = "resulFileName.trx";
Process _process = new Process();
_process.StartInfo.Arguments = string.Format("{0} {1} {2}", "\"" + _testContainer + "\"", _result, "\"" + _testMethodName + "\"");
_process.StartInfo.FileName = _myBatchFile;
_process.Start();
_process.WaitForExit();
Use quotation mark character before and after paths if they contains spaces between them. Otherwise it will be a problem to send them as argument to bat file.
Create a bat file like below to call it by the Process.
@ECHO on
"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\mstest.exe" /testcontainer:%1 /test:%3 /resultsfile:%2
Upvotes: 1
Reputation: 14076
Can you set an environment variable before invoking mstest
and then use its value to generate the path string?
Upvotes: 1
Reputation: 9793
No, unfortunately there is no way to do that. Check the MSTest Command-Line Options
The only possible way I can think is to associate the CodedUi Tests
with the Test Cases
and run them from Microsoft Test Manager.
Then you can easily parameterize the tests by adding parameters to test cases. These parameters are the DataSource
of the associated test and you can read them from your CodedUi Test.
Upvotes: 1