我有一些用量角器编写的e2e测试。我的某些测试执行的内容会导致显示警报(uib-alert)。测试运行良好,可以找到并验证警报,但是如果我使用uib-alert的标记dismiss-on-timeout,则测试将失败,因为量角器在执行断言之前会等待超时。
问题:https : //github.com/angular-ui/bootstrap/pull/2798和https://github.com/angular/protractor/issues/169
因此,我想在运行量角器时创建不带time-out-timeout标签的警报。
我的警报是由这样的服务创建的:
angular.module('MyApp').factory("AlertService", function (...
如何在量角器上覆盖此内容?我正在尝试使用browser.addMockModule('AlertService',模拟),但这不起作用...
我通过将AlertService提取到一个全新的模块然后对其进行模拟来做到这一点。我想量角器不能模拟模块中的单个服务,只能模拟整个事情。
编辑:我创建了alert.module.js:
angular.module('MyApp.alert', []);
angular.module('MyApp.alert').factory("AlertService", function($rootScope) {
...
而在protractor.conf.js上,它们是:
exports.config = {
framework: 'jasmine',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: [],
capabilities: {
browserName: 'phantomjs',
'phantomjs.binary.path': require('phantomjs-prebuilt').path
},
onPrepare: function() {
...
function mockAlertService(){
var alertMock = function() {
angular.module('MyApp.alert', []);
angular.module('MyApp.alert').factory("AlertService", function($rootScope) {
...
}
browser.addMockModule('MyApp.alert', alertMock);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句