Retrieve Browser Log using Selenium RC

Posted on Friday, August 26, 2011

I wasn't able to locate anything that natively allowed me to save the browser log being written to during the test.

I included the following javascript as a user extension, which hooks into Selenium's browser logging functionality:

You can then retrieve the log text as a string at the end of your test using GetEval

I go a step further and utilize TestContext.AddResultFile(String filename), included in Visual Studio 2010's testing suite, to neatly attach the browser log to the test result:

Labels: , ,


 

Selenium IE9 WaitForPageToLoad Fix

There appears to be an issue in Selenium that causes WaitForPageToLoad to act improperly in IE9.

To resolve the issue copy the following code into a file called "user-extensions.js":

Reference that file when you start the Selenium server using the "-userExtensions" option:

java -jar selenium-server-standalone-2.4.0.jar -userExtensions user-extensions.js

Now for the explanation...

I noticed that when I experienced the WaitForPageToLoad timeout, the browser logs showed an unusual error message coming from IEBrowserBot.windowclosed:

debug(1314123427103): _isSamePage: sameLoc: true
debug(1314123427103): _isSamePage: sameHref: true
debug(1314123427103): _isSamePage: markedLoc: true
debug(1314123427824): replaced getReadyState used
debug(1314123427824): pageUnloading = true!!!!
debug(1314123427824): getReadyState returning loading
debug(1314123427824): pollForLoad continue (selenium1314123422376): undefined
debug(1314123427824): runScheduledPollers DONE
debug(1314123427843): runScheduledPollers
debug(1314123427843): IEBrowserBot.pollForLoad: selenium1314123422376
debug(1314123427843): pollForLoad original (selenium1314123422376): http://localhost:8000/weblo/Gfe.aspx
debug(1314123427899): IEBrowserBot.windowClosed: couldn't read win.document, assume closed:  (this.pageUnloading=true)
debug(1314123427899): pollForLoad WINDOW CLOSED (selenium1314123422376)
debug(1314123427899): runScheduledPollers DONE
debug(1314123427900): runScheduledPollers
debug(1314123427900): runScheduledPollers DONE
debug(1314123427919): runScheduledPollers
debug(1314123427919): runScheduledPollers DONE

Looking at browser-bot.js, I noticed that the condition with the logged error "couldn't read win.document, assume closed" is the only one that returns true:

I changed that to return false and included the entire function as a user extension, thus overwriting the original:

Since then, I have run over a thousand tests (on IE9) and not one has faltered because of WaitForPageToLoad.

Labels: , , , , , ,