【发布时间】:2016-06-22 23:21:11
【问题描述】:
使用量角器提供的示例conf.js 时似乎出现错误。
我正在使用grunt-protractor-runner 运行我的测试,但即使使用提供的示例配置也会出错。
我的Gruntfile.js 看起来像这样:
/*global module:false*/
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
protractor: {
options: {
configFile: "smoketest.conf.js", // Default config file
keepAlive: false, // If false, the grunt process stops when the test fails.
noColor: false, // If true, protractor will not use colors in its output.
webdriverManagerUpdate: true,
args: {
seleniumServerJar: './node_modules/protractor/selenium/selenium-server-standalone-2.51.0.jar'
}
},
smoke_test: { // Grunt requires at least one target to run so you can simply put 'all: {}' here too.
options: {
configFile: "smoketest.conf.js", // Target-specific config file
args: {
}
}
},
protractor_test: { // Grunt requires at least one target to run so you can simply put 'all: {}' here too.
options: {
configFile: "./node_modules/protractor/example/conf.js", // Target-specific config file
args: {
}
}
},
},
})
grunt.loadNpmTasks('grunt-protractor-runner');
// Default task.
grunt.registerTask('default', ['protractor:smoke_test']);
};
我正在运行使用此文件的grunt protractor:protractor_test:
describe('angularjs homepage', function() {
it('should greet the named user', function() {
browser.get('http://www.angularjs.org');
element(by.model('yourName')).sendKeys('Julie');
var greeting = element(by.binding('yourName'));
expect(greeting.getText()).toEqual('Hello Julie!');
});
describe('todo list', function() {
var todoList;
beforeEach(function() {
browser.get('http://www.angularjs.org');
todoList = element.all(by.repeater('todo in todoList.todos'));
});
it('should list todos', function() {
expect(todoList.count()).toEqual(2);
expect(todoList.get(1).getText()).toEqual('build an angular app');
});
it('should add a todo', function() {
var addTodo = element(by.model('todoList.todoText'));
var addButton = element(by.css('[value="add"]'));
addTodo.sendKeys('write a protractor test');
addButton.click();
expect(todoList.count()).toEqual(3);
expect(todoList.get(2).getText()).toEqual('write a protractor test');
});
});
});
但是,当它运行时,我会遇到错误
Error while waiting for Protractor to sync with the page: "window.angular is undefined. This could be either because this is a non-angular page or because your test involves client-side navigation, which can interfere with Protractor's bootstrapping. See http://git.io/v4gXM for details"`enter code here`
我去过http://git.io/v4gXM,但我似乎找不到任何东西可以解决我的问题?有没有其他人遇到过这个问题,示例测试应该总是有效吗?
【问题讨论】:
-
恢复到旧版本的量角器(最后知道使用我们的测试脚本)并且它可以工作......?
-
可能是因为
Jasmine如果遇到类似问题,下次尝试切换到使用Jasmine2。 (这有很多可能性,但最简单的解决方案是使用 jasmine2) -
升级 Protractor 后我也遇到了类似的错误。对我来说,我在 3.1.1 中没有遇到这个错误,但是我遇到了其他错误,所以我希望 3.2.1 能够修复这些错误。但是对于 3.2.1,我遇到了这个确切的错误。我认为这可能是因为我的 ng-app 指令位于 html 元素而不是 body 元素上。但是将 rootElement: 'html' 添加到我的量角器配置中并没有帮助。 github.com/angular/protractor/issues/1742
标签: javascript angularjs protractor