量角器:等待量角器与页面同步时出错:“angularJS 可测试性和 angular 可测试性均未定义
Protractor: Error while waiting for Protractor to sync with the page: "both angularJS testability and angular testability are undefined
我正在尝试编写一些端到端测试,并且不想使用 async 和 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');
});
})
错误
等待量角器与页面同步时出错:"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."
为什么会出现此错误?谢谢
您收到此错误是因为 Protractor 默认等待 angular 页面加载。如果您使用非 angular,您应该将 await browser.waitForAngularEnabled(false);
添加到 onPrepare
块:
onPrepare: async () => {
...
await browser.waitForAngularEnabled(false);
...
这个 "waiting" 机制是如何运作的?我将从代码中复制描述:
* 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
任务的。开发人员经常以不正确的方式使用它。
总之,如果您看到这样的错误:
both angularJS testability and angular testability are undefined
您必须添加 await browser.waitForAngularEnabled(false);
。
给 getPageTimeOut 超过 20 秒。在 browser.get 方法之后使用像 browser.sleep(2000) 这样的显式等待。发生错误可能是因为网页响应缓慢,也可能使用 dirctConnect 而不是 seleniumAddress。
早些时候我需要在我的script.js中添加这个
browser.driver.ignoreSynchronization = 真;
但是添加这个解决了我的问题。
browser.waitForAngularEnabled(假);
所以一共最后 script.js 是
describe('My first non angular class', function() {
it('My function', function() {
browser.driver.ignoreSynchronization = true;
browser.waitForAngularEnabled(false);
browser.driver.manage().window().maximize();
//browser.get('http://juliemr.github.io/protractor-demo/');
browser.driver.get('https://whosebug.com/users/login');
element(by.id('email')).sendKeys('6');
})
})
我正在尝试编写一些端到端测试,并且不想使用 async 和 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');
});
})
错误 等待量角器与页面同步时出错:"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."
为什么会出现此错误?谢谢
您收到此错误是因为 Protractor 默认等待 angular 页面加载。如果您使用非 angular,您应该将 await browser.waitForAngularEnabled(false);
添加到 onPrepare
块:
onPrepare: async () => {
...
await browser.waitForAngularEnabled(false);
...
这个 "waiting" 机制是如何运作的?我将从代码中复制描述:
* 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
任务的。开发人员经常以不正确的方式使用它。
总之,如果您看到这样的错误:
both angularJS testability and angular testability are undefined
您必须添加 await browser.waitForAngularEnabled(false);
。
给 getPageTimeOut 超过 20 秒。在 browser.get 方法之后使用像 browser.sleep(2000) 这样的显式等待。发生错误可能是因为网页响应缓慢,也可能使用 dirctConnect 而不是 seleniumAddress。
早些时候我需要在我的script.js中添加这个 browser.driver.ignoreSynchronization = 真;
但是添加这个解决了我的问题。 browser.waitForAngularEnabled(假);
所以一共最后 script.js 是
describe('My first non angular class', function() {
it('My function', function() {
browser.driver.ignoreSynchronization = true;
browser.waitForAngularEnabled(false);
browser.driver.manage().window().maximize();
//browser.get('http://juliemr.github.io/protractor-demo/');
browser.driver.get('https://whosebug.com/users/login');
element(by.id('email')).sendKeys('6');
})
})