我为我的 Web 应用程序创建了以下 Web 编码 UI 测试。
执行时,测试用例成功运行。
当测试用例作为“负载测试”的一部分添加时,它开始抛出错误消息。
Test Error TestError 4 Test method testWithSQLExp.CodedUITest2.CodedUITestMethod1 threw exception:
System.NullReferenceException: Object reference not set to an instance of an object.
顺便说一句,当用户计数设置为 1 时,具有相同 codedUI 测试的相同负载测试工作良好。
我的代码如下 UIMap.cs
public void AssertMethod1()
{
#region Variable Declarations
HtmlCell uIItem1363758Cell = this.UIFirstNetHomePageWindWindow.UIEConnectFirstMeritBaDocument1.UIMainContent_gvAccounTable.UIItem1363758Cell;
#endregion
// Verify that the 'InnerText' property of '$13,637.58' cell equals '$13,637.58'
Assert.AreEqual(this.AssertMethod1ExpectedValues.UIItem1363758CellInnerText, uIItem1363758Cell.InnerText);
}
public void RecordedMethod1()
{
#region Variable Declarations
HtmlEdit uICompanyEdit = this.UIFirstNetHomePageWindWindow.UIBusinessDocument.UICompanyEdit;
HtmlEdit uIUsernameEdit = this.UIFirstNetHomePageWindWindow.UIBusinessDocument.UIUsernameEdit;
HtmlEdit uITxtPasswordEdit = this.UIFirstNetHomePageWindWindow.UIEConnectFirstMeritBaDocument.UITxtPasswordEdit;
#endregion
// Go to web page 'https://dev.firstmerit.com/business/index.html' using new browser instance
this.UIFirstNetHomePageWindWindow.LaunchUrl(new System.Uri(this.RecordedMethod1Params.UIFirstNetHomePageWindWindowUrl));
// Type 'demo' in 'Company' text box
uICompanyEdit.Text = this.RecordedMethod1Params.UICompanyEditText;
// Type '{Tab}' in 'Company' text box
Keyboard.SendKeys(uICompanyEdit, this.RecordedMethod1Params.UICompanyEditSendKeys, ModifierKeys.None);
// Type 'user' in 'Username' text box
uIUsernameEdit.Text = this.RecordedMethod1Params.UIUsernameEditText;
// Type '{Enter}' in 'Username' text box
Keyboard.SendKeys(uIUsernameEdit, this.RecordedMethod1Params.UIUsernameEditSendKeys, ModifierKeys.None);
// Type '********' in 'txtPassword' text box
uITxtPasswordEdit.Password = this.RecordedMethod1Params.UITxtPasswordEditPassword;
// Type '{Enter}' in 'txtPassword' text box
Keyboard.SendKeys(uITxtPasswordEdit, this.RecordedMethod1Params.UITxtPasswordEditSendKeys, ModifierKeys.None);
}
CodedUITest2.cs
命名空间 testWithSQLExp {
[CodedUITest]
public class CodedUITest2
{
public CodedUITest2()
{
}
[TestMethod]
public void CodedUITestMethod1()
{
// To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
// For more information on generated code, see http://go.microsoft.com/fwlink/?LinkId=179463
this.UIMap.RecordedMethod1();
this.UIMap.AssertMethod1();
}
public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}
private TestContext testContextInstance;
public UIMap UIMap
{
get
{
if ((this.map == null))
{
this.map = new UIMap();
}
return this.map;
}
}
private UIMap map;
}
}