Reputation: 13
It appears that the WebBrowser_DocumentCompleted()
event is not very adequate sometimes, and for me this has been the case. I am creating several reports web pages for automation checks (currently 5), and this event runs very soon, once, for each of these pages. If the page isn't finished, I am wondering what the best approach is to get DocumentCompleted()
to continue to run.
I've tried checking the ReadyState and URL to see if they match in my automationExec()
function, and this has been worthless, ReadyState is Complete and the URLs match. That hasn't been a problem, though, I can just check the existence of the footer tag on the page, so ReadyState
and the WebBrowserDocumentCompletedEventArgs.Url
do not need to be covered.
private void openReport(UnitTestType unitTest)
{
BrowserPopup testBrowser = new BrowserPopup();
WebBrowser reportBrowser = new WebBrowser();
...
reportBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(automationExec);
testBrowser.CreateWindow(reportBrowser, "QA Automation", unitTest.hash); //creates browser window
}
private void automationExec(object sender, WebBrowserDocumentCompletedEventArgs e)
{
WebBrowser reportBrowser = (WebBrowser)sender;
//footer, version tag
if (reportBrowser.Document.Body.FirstChild.NextSibling.NextSibling.FirstChild.FirstChild.FirstChild.NextSibling == null)
{
reportBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(automationExec);
//i'm not sure how to re-raise DocumentCompleted event now that it has occured
return;
}
//report is complete, perform automation tests
}
Upvotes: 1
Views: 1134
Reputation: 100545
You can't "replay" document complete event. Feels like your page is actually using some JavaScript to do rendering and is not really "complete" from your point of view when browser is done loading HTML/scripts/images. This is quite common for modern pages.
Periodically checking for something you expect to be on the page (i.e. similar to check you already have) may be the easiest option in this case.
Upvotes: 1