2017-06-15 118 views
1

我正在爲我的Angular組件編寫一些量角器測試,並在嘗試使用時不斷收到錯誤「未知錯誤:未定義角度」 .model來選擇輸入元素。量角器 - 未知錯誤:使用by.model時未定義角度

它的奇怪,因爲如果我這樣做,它工作正常和pases:

it('should have an input element for searching',() => { 
    var inputElement = element(by.model('searchText'); 
    expect(inputElement).toBeDefined(); 
}); 

但是,當我嘗試做這樣的事情它失敗的角未定義錯誤:

it('should filter the search text',() => { 
    var inputElement = element(by.model('searchText'); 
    expect(inputElement).toBeDefined(); 

    inputElement.clear() 
    inputElement.click(); 
    inputElement.sendKeys('ICBC'); 

    var tableLengthRow = element.all(by.css('.animate-repeat').count(); 
    expect(tableLength).toBe(1); 
}); 

如果我這一個

var inputElement = element(by.model('searchText'); 

:替換該行

var inputElement = element.all(by.tagName('input')).get(0); 

並離開休息,因爲我有它的測試通過。

有誰知道爲什麼上面的第一個測試與by.model一起工作,但不是第二個,我實際上點擊元素?

然後我怎樣才能使用Webpack和npm在頁面上定義角?

感謝

+0

[量角器角2失敗:未知錯誤:角沒有定義]的可能的複製(https://開頭stackoverflow.com/questions/36201691/protractor-angular-2-failed-unknown-error-angular-is-not-defined) – LoganMzz

回答

3

by.model沒有在角(angular2,angular4和)的支持。

推薦的替代方案是by.css()

作爲每angular/protractor's current readme:在Angular Guide - E2E Tests替代的

Protractor works with AngularJS versions greater than 1.0.6/1.1.4, and is compatible with Angular applications. Note that for Angular apps, the by.binding() and by.model() locators are not supported. We recommend using by.css() .

實例:

Previous code    New code   Notes 
by.model('$ctrl.query')  by.css('input') The model matcher relies on AngularJS ng-model 
by.model('$ctrl.orderProp') by.css('select') The model matcher relies on AngularJS ng-model 
相關問題