![](/img/trans.png)
[英]Protractor - adding a count function returns “”both angularJS testability and angular testability are undefined…" error
[英]Protractor 3.1.1 + Angular2: Could not find testability for element
我正在使用Protractor 3.1.1和Angular2運行一個簡單的HelloWorld示例,但這件事一直告訴我無法找到元素的可測試性 。 我在網上搜索了有關錯誤的一些信息,但沒有運氣,這似乎是一個新的例外,沒有那么多人面臨過。
這是我正在使用的組件:
import {Component} from 'angular2/core';
@Component({
selector: 'my-app',
template: '<h1>My First Angular 2 App</h1>' +
'<h2>{{myName}}</h2>' +
'<input id="someId" [(ngModel)]="myName"/>'
})
export class AppComponent {
myName = 'Joe';
}
這是Protractor配置文件:
exports.config = {
framework: 'jasmine',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: [
'e2e/*.js'
],
baseUrl: 'http://localhost:3000'
};
這是我正在運行的量角器場景:
describe('angularjs homepage', function() {
it('should say my name', function() {
browser.get('/index.html');
var greeting = element(by.id('someId'));
expect(greeting.getAttribute('value')).toEqual('Joe');
});
});
網頁正常加載模板HTML,但是Protractor認為生成的網頁不是Angular網頁,現在,為什么呢? 顯然,如果我檢查生成的網頁,它只是處理過的Angular代碼的結果HTML,我做錯了嗎?
這是完整的錯誤:
Error: Failed: Error while waiting for Protractor to sync with the page: "Could not find testability for element."
如果我像Protractor Tutorial所說的那樣運行一個簡單的測試,使用這個演示頁面: http ://juliemr.github.io/protractor-demo/,它按預期工作,所以有一些東西我的Angular2代碼,Protractor沒有使用它,但我已經沒有想法,任何人都知道發生了什么?
更新2016年2月23日
經過一些研究,我發現要使用帶有Angular2的Protractor,配置文件中必須有一個額外的配置行:
useAllAngular2AppRoots: true
這樣conf.js現在看起來像:
exports.config = {
framework: 'jasmine',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: [
'e2e/*.js'
],
baseUrl: 'http://localhost:3000',
useAllAngular2AppRoots: true
};
或明確包含應用程序根目錄:
rootElement: 'my-app'
在此更新之后,所有調用以查找元素by.id()
可以正常工作,但是如果您假裝使用任何定位器by.model()
或by.binding()
,它將會失敗並顯示消息UnknownError: unknown error: angular is not defined
。 不知道為什么。
顯然,該提交中存在一個錯誤。 檢查一下! 。
但是現在你可以使用browser.executeScript('window.name = "NG_ENABLE_DEBUG_INFO!"');
運行你的測試browser.executeScript('window.name = "NG_ENABLE_DEBUG_INFO!"');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.