量角器 - 未知错误:使用by.model时未定义角度
问题描述:
我正在为我的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在页面上定义角?
感谢
答
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()
andby.model()
locators are not supported. We recommend usingby.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
[量角器角2失败:未知错误:角没有定义]的可能的复制(https://开头*.com/questions/36201691/protractor-angular-2-failed-unknown-error-angular-is-not-defined) – LoganMzz