量角器:等待量角器与页面同步时出错:"angularJS可测试性和角度可测试性均未定义 [英] Protractor: Error while waiting for Protractor to sync with the page: "both angularJS testability and angular testability are undefined
问题描述
我正在尝试编写一些端到端测试,并希望使用async和await.
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
推荐答案
您收到此错误的原因是,默认情况下,量角器会加载等待角度页面.如果使用非角度,则应在onPrepare
块中添加await browser.waitForAngularEnabled(false);
:
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屋!