Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery AJAX success not getting triggered with Coded UI test project

I am trying to run a Coded-UI test project on a asp.net MVC4 application. The application contains various ajax calls involved. When i test it manually,it works fine but when i test it by using coded-ui test project, it breaks because in the ajax calls,the callback function does not get called. Can anybody tell me what am i missing here.? Thanks in advance.

like image 746
user2617088 Avatar asked Jul 25 '13 04:07

user2617088


1 Answers

What's going wrong

Microsoft's Coded UI browser injects javascript to shim the XMLHttpRequest object for tracking. Any ajax calls in the page will use this shim instead of the real XMLHttpRequest. The shim assumes that your completion callback is attached to the XMLHttpRequest's onreadystatechange property, but jQuery 2.0 uses the new onload and onerror events, so the callback is never called by the shim.

Workaround

The work-around is to add the following to the App.config file for your test project:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="WebWaitForReadyLevel" value="3"/>
  </appSettings>
</configuration>

Setting WebWaitForReadyLevel to 3 stops the Coded UI WebBrowser from injecting the javascript to track ajax calls and timers. jQuery will get a real XMLHttpRequest, and your ajax callbacks will work again.

like image 187
Ross McNab Avatar answered Oct 08 '22 16:10

Ross McNab