How to make waitForWebPageToLoad to work in coded ui test?

前提是你 提交于 2019-12-23 20:22:27

问题


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

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.

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... :)

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

回答1:


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)

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

Hope that helps!



来源:https://stackoverflow.com/questions/41815336/how-to-make-waitforwebpagetoload-to-work-in-coded-ui-test

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!