AngularJS量角器E2E-具有绝对URL的模拟httpBackend
我刚刚开始使用量角器为angularJS应用程序进行E2E UI测试 应用程序的基本url类似于-AngularJS量角器E2E-具有绝对URL的模拟httpBackend,angularjs,protractor,Angularjs,Protractor,我刚刚开始使用量角器为angularJS应用程序进行E2E UI测试 应用程序的基本url类似于- http://localhost:8181/web-module/?username=admin 然后,此url重定向到实际应用程序中给定用户名的安全模块。安全模块正在另一个端口9191上运行 重定向的请求看起来像- http://localhost:9191/security-module/user/?username=admin 当我尝试使用$httpBackend模拟此请求时,使用- G
http://localhost:8181/web-module/?username=admin
然后,此url重定向到实际应用程序中给定用户名的安全模块。安全模块正在另一个端口9191上运行
重定向的请求看起来像-
http://localhost:9191/security-module/user/?username=admin
当我尝试使用$httpBackend模拟此请求时,使用-
GET调用仍然试图命中实际的http服务/url,而不是模拟的http服务/url
我不确定我在这里做错了什么。任何帮助都很好。在哪里执行重定向?我认为,它应该是这样的:
$httpBackend.whenGET('http://localhost:8181/web-module/?username=admin')
.respond(function(method, url, data, headers) {
return [200, current_user, {}];
});
因为如果重定向是在服务器端完成的,那么应用程序不知道重定向。我以前也遇到过同样的问题。在whenGET()方法中使用regex,以确保任何其他参数都在那里,并且您看不到它 尝试: 您将匹配所有以正则表达式路径开头的URL。然后,您可以更新正则表达式,以仅在参数为username=admin时指定。将regex与$httpBackend一起使用是一件痛苦的事情,但该服务仅将参数作为字符串进行检查 要避免每次都写:
/^http:\/\/localhost:9191
您可以在paragrator.conf.js中指定baseUrl:
baseUrl: 'http://localhost:9191',
模拟代码在量角器端或应用程序端的何处?@gontard-我猜你指的是httpbackendMock定义。所有代码都在'descripe'块'var httpBackendMock=function(){var app=angular.module('httpBackendMock',['app',ngMockE2E']);app.run(function($httpBackend){}'下的spec javascript文件中。你能提供一个更完整的例子来更新你的问题吗。@gontard-我现在更新了这个问题。
/^http:\/\/localhost:9191
baseUrl: 'http://localhost:9191',