首先,我是编码 ui 测试的初学者,我的代码技能很差,但我正在努力学习。
现在我正在 visual studio 中手动编写一些测试用例 (c#)(记录选项对我来说不够),但我无法让 waitForWebPageToLoad
工作。
例如,我单击一个链接,输入一些文本并单击一个按钮。之后我希望代码在继续之前等待网页加载。我现在所做的是 Thread.Sleep
但这不是一个好的解决方案...
ClickLink(Repo.Link(Browser));
EnterText(Repo.Field(Browser), "12345789");
ClickButton(Repo.LeftButton(Browser));
Thread.Sleep(5000); //<-------- This must be replaced... :)
如何让 waitForWebPageToLoad
函数工作?
我有这些方法,但我不明白如何使它们起作用,有人想帮助我理解吗?
void ClickButton(HtmlInputButton obj) {
waitForWebPageToLoad(obj, 10);
TestContext.WriteLine("Clicking button: " + obj.Name);
Mouse.Click(obj);
}
和:
void waitForWebPageToLoad(UITestControl parent, int waitTime) {
waitTime = int.Parse(waitTime.ToString() + "000"); //waitTimeExtension.ToString());
Playback.PlaybackSettings.SearchTimeout = waitTime;
parent.WaitForControlExist(waitTime);
parent.WaitForControlReady(waitTime);
}
最佳答案
waitforcontrol
类方法在控件类型上被调用。 control exist 会是真的,但这并不意味着控件已经准备好了(它可能正在加载)
一般的做法是调用super parent的waitforcontrolready方法。 (说浏览器)。我已将您的方法修改如下,
public void WaitForPageToLoad(BrowserWindow browser, int WaitTimeOut)
{
// Waiting on all threads enable to wait for any background process to complete
Playback.PlaybackSettings.WaitForReadyLevel = WaitForReadyLevel.AllThreads;
// Wait
browser.WaitForControlReady(WaitTimeOut * 1000);
// Revert the playback settings (As waiting on all threads may sometime have a toll on execution speed
Playback.PlaybackSettings.WaitForReadyLevel = WaitForReadyLevel.UIThreadOnly;
}
然后只需调用方法等待,无论您在哪里加载页面。请记住以秒为单位传递浏览器和超时作为参数。类似的东西,
ClickButton(Repo.LeftButton(Browser));
WaitForPageLoad(Browser, 120);
希望对您有所帮助!
关于c# - 如何使 waitForWebPageToLoad 在编码的 ui 测试中工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41815336/