如何使用 Testacular + AngularJS 测试外部服务的应用程序

2023-02-25前端开发问题
4

本文介绍了如何使用 Testacular + AngularJS 测试外部服务的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个在 http://localhost:6543 上运行的应用程序 - 这是一个 Pyramid 应用程序.

I have an app running on http://localhost:6543 - it's a Pyramid app.

  • 此应用在/处为 AngularJS 应用提供服务
  • 此应用使用 socket.io 本身

问题是:是否可以使用这些工具测试该应用程序?

我的 scenario.js 文件中有这个:

I have this in my scenario.js file:

beforeEach(function() {
   browser().navigateTo('http://localhost:6543/');
});

但当我启动 testacular(使用 runstart)时,我收到以下错误消息:

but the moment I launch testacular (with run or start), I get this error message:

Chrome 23.0 registration: should delete all cookies when user clicks on "remove all" button FAILED
browser navigate to 'http://localhost:6543/'
/home/abourget/myapp/jstests/scenarios/registration_scenario.js:9:5: Sandbox Error: Application document not accessible.

所以我知道浏览器不允许访问 iframe 的文档,因为这会违反跨域.

so I understand the browser doesn't give access to the iframe's document, because it'd be some Cross-Origin violation.

我尝试了什么:

  • 使用 Testacular 网络服务器(使用 proxies 选项)代理到我的应用程序,但 / 会与 Testacular 自己的框架服务冲突.此外,这两个应用程序最终都会尝试使用 /socket.io,这也会发生冲突.
  • 做相反的事情(调整我的应用程序以代理到 Testacular 的服务器),但是,我们会遇到与 /socket.io 相同的问题.
  • Proxying to my app using the Testacular web server (with the proxies option), but / would conflict with Testacular's own serving of its framework. Also, both apps would eventually try to use /socket.io and that would conflict also.
  • Doing the reverse (tweaking my app to proxy to Testacular's server), but then, we'd get the same issues with /socket.io.

感谢您提供这些出色的工具,顺便说一句!

Thanks for these great tools, btw!

推荐答案

而不是有

beforeEach(function() {
    browser().navigateTo('http://localhost:6543/');
});

把这个改成

beforeEach(function() {
    browser().navigateTo('/');
});

然后在你的 testacular-e2e.conf.js 文件中添加:

and then in your testacular-e2e.conf.js file add:

proxies = {
    '/': 'http://localhost:6543/'
};

您可能还有其他问题,但我可以重现沙盒错误:无法访问应用程序文档".仅包含 Pyramid Hello World App 和此配置问题的消息.

You might still have other issues, but I can reproduce the "Sandbox Error: Application document not accessible." message with just the Pyramid Hello World App and this configuration problem.

这篇关于如何使用 Testacular + AngularJS 测试外部服务的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

如何使用百度地图API获取地理位置信息
首先,我们需要在百度地图开放平台上申请一个开发者账号,并创建一个应用。在创建应用的过程中,我们会得到一个密钥(ak),这是调用API的凭证。 接下来,我们需要准备一个PHP文件,以便可以在网页中调用。首先,我们需要引入百度地图API的JS文件,代码如下...
2024-11-22 前端开发问题
244

js删除数组中指定元素的5种方法
在JavaScript中,我们有多种方法可以删除数组中的指定元素。以下给出了5种常见的方法并提供了相应的代码示例: 1.使用splice()方法: let array = [0, 1, 2, 3, 4, 5];let index = array.indexOf(2);if (index -1) { array.splice(index, 1);}// array = [0,...
2024-11-22 前端开发问题
182

layui 实现实时刷新一个外部的div
主页面上显示了一个合计,在删除和增加的时候需要更改这个总套数的值: //html代码div class="layui-inline layui-show-xs-block" style="margin-left: 10px" id="sumDiv"spanSOP合计:/spanspan${totalNum}/spanspan套/span/div 于是在我们删除这个条数据后,...
2024-11-14 前端开发问题
156

layui树状组件tree怎么默认勾选?
在layui树状组件tree中,勾选问题可以通过以下方法解决: 通过tree的oncheck事件来监听勾选操作,然后根据勾选状态进行相应的处理。例如: tree.on('check', function(obj) { // 获取勾选状态 var isChecked = obj.checked; // 获取当前节点数据 var data =...
2024-11-09 前端开发问题
372

layui要如何改变时间日历布局大小?
问题描述 我想改变layui时间日历布局大小,这个要怎么操作呢? 解决办法 可以用css样式对时间日历进行重新布局,具体代码如下: !DOCTYPE htmlhtmlheadmeta charset="UTF-8"title/titlelink rel="stylesheet" href="../../layui/css/layui.css" /style#test-...
2024-10-24 前端开发问题
271

JavaScript小数运算出现多位的解决办法
在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会...
2024-10-18 前端开发问题
301