This is a migrated thread and some comments may be shown as answers.

Error on wait on Ajax

2 Answers 65 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Bartosz
Top achievements
Rank 1
Bartosz asked on 09 May 2012, 08:14 AM
Hello,

From time to time I get strange tests failture reports on wait for ajax.
I'm using a code from this forum:
[CodedStep("Wait for AJAX")]
        public void AjaxWait()
        {
            Wait.For<int>(c => ActiveAjaxConnections() == 0, 0, 120000);
        }
  
        public int ActiveAjaxConnections()
        {
            return Actions.InvokeScript<int>("jQuery.active");
        }

It works great but from time to time exception is thrown and I get false alerts on application status:
Here is stack trace for the exception:
System.ApplicationException: Exception thrown during the wait for a condition. Error: Unexpected error while waiting on condition. Error: ArtOfTest.WebAii.Exceptions.ExecuteCommandException: ExecuteCommand failed!
InError set by the client. Client Error:
System.InvalidOperationException: Javascript call [JSON.stringify(eval(\"jQuery.active\"));] failed! Please make the function exists and the call is using the correct prototype signature. Javascript error: TypeError: 'jQuery' is undefined
   at ArtOfTest.InternetExplorer.IECommandProcessor.InvokeFunction(String functionCall, Boolean useEval, Boolean returnJSON)
   at ArtOfTest.InternetExplorer.IECommandProcessor.ProcessActionCommands(BrowserCommand request)
   at ArtOfTest.InternetExplorer.IECommandProcessor.ProcessCommand(WebBrowserClass ieInstance, BrowserCommand request, IHTMLDocument2 document) BrowserCommand (Type:'Action',Info:'NotSet',Action:'InvokeJsFunctionReturnJSON',Target:'ElementId (tagName: '',occurrenceIndex: '-1')',Data:'jQuery.active',ClientId:'Client_e44e8a42-9bf5-4df0-940f-bae9ef9c4df0',HasFrames:'False',FramesInfo:'',TargetFrameIndex:'-1',InError:'True',Response:'System.InvalidOperationException: Javascript call [JSON.stringify(eval(\"jQuery.active\"));] failed! Please make the function exists and the call is using the correct prototype signature. Javascript error: TypeError: 'jQuery' is undefined
   at ArtOfTest.InternetExplorer.IECommandProcessor.InvokeFunction(String functionCall, Boolean useEval, Boolean returnJSON)
   at ArtOfTest.InternetExplorer.IECommandProcessor.ProcessActionCommands(BrowserCommand request)
   at ArtOfTest.InternetExplorer.IECommandProcessor.ProcessCommand(WebBrowserClass ieInstance, BrowserCommand request, IHTMLDocument2 document)')
InnerException: none.
 
   at ArtOfTest.WebAii.Core.Browser.ExecuteCommandInternal(BrowserCommand request)
   at ArtOfTest.WebAii.Core.Browser.ExecuteCommand(BrowserCommand request, Boolean performDomRefresh, Boolean waitUntilReady)
   at ArtOfTest.WebAii.Core.Browser.ExecuteCommand(BrowserCommand request)
   at ArtOfTest.WebAii.Core.Actions.InvokeScript[T](String script)
   at ArtOfTest.WebAii.BrowserSpecialized.InternetExplorer.InternetExplorerActions.InvokeScript[T](String script)

Any idea how to prevent it?

I could use try / catch block but I don't like this solution because I would'n get info when something really wrong happens to my application.

I'm using Telerik Test Studio version 2011.2.928.0

Bartosz

2 Answers, 1 is accepted

Sort by
0
Stoich
Telerik team
answered on 10 May 2012, 12:59 PM
Hi Bartosz,
the only way we were able to reproduce this error is by invoking this:
Actions.InvokeScript<int>("jQuery.active");
on pages that do not contain jQuery at all.

Perhaps this is what's happening on your end as well? There's no way that this piece of code would work on a page that is not rigged to use jQuery. So you can avoid the problem by handling the exception:
int CheckjQuery()
       {
           int res = -1;
            
           try
           {
               res = Actions.InvokeScript<int>("jQuery.active");
           }
           catch
           {
               Log.WriteLine("No jQuery to invoke!");
           }
            
           return res;
       }

Alternatively, this might be a timing issue where the browser still doesn't think that the Javascript in the page is ready to go. But if this is the case, we would have to spend additional time on this in order to confirm/disconfirm this.

Regards,
Stoich
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Bartosz
Top achievements
Rank 1
answered on 10 May 2012, 01:36 PM
Hi,

Thank you for answer.
I also think that it may be some timing issue (or server error), jQuery lib is present on the page and for most of the time tests are working fine.
This exception is appearing statistically on 1 of the 30 test executions.

I think that may be some web server problem  so I'll check it and let you know.

For now I think you could leave it as it is and wait for me to check this.

!!UPDATE!! <Solved>
I've checked and the conclusion is that web server on Azure has some problem with serving proper web page from time to time.
So this is solved as it is fault of Azure service,
 

Bartosz

Tags
General Discussions
Asked by
Bartosz
Top achievements
Rank 1
Answers by
Stoich
Telerik team
Bartosz
Top achievements
Rank 1
Share this question
or