如何使用 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.

相关文章