【发布时间】:2018-10-18 14:19:11
【问题描述】:
我在测试类中有我的测试方法。我使用编码的 UI。 到目前为止我测试的一切似乎都很好。现在我想在单击 Save 按钮时等待 Ajax 调用,但我不知道如何。 有可能这样做吗?如果我的 Ajax 响应超过 500 毫秒,那么测试应该会失败。
这是我的示例类:
[TestInitialize]
public void TestInitialize()
{
string serviceName = "xxxxxxx.exe";
var binPath = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory)));
string servicePath = @"\ServiceProjects\vvvvvv\bin\Debug\";
string absolutePath = String.Format("{0}{1}{2}", binPath, servicePath, serviceName);
Process.Start(absolutePath);
BrowserWindow.CurrentBrowser = "ie";
BrowserWindow.Launch(baseAddress);
}
[TestMethod]
public void ManagerTestMethod()
{
this.UIMap.ManagerTestMethod_MobilePrefix();
}
[TestCleanup]
public void TestCleanup()
{
this.UIMap.TestCleanup();
}
在这个 ManagerTestMethod_MobilePrefix() 方法中,我点击保存按钮:
public void ManagerTestMethod_MobilePrefix()
{
#region Variable Declarations
HtmlDiv uISljedećizahtjevNoPane = this.UIAddikoAPSInternetExpWindow.UIAddikoAPSDocument.UISljedećizahtjevNoPane;
HtmlButton uIItemButton = this.UIAddikoAPSInternetExpWindow.UIAddikoAPSDocument.UIItemButton;
HtmlCustom uIItemCustom = this.UIAddikoAPSInternetExpWindow.UIAddikoAPSDocument1.UIŠifarniciCustom.UIItemCustom;
HtmlHyperlink uIMobilniprefiksHyperlink = this.UIAddikoAPSInternetExpWindow.UIAddikoAPSDocument1.UICodelistsSubMenuCustom.UIMobilniprefiksHyperlink;
HtmlDiv uIItemPane = this.UIAddikoAPSInternetExpWindow.UIAddikoAPSDocument2.UIAps_mng_mobilephonepPane.UIItemPane;
HtmlSpan uIItemPane1 = this.UIAddikoAPSInternetExpWindow.UIAddikoAPSDocument2.UIAps_mng_mobilephonepPane.UIItemPane1;
HtmlEdit uIApsmngmobilephonepreEdit = this.UIAddikoAPSInternetExpWindow.UIAddikoAPSDocument2.UIApsmngmobilephonepreEdit;
HtmlEdit uIApsmngmobilephonepreEdit1 = this.UIAddikoAPSInternetExpWindow.UIAddikoAPSDocument2.UIApsmngmobilephonepreEdit1;
HtmlEdit uIApsmngmobilephonepreEdit2 = this.UIAddikoAPSInternetExpWindow.UIAddikoAPSDocument2.UIApsmngmobilephonepreEdit2;
HtmlButton uISačuvatiButton = this.UIAddikoAPSInternetExpWindow.UIAddikoAPSDocument2.UISačuvatiButton;
#endregion
// Click '+ Sljedeći zahtjev + No' pane
Mouse.Click(uISljedećizahtjevNoPane, new Point(1651, 234));
// Click '+ Sljedeći zahtjev + No' pane
Mouse.Click(uISljedećizahtjevNoPane, new Point(1778, 308));
// Click '+' button
Mouse.Click(uIItemButton, new Point(51, 23));
// Click custom control
Mouse.Click(uIItemCustom, new Point(48, 30));
// Click 'Mobilni prefiks' link
Mouse.Click(uIMobilniprefiksHyperlink, new Point(87, 18));
// Set flag to allow play back to continue if non-essential actions fail. (For example, if a mouse hover action fails.)
Playback.PlaybackSettings.ContinueOnError = true;
// Mouse hover pane at (1, 1)
Mouse.Hover(uIItemPane, new Point(1, 1));
// Reset flag to ensure that play back stops if there is an error.
Playback.PlaybackSettings.ContinueOnError = false;
// Click pane
Mouse.Click(uIItemPane1, new Point(6, 5));
// Type 'test1' in 'aps.mng.mobilephoneprefix.details.Code' text box
uIApsmngmobilephonepreEdit.Text = this.ManagerTestMethod_MobilePrefixParams.UIApsmngmobilephonepreEditText;
// Type '{Tab}' in 'aps.mng.mobilephoneprefix.details.Code' text box
Keyboard.SendKeys(uIApsmngmobilephonepreEdit, this.ManagerTestMethod_MobilePrefixParams.UIApsmngmobilephonepreEditSendKeys, ModifierKeys.None);
// Type 'test1' in 'aps.mng.mobilephoneprefix.details.CoreCode' text box
uIApsmngmobilephonepreEdit1.Text = this.ManagerTestMethod_MobilePrefixParams.UIApsmngmobilephonepreEdit1Text;
// Type '100' in 'aps.mng.mobilephoneprefix.details.Value' text box
uIApsmngmobilephonepreEdit2.Text = this.ManagerTestMethod_MobilePrefixParams.UIApsmngmobilephonepreEdit2Text;
// Click 'Sačuvati' button
Mouse.Click(uISačuvatiButton, new Point(52, 20));
}
最后一步对我来说至关重要:Mouse.Click(uISačuvatiButton, new Point(52, 20));在该步骤中,我正在对我的 API 控制器进行 Ajax 调用以插入数据。 我希望能够从我的表单中捕获验证,还希望能够捕获通过单击保存按钮触发的 Ajax 调用的响应。
【问题讨论】:
标签: asp.net ajax model-view-controller coded-ui-tests