Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
463 views
in Technique[技术] by (71.8m points)

asp.net mvc - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...