角量角器 e2e 测试 [英] Angular Protractor e2e Testing

查看:22
本文介绍了角量角器 e2e 测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Protractor 为我的 Angular 应用程序编写端到端测试.我可以模拟 httpBackend 进行单元测试,但我想实际调用服务器并获取 JSON 响应并再次编写测试返回的数据.
我已经阅读了很多关于 stackoverflow 的内容,但无法理解这是如何完成的.

I am writing an end-to-end test using Protractor for my Angular application. I can mock httpBackend for unit test but I want to actually call the server and get the JSON response back and write tests again the data returned.
I have read a lot on stackoverflow but can not understand how this is done.

我使用 $http 吗?如何将它注入我的 Jasmine 测试中?如何将响应 JSON 返回到我的 Jasmine 测试中?

Do I use $http? How do I inject it into my Jasmine tests? How do I get the response JSON back into my Jasmine test?

任何帮助或资源链接以及有关执行此操作的说明都会有所帮助.

any help or links to resources with instructions on doing this will be helpful.

再次,我不想模拟服务器,我想访问服务器并取回 JSON.

Again I do NOT want to mock to server, I want to hit the server and get the JSON back.

谢谢!

推荐答案

我现在正在自己解决这个问题.我认为简短的回答是你设置你的应用程序就像你自己手动测试它一样 - 所以量角器实际上只是一个机器人用户,它没有(嗯,几乎没有)访问你的应用程序的内部.

I'm working through this myself at the moment. The short answer I think is that you set up your application exactly the same as if you were manually testing it yourself - so Protractor is really just a robot user, it has no (well, almost no) access to the internals of your application.

因此,如果您的应用程序需要一个 Web 服务器(大多数都需要),那么您启动该 Web 服务器,然后让量角器通过浏览器连接到您的应用程序并运行它.

So, if your application needs a web server (and most do), then you start up that web server, then have protractor connect to your application via the browser and exercise it.

就我而言,我的目标是使用 grunt 在开始运行我的量角器 e2e 测试之前调用一个执行基本数据库设置的任务 - 这应该会给我一个已知的数据库状态.

For my case, I'm aiming to use grunt to call a task that does basic database setup before it starts running my protractor e2e tests - this should give me a known database state.

作为一个例子,我一直在编写一个使用 Rails 4 和 AngularJS 的教程,关于使用量角器进行 e2e 测试的部分不是特定于 Rails 的,可能有用:http://technpol.wordpress.com/2013/11/16/5-end-to-end-testing/

For an example of this, I've been writing a tutorial for using Rails 4 with AngularJS, the section on using protractor for e2e testing is not rails-specific and might be useful: http://technpol.wordpress.com/2013/11/16/5-end-to-end-testing/

这篇关于角量角器 e2e 测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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