我想用量角器测试我的角度应用程序.该应用程序有一个与服务器通信的API模块在这些测试中,我想模拟这个Api模块.我不想进行完整的集成测试,而是根据API的预期值从用户输入进行测试.这不仅可以使客户端测试更快,而且还允许我测试边缘情况,例如连接错误.
我怎样才能用量角器做到这一点?我刚刚开始设置集成测试.
我使用了npm量角器模块,安装了selenium,调整了默认配置并使用onProtractorRunner.js来验证我的设置是否有效.
推荐的嘲讽方式是什么?我假设模拟必须在浏览器中完成,而不是直接在测试文件中完成.我假设测试文件中的命令是特定于量角器的,并将被发送到selenium跑步者.因此,我无法在会话和测试期间共享javascript对象.
我莫名其妙地希望我需要一个像sinon.js这样的间谍库,或者这已经包含在量角器中?
编辑:我在量角器问题跟踪器中读到了这个问题,这可能是一种方法.基本上你在测试中写了一个模拟模块,它被发送到浏览器/应用程序范围内执行.
编辑:这是更有希望的问题.第一部分讨论将Mocks添加到Angular App.第二个谈论嘲笑后端.
这看起来非常好,在这种情况下,Angular App将保留其原始形式.但是,目前仅适用于已弃用的ng-scenario.
我在这个问题上搜索了很多,但找不到解决方案.
我正在试图模拟我的后端,经过充分测试,所以我可以完全隔离我的前端.我尝试过使用protractor-http-mock以及角度模拟的各种努力.
使用HttpBackend解决了角度模拟方法后,我在启动量角器测试时遇到了这个错误:
MBP:test-site admin$ protractor protractor.conf.js
Using ChromeDriver directly...
[launcher] Running 1 instances of WebDriver
[launcher] Error: ReferenceError: window is not defined
at Object.<anonymous> (/Users/Ed/Sites/F4F/web/node_modules/angular/angular.js:30426:4)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Object.<anonymous> (/Users/Ed/Sites/F4F/web/node_modules/angular/index.js:1:1)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
[launcher] Process exited with error code 100
Run Code Online (Sandbox Code Playgroud)
这是我的protractor.conf.js
exports.config = {
directConnect: true,
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'chrome'
}, …Run Code Online (Sandbox Code Playgroud) 尝试运行Protractor时,我在命令行中收到以下错误:
>致命错误:量角器退出代码:1
我需要代理到https测试服务器.我该如何做到这一点?我按照这个Github问题的建议,但我仍然得到上述错误.这是我的配置文件:
// A reference configuration file.
exports.config = {
// ----- How to setup Selenium -----
//
// There are three ways to specify how to use Selenium. Specify one of the
// following:
//
// 1. seleniumServerJar - to start Selenium Standalone locally.
// 2. seleniumAddress - to connect to a Selenium server which is already
// running.
// 3. sauceUser/sauceKey - to use remote Selenium servers via SauceLabs.
// The location of the selenium …Run Code Online (Sandbox Code Playgroud) 我正在尝试自动化角度4应用程序。(量角器,黄瓜,打字稿)。坚持模拟HTTP请求。
找到几种方法:
1)httpBackend 2)http-backend-proxy
但是他们所有人都在谈论AngularJs的应用。根据我的理解,他们已经使用ngMockE2E实现了该功能,而我在angular2 + api doc中找不到。
我也试着跟随这个,没有运气。
谁能在我的量角器项目中帮助我在哪里引用以模拟HTTP调用(GET,POST,PUT等)。
提前致谢。
@Ram Pasala,@ vict:您有任何评论!
我们有一个庞大的项目,我们编写了许多测试用例,以涵盖e2e功能测试用例中的许多实际场景用户行为。
随着测试的进行,它会进行大量的调用以完成测试用例。当我们在酱料实验室中使用其他浏览器时,它会倍增5-9倍。
我要模拟所有其余的调用,这样就不会对实际服务器进行任何真正的调用,但是会在内部对其进行处理。它用于功能e2e测试,而不是单元测试,因为我们使用jasmine模拟了所有单元测试spyOn。
我已经探索json-server和$httpBackend量角器。子服务器不合适,因为它不能很好地处理应用程序的发布,放置,删除呼叫。如果是$ httpBackend
我已经看完了这篇文章,它涉及的是andularJs应用程序而不是angular应用程序,也涉及到有关angularJs的单个rest调用模拟,而不是所有rest调用。
还为angularjs看了这个angularjs 多重模拟,也为angularjs 看到了它,而不是angularjs,看起来像这样更改了查询参数的原始REST URL。
protractor ×5
angularjs ×3
angular ×2
angular-mock ×2
httpbackend ×2
javascript ×2
angular-e2e ×1
angular-test ×1
http-proxy ×1
selenium ×1
typescript ×1
unit-testing ×1