我正在尝试进行基本的 Protractor 测试(使用 Jasmine)。 Protractor 已安装,selenium 正在运行,并且 Protractor 文档中的示例正在运行。
但是,当我将测试网站的内容(angularjs.org 上的“基础知识”示例)复制到 jsfiddle ( http://jsfiddle.net/yfUQ8/2/ ) 时,测试错误:
Error: Error while waiting for Protractor to sync with the page: {}
我的测试如下所示:
describe('angularjs homepage', function() {
it('should greet the named user', function() {
browser.get('http://fiddle.jshell.net/yfUQ8/2/show/'); // fails
// browser.get('http://www.angularjs.org/'); // works
element(by.model('yourName')).sendKeys('Julie');
var greeting = element(by.binding('yourName'));
expect(greeting.getText()).toEqual('Hello Julie!');
});
});
当手动查看 fiddle 时,一切似乎都工作正常。 Angular 使用 ng-app 进行引导,测试在 3 秒内运行(因此看起来并没有超时)。
最佳答案
Protractor需要用ngapp找到元素来同步。默认为“正文”。在你的 jsfiddle 中,我看到:
<body>
<div ng-app>
如果你设置了 rootEl 属性,你的 jsfiddle 应该可以工作。
describe('angularjs homepage', function() {
it('should greet the named user', function() {
browser.get('http://fiddle.jshell.net/yfUQ8/2/show/');
browser.rootEl = 'div';
element(by.model('yourName')).sendKeys('Julie');
var greeting = element(by.binding('yourName'));
expect(greeting.getText()).toEqual('Hello Julie!');
});
});
关于angularjs - Protractor 无法与页面同步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21313018/