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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With