views:

460

answers:

3

I am Using WaitforComplete() in watiN but it doesnt seems to work well. As it executes the next statement even if you have given longer time to wait. I am using thread.sleep() to stop my application until it gets the desired page or element. But the thing is pages are so much dynamic that sometimes it takes much longer time as specified.

Any better solution. Any thing that will catch the page return dynamically and dont go to execute next statments in application.

Sample of Code

    'Show Details page
    Assert.AreEqual("Confirmation", _internetExplorer.Title)

    If (_internetExplorer.Button(Find.ById(New Regex("btnFinish"))).Exists) Then
        _internetExplorer.Button(Find.ById(New Regex("btnFinish"))).Click()
    Else
        Assert.Fail("Could not Find Finish Booking Button on Confirmation Page")
    End If

    System.Threading.Thread.Sleep(100000)

'Show Booking Summary page Assert.AreEqual("Display Booking", _internetExplorer.Title)

I want something that detect the return of page dynamically. instead of giving some constant value.

A: 

If it is executing the next statement, it should be finding the corresponding element. I suggest posting a sample of the code you are trying.

eglasius
+1  A: 

Hi Sam,

WaitForComplete only works well if there is a postback after some action. Otherwise you have to find something else to wait for. Following an example on how to wait for the specified title:

_internetExplorer.Element("title", "Confirmation").WaitUntilExists();

I would always prefer to use one of the WaitXXX methods instead of Thread.Sleep cause the WaitXXX methods do only wait until the contraint is met. Where as Sleep waits for the time you specified. If its to long, time is waisted. If its to short, problems arise.

HTH, Jeroen

Jeroen van Menen
A: 

The WaitForComplete method esentially moves on once the browser has set it's readystate to comllete and the busy state to false.

What I typically do is to try and access what you need to, then perform a thread.sleep for say half a second, then try again. I also have a global timeout that quits after say 10 seconds.

    int timeout = 20;
    bool controlFound = false;
    for (int i = 0; i < timeout; i++)
    {
        if (_internetExplorer.Button(Find.ById(New Regex("btnFinish"))).Exists)
        {
            _internetExplorer.Button(Find.ById(New Regex("btnFinish"))).Click();
            controlFound = true;
            break;
        }
        else
        {
            System.Threading.Thread.Sleep(500);
        }   
    }


   if (!controlFound)
   {
        Assert.Fail("Control not found");
   }
Bruce McLeod