我试图浏览教程http://angular.github.io/protractor/#/tutorial
当我尝试使用.first()
或.last()
方法获取元素时
测试失败并出现错误:
TypeError Object [object Object]没有方法' indexof'
这里是spec.js
var firstNumber = element(by.model('first'));
var secondNumber = element(by.model('second'));
var go = element(by.id('gobutton'));
var latest = element(by.binding('latest'));
var history = element.all(by.repeater('result in memory'));
beforeEach(function() {
browser.get('http://juliemr.github.io/protractor-demo/');
});
//...other tests passed
it('should have a history', function(){
firstNumber.sendKeys(1);
secondNumber.sendKeys(2);
go.click();
expect(history.count()).toEqual(1);
// expect(history.last()).toContain('1 + 2'); //error here
firstNumber.sendKeys(3);
secondNumber.sendKeys(5);
go.click();
expect(history.count()).toEqual(2);
// expect(history.first()).toContain('3 + 5'); //and here
});
关于这个ElementArrayFinder API它应该运行正常
我正在使用
答案 0 :(得分:2)
您可能希望期待元素的文本:
expect(history.last().getText()).toContain('1 + 2');
expect(history.first().getText()).toContain('3 + 5');