编码 UI 测试项目未触发 Jquery AJAX 成功 [英] Jquery AJAX success not getting triggered with Coded UI test project

查看:32
本文介绍了编码 UI 测试项目未触发 Jquery AJAX 成功的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 asp.net MVC4 应用程序上运行编码 UI 测试项目.该应用程序包含涉及的各种 ajax 调用.当我手动测试时,它工作正常,但是当我使用 coded-ui 测试项目对其进行测试时,它中断是因为在 ajax 调用中,回调函数没有被调用.谁能告诉我我在这里错过了什么.?提前致谢.

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.

推荐答案

出了什么问题

Microsoft 的编码 UI 浏览器会注入 javascript 以填充 XMLHttpRequest 对象以进行跟踪.页面中的任何 ajax 调用都将使用这个 shim 而不是真正的 XMLHttpRequest.shim 假定您的完成回调附加到 XMLHttpRequest 的 onreadystatechange 属性,但 jQuery 2.0 使用新的 onload 和 onerror 事件,因此该回调永远不会被 shim 调用.

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.

解决方法

解决方法是将以下内容添加到您的测试项目的 App.config 文件中:

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>

将 WebWaitForReadyLevel 设置为 3 会阻止编码的 UI WebBrowser 注入 javascript 以跟踪 ajax 调用和计时器.jQuery 将获得一个真正的 XMLHttpRequest,您的 ajax 回调将再次起作用.

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.

这篇关于编码 UI 测试项目未触发 Jquery AJAX 成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆