量角器:等待量角器与页面同步时出错:“angularJS 可测试性和角度可测试性都未定义 [英] Protractor: Error while waiting for Protractor to sync with the page: "both angularJS testability and angular testability are undefined
问题描述
我正在尝试编写一些端到端测试,并希望使用异步和等待.
I am trying to write some end to end tests and waned to use async and await.
配置文件
exports.config = {
framework: 'jasmine',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['spec.js'],
SELENIUM_PROMISE_MANAGER: false,
getPageTimeout: 10000,
multiCapabilities: [
{
browserName: 'firefox'
}, {
browserName: 'chrome'
}
]
}
规范文件
describe('home-view', function(){
beforeEach(async function(){
await browser.get('http://localhost:49335/index.html#!/home');
});
it('sorted by firstname', async function(){
await element(by.css("[ng-click="sortData('firstname')"]")).click();
var firstname = element.all(by.repeater('a in emps')).all(by.css('td'));
expect(await firstname.get(0).getText()).toEqual('abraham');
});
})
错误等待量角器与页面同步时出错:angularJS 可测试性和角度可测试性都未定义.这可能是因为这是一个非角度页面,也可能是因为您的测试涉及客户端导航,这可能会干扰量角器的引导."
Error Error while waiting for Protractor to sync with the page: "both angularJS testability and angular testability are 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."
为什么会出现此错误?谢谢
Why do I get this error? Thanks
推荐答案
你得到这个错误是因为 Protractor 默认会等待 Angular 页面被加载.如果您使用非角度工作,则应将 await browser.waitForAngularEnabled(false);
添加到 onPrepare
块:
You got this error because Protractor by default wait angular page is loaded. If you work with non angular you should add await browser.waitForAngularEnabled(false);
to onPrepare
block:
onPrepare: async () => {
...
await browser.waitForAngularEnabled(false);
...
这种等待"机制是如何工作的?我将从代码中复制描述:
How does this "waiting" mechanism works? I will copy description from code:
* If set to false, Protractor will not wait for Angular $http and $timeout
* tasks to complete before interacting with the browser. This can cause
* flaky tests, but should be used if, for instance, your app continuously
* polls an API with $timeout.
所以,正如您所见,这都是关于 $http
和 $timeout
任务的.开发人员经常以不正确的方式使用它.
So, as you can see it is all about $http
and $timeout
tasks. A bit often developers use it in a not proper way.
总之,如果你看到这样的错误:
In conclusion, if you see such error:
both angularJS testability and angular testability are undefined
你必须添加 await browser.waitForAngularEnabled(false);
.
这篇关于量角器:等待量角器与页面同步时出错:“angularJS 可测试性和角度可测试性都未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!