I ran into an interesting timing issue causing an exception. I understand what is happening now and thought I would let others know. (Maybe there is a way to trap this and make a friendlier exception?)
It basically comes down to making sure that you wait for the postback on all clicks. (Idea: Maybe there is a way to 'set' the default behavior for the framework during run time? Like a static property that could be set? InteractionMode? Asynch, WaitForPostback???)
Here are the code snippets. The first section causes the error to happen randomly, the second fixes it.
// This code is in my own adapter format, the important point
// for you is that the Click is actually an HtmlElement.Click()
// and the NavigateTo() is actually a HtmlPage.Navigate();
type2DiabetesAdapter.NavigateTo();
type2DiabetesAdapter.HomeButton.Click(); // Goes back to the home page
type2DiabetesAdapter.NavigateTo();
// Here is the fix
type2DiabetesAdapter.NavigateTo();
type2DiabetesAdapter.HomeButton.Click(WaitFor.Postback); // Goes back to the home page
type2DiabetesAdapter.NavigateTo();
Error in Test 'UITestWeb.Library.Tests.ConsumerWeb.FrameworkExamples.Example_InteractWithGlobalNav'
Exception was thrown by the client engine: "[TestExecutorException]: Unhandled JS exception while executing command handler function NavigateToUrl. (Details: {\"name\":\"TypeError\",\"message\":\"'this._currentFrame.get_jsFrame().document.body'
is null or not an object\",\"number\":-2146823281,\"description\":\"'this._currentFrame.get_jsFrame().document.body' is null or not an object\"})" when running command: Navigate - http://localhost:4080/Default.aspx?machine=NBI0EjQSNBISNBI0EjQSNA&session=5tsHyriEaU2FEv673AU7sw&contentid=1202003&text=0+items
on the target: < id=, index: 0>.
Exception Details:
Microsoft.Web.Testing.Light.WebTestException: Exception was thrown by the client engine: "[TestExecutorException]: Unhandled JS exception while executing command handler function NavigateToUrl. (Details: {\"name\":\"TypeError\",\"message\":\"'this._currentFrame.get_jsFrame().document.body'
is null or not an object\",\"number\":-2146823281,\"description\":\"'this._currentFrame.get_jsFrame().document.body' is null or not an object\"})" when running command: Navigate - http://localhost:4080/Default.aspx?machine=NBI0EjQSNBISNBI0EjQSNA&session=5tsHyriEaU2FEv673AU7sw&contentid=1202003&text=0+items
on the target: < id=, index: 0>.
Source Error:
Line 255: ToUri().ToString();
Line 256:
Line 257: Page.Navigate(manipulatedUrl, navigationVerification);
Line 258: Thread.Sleep(NavigationSleepWaitTimeMS);
Line 259: AutomationAssert.IsAdapterLoaded(this, ignoreErrors);
[Microsoft.Web.Testing.Light.WebTestException: Exception was thrown by the client engine: "[TestExecutorException]: Unhandled JS exception while executing command handler function NavigateToUrl. (Details: {\"name\":\"TypeError\",\"message\":\"'this._currentFrame.get_jsFrame().document.body' is null or not an object\",\"number\":-2146823281,\"description\":\"'this._currentFrame.get_jsFrame().document.body' is null or not an object\"})" when running command: Navigate - http://localhost:4080/Default.aspx?machine=NBI0EjQSNBISNBI0EjQSNA&session=5tsHyriEaU2FEv673AU7sw&contentid=1202003&text=0+items on the target: < id=, index: 0>.]
at Microsoft.Web.Testing.Light.HtmlPage.ExecuteCommand(BrowserCommand command)
at Microsoft.Web.Testing.Light.HtmlPage.Navigate(String absoluteUrl, NavigationVerification navigationVerificationMode, Int32 millisecondsWaitToLoad)
at Microsoft.Web.Testing.Light.HtmlPage.Navigate(String url, NavigationVerification navigationVerificationMode)
at UITestWeb.Library.Tests.ConsumerWeb.Adapters.BaseAdapters.ConsumerWebAdapter.NavigateTo(Boolean ignoreErrors, NavigationVerification navigationVerification) in C:\Dev\Healthnotes\Core\Current\UnitTests\Web\UITestWeb\Library\Tests\ConsumerWeb\Adapters\BaseAdapters\ConsumerWebAdapter.cs:line 257
at UITestWeb.Library.Framework.EndpointAdapter.NavigateTo(Boolean ignoreErrors) in C:\Dev\Healthnotes\Core\Current\UnitTests\Web\UITestWeb\Library\Framework\EndpointAdapter.cs:line 179
at UITestWeb.Library.Framework.EndpointAdapter.NavigateTo() in C:\Dev\Healthnotes\Core\Current\UnitTests\Web\UITestWeb\Library\Framework\EndpointAdapter.cs:line 166
at UITestWeb.Library.Tests.ConsumerWeb.FrameworkExamples.Example_InteractWithGlobalNav() in C:\Dev\Healthnotes\Core\Current\UnitTests\Web\UITestWeb\Library\Tests\ConsumerWeb\FrameworkExamples.cs:line 273
Version Information: Microsoft .NET Framework Version: 2.0.50727.3082; ASP.NET Version: 2.0.50727.3082; ASP.NET AJAX Version: 3.5.30729.196; Microsoft.Web.Testing Version: 1.0.0.0</div>
Michael Cowan
Aisle7
QA Manager (QA Lead)
michael.cowan@healthnotes.com
Both good suggestions. I think we can definelty do something about the exception message to make it clearer.
I'll think about your second issue, basically you want a way to specify what is the default WaitFor enum for the simple Click() overload right? My concern is readibility of tests, you can imagine that now you can set the default somewhere else in your testbed,
and when I read a test that says "Click()" I won't necesarily know that is waiting for postback or just "fire and forget".
I'll open a bug and discuss it over with the rest of the team.
I see what you are saying about readability. Its something I have struggled with as well.
Really you currently support two 'modes' of automation:
<div mce_keep="true">Primarilty Ajax sites with a few Postback requests.</div>
<div mce_keep="true">Primarily Postback sites with a few Ajax requests.</div>
Putting more thought into this, I am thinking that its bigger than just Click(). Right now all the operations have a single default mode. Click(), NavigateTo(), Waits...(). Maybe an option is to be able to set a default WebSite Mode. It would not be a
per-operation setting, it would be something that was set maybe in a config file? Or a setting on the driver page?
Where it is set needs some more thought, but I kindof like elegance of being able to remove the need to specify the NavigationValidation.Ajax on every Navigate() method or WaitFor.Postback on every Click().
Either way, its not a big deal and if I wake up one night and can't stand it I can always wrap the HtmlElement
Michael Cowan
Aisle7
QA Manager (QA Lead)
michael.cowan@healthnotes.com
mcowan
Member
8 Points
42 Posts
Unhandled JS Exception when trying to navigate while a page is in the middle of a postback
Apr 05, 2009 08:17 PM|LINK
I ran into an interesting timing issue causing an exception. I understand what is happening now and thought I would let others know. (Maybe there is a way to trap this and make a friendlier exception?)
It basically comes down to making sure that you wait for the postback on all clicks. (Idea: Maybe there is a way to 'set' the default behavior for the framework during run time? Like a static property that could be set? InteractionMode? Asynch, WaitForPostback???)
Here are the code snippets. The first section causes the error to happen randomly, the second fixes it.
Here is the full stack trace:
Test Stack Trace:
<div style="FONT-SIZE: 8.5pt; WIDTH: 100%; COLOR: black; FONT-FAMILY: 'Verdana'; BACKGROUND-COLOR: white">Error in Test 'UITestWeb.Library.Tests.ConsumerWeb.FrameworkExamples.Example_InteractWithGlobalNav'
Exception was thrown by the client engine: "[TestExecutorException]: Unhandled JS exception while executing command handler function NavigateToUrl. (Details: {\"name\":\"TypeError\",\"message\":\"'this._currentFrame.get_jsFrame().document.body' is null or not an object\",\"number\":-2146823281,\"description\":\"'this._currentFrame.get_jsFrame().document.body' is null or not an object\"})" when running command: Navigate - http://localhost:4080/Default.aspx?machine=NBI0EjQSNBISNBI0EjQSNA&session=5tsHyriEaU2FEv673AU7sw&contentid=1202003&text=0+items on the target: < id=, index: 0>.
Exception Details: Microsoft.Web.Testing.Light.WebTestException: Exception was thrown by the client engine: "[TestExecutorException]: Unhandled JS exception while executing command handler function NavigateToUrl. (Details: {\"name\":\"TypeError\",\"message\":\"'this._currentFrame.get_jsFrame().document.body' is null or not an object\",\"number\":-2146823281,\"description\":\"'this._currentFrame.get_jsFrame().document.body' is null or not an object\"})" when running command: Navigate - http://localhost:4080/Default.aspx?machine=NBI0EjQSNBISNBI0EjQSNA&session=5tsHyriEaU2FEv673AU7sw&contentid=1202003&text=0+items on the target: < id=, index: 0>.Source Error:
Source File: C:\Dev\Healthnotes\Core\Current\UnitTests\Web\UITestWeb\Library\Tests\ConsumerWeb\Adapters\BaseAdapters\ConsumerWebAdapter.cs Line: 257 Method: UITestWeb.Library.Tests.ConsumerWeb.Adapters.BaseAdapters.ConsumerWebAdapter.NavigateTo(Boolean ignoreErrors, NavigationVerification navigationVerification)
Stack Trace:
Version Information: Microsoft .NET Framework Version: 2.0.50727.3082; ASP.NET Version: 2.0.50727.3082; ASP.NET AJAX Version: 3.5.30729.196; Microsoft.Web.Testing Version: 1.0.0.0</div>
Aisle7
QA Manager (QA Lead)
michael.cowan@healthnotes.com
farmas
Participant
1164 Points
259 Posts
Microsoft
Re: Unhandled JS Exception when trying to navigate while a page is in the middle of a postback
Apr 05, 2009 11:55 PM|LINK
Both good suggestions. I think we can definelty do something about the exception message to make it clearer.
I'll think about your second issue, basically you want a way to specify what is the default WaitFor enum for the simple Click() overload right? My concern is readibility of tests, you can imagine that now you can set the default somewhere else in your testbed, and when I read a test that says "Click()" I won't necesarily know that is waiting for postback or just "fire and forget".
I'll open a bug and discuss it over with the rest of the team.
- Federico
mcowan
Member
8 Points
42 Posts
Re: Unhandled JS Exception when trying to navigate while a page is in the middle of a postback
Apr 06, 2009 03:54 AM|LINK
I see what you are saying about readability. Its something I have struggled with as well.
Really you currently support two 'modes' of automation:
Putting more thought into this, I am thinking that its bigger than just Click(). Right now all the operations have a single default mode. Click(), NavigateTo(), Waits...(). Maybe an option is to be able to set a default WebSite Mode. It would not be a per-operation setting, it would be something that was set maybe in a config file? Or a setting on the driver page?
Where it is set needs some more thought, but I kindof like elegance of being able to remove the need to specify the NavigationValidation.Ajax on every Navigate() method or WaitFor.Postback on every Click().
Either way, its not a big deal and if I wake up one night and can't stand it I can always wrap the HtmlElement
Aisle7
QA Manager (QA Lead)
michael.cowan@healthnotes.com