1

In the final release 2.0 of WatiN the new feature for Internet Explorer was announced:

"WatiN will now wait for IE and the DOM Document to get to the ‘interactive’ or ‘ready’ state to avoid unnecessary time-outs"

In fact, in my project we need to use old functionality for existed tests, when WatiN waits only 'ready' state(as I understand it is fully loading of the web page). For now, the many tests are failed.

The main problem is that WatiN try to find and to manipulate elements that aren't loaded yet after some action(for example, click on the button)

Is it possible to switch new version of WatiN to old work principle?

Dmitry
  • 59
  • 6
  • Hi Dmitry, could you add some code examples that fail due to this change? I'll could make this wait behavior configurable in a next release, but I also like to better understand the issue you are experiencing. Regards Jeroen, lead dev WatiN – Jeroen van Menen Mar 17 '11 at 15:54
  • Hi Jeroen, Unfortunately I cannot provide you code sample. We've used now WatiN RC with version 2.0.20.0, that doesn't contain this problem. Our issue occurs when page is reloading or browser goes to page. Pages in our application are big and contain much marking. So, we'll be glad, if you'll make option that switches between new and old functionality of WatiN. Best regards, Dmitry – Dmitry Mar 24 '11 at 14:57

2 Answers2

1

Try this extension method

public static void WaitForReady(this Browser browser)
{
    int timeWaitedInMilliseconds = 0;
    var maxWaitTimeInMilliseconds = Settings.WaitForCompleteTimeOut * 1000;

    while (browser.Eval("document.readyState") != "complete" && timeWaitedInMilliseconds < maxWaitTimeInMilliseconds)
    {
        Thread.Sleep(Settings.SleepTime);
        timeWaitedInMilliseconds += Settings.SleepTime;
    }
}
Neil Mosafi
  • 460
  • 1
  • 4
  • 14
0

I believe I'm having the same issue. The speed improvements in the new Watin, though, are fantastic!

Loading a page and executing something like

foreach(TextField t in browser.TextFields) {
t.setAttribute("value","test");
}

Gives me a system unauthorized exception with the new Watin about 1/10 times. When this happens browser.text returns ""

so I'm thinking of playing with something like

while(browser.text=="") {
System.Thread.Thread.Sleep(500);
}

(with a break in case the page actually has no text).

dandan78
  • 13,328
  • 13
  • 64
  • 78
chris
  • 1