如何使waitForWebPageToLoad在编码的ui测试中工作? [英] How to make waitForWebPageToLoad to work in coded ui test?

查看:70
本文介绍了如何使waitForWebPageToLoad在编码的ui测试中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我是编码ui测试的初学者,我的代码技能很差,但是我想学习。

First of all, i'm a beginner at coded ui testing and i have poor code skills but im trying to learn.

现在我正在手工编码Visual Studio中的一些测试用例(c#)(记录选项对我来说还不够),但是我无法使 waitForWebPageToLoad 正常工作。

Right now i'm hand coding some test cases (c#) in visual studio (the record option is not enough for me) but i can't get the waitForWebPageToLoad to work.

例如,在下面的示例中,我单击一个链接,输入一些文本,然后单击一个按钮。之后,我希望代码在继续之前等待网页加载。我现在所做的是一个 Thread.Sleep ,但这不是一个好的解决方案...

So for example below, i click a link, enter some text and click a button. After that i would like the code to wait for the webpage to load before proceeding. What i have done now is a Thread.Sleep but that's not a good solution...

ClickLink(Repo.Link(Browser));
EnterText(Repo.Field(Browser), "12345789");
ClickButton(Repo.LeftButton(Browser));
Thread.Sleep(5000);  //<-------- This must be replaced... :)

如何使 waitForWebPageToLoad 函数起作用?
我有这种方法,但是我不明白如何使它们起作用,有人想帮我理解吗?

How do i get the waitForWebPageToLoad function to work? I have this methods but i can't understand how to make them work, anyone wanna help me understand?

void ClickButton(HtmlInputButton obj) {
    waitForWebPageToLoad(obj, 10);
    TestContext.WriteLine("Clicking button: " + obj.Name);
    Mouse.Click(obj);
}



并且:



And:

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 有点方法是在控件类型上调用的。并且控件存在是正确的,但这并不意味着控件已准备就绪(可能正在加载)

The waitforcontrol kinda methods are called on a control type. And control exist would be true, but it doesn't mean that the control is ready (It probably be loading)

一般做法是在超级控件上调用waitforcontrolready方法父母(说浏览器)。我已按照以下方法修改了您的方法,

The general practice is call the waitforcontrolready method on the super parent. (Say Browser). I've modified your method as below,

 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;
    }

然后只要在页面加载的任何地方调用方法来等待,切记以秒为单位传递浏览器和超时。

then just call the method to wait, where ever you do a page load. Remember to pass browser and timeout in seconds as a parameter. Something like,

    ClickButton(Repo.LeftButton(Browser));
    WaitForPageLoad(Browser, 120);

希望有帮助!

这篇关于如何使waitForWebPageToLoad在编码的ui测试中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆