阅读 https://msdn.microsoft.com/en-us/library/jj635153.aspx 后我创建了一个类似于示例的.RunSettings
文件,其中包含了一些参数。
<TestRunParameters>
<Parameter name="webAppUrl" value="http://localhost" />
<Parameter name="webAppUserName" value="Admin" />
<Parameter name="webAppPassword" value="Password" />
</TestRunParameters>
我计划为我们每个环境设置一个.RunSettings
文件,其中包含适当的URL和凭据,以在指定的RunSettings文件的环境中运行CodedUI测试。
我可以看到从命令行引用设置文件的方法是运行:
vstest.console myTestDll.dll /Settings:Local.RunSettings /Logger:trx
vstest.console myTestDll.dll /Settings:QA.RunSettings /Logger:trx
但是我没有找到任何调用实际如何利用代码UI测试中的TestRunParameters
的方法。
我想要做的是设置测试初始化器,使用TestRunParameters
来确定在哪里登录以及使用什么凭据。就像这样:
[TestInitialize()]
public void MyTestInitialize()
{
// I'm unsure how to grab the RunSettings.TestRunParameters below
string entryUrl = ""; // TestRunParameters.webAppUrl
string userName = ""; // TestRunParameters.webAppUserName
string password = ""; // TestRunParameters.webAppPassword
LoginToPage(entryUrl, userName, password);
}
public void LoginToPage(string entryUrl, string userName, string password)
{
// Implementation
}
非常感谢有关如何引用 TestRunParameters
的信息!
编辑
/// <summary>
/// Summary description for CodedUITest1
/// </summary>
[CodedUITest]
public class CodedUITest1
{
public static string UserName = string.Empty;
[ClassInitialize]
public static void TestClassInitialize(TestContext context)
{
UserName = context.Properties["webAppUserName"].ToString();
Console.WriteLine(UserName);
}
[TestMethod]
public void CodedUITestMethod1()
{
this.UIMap.RecordedMethod1();
// To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
}
// Rest of the default class - TestContext instantiation, UI map instantiation, etc
}
运行时遇到的异常:
NullReference Exception
@williamfalconeruk 我已经按照上述内容更新了我的测试类,但仍然遇到相同的错误,请问我做错了什么?