我的测试在我正在测试的应用程序中创建了一个新条目。测试会插入一条包含时间戳的评论,以便我稍后识别它。
在运行测试的页面上,会显示数据库中所有条目的列表,每个条目旁边都有一个按钮。测试应该获取转发器,测试任务是否在其中,导航到它并单击正确的按钮。
我可以导航到任务并单击按钮,但我对如何测试测试条目是否存在感到困惑。
it('should start a tasks', function() {
repeater = by.repeater('task in taskList');
tasks = element.all( repeater );
expect( tasks.count() ).not.toBe(0);
// ???
// the missing piece would go here
// = Check if the list contains a task with the time stamped comment
// Now in detail we single out the task an click its button to
// perform additional tests
tasks.map( function(elmnt, indx){
description = elmnt.findElement( by.className('taskDescription') );
description.getText().then( function(text){
if ( text.indexOf( timeStampedComment ) > -1 ) {
console.log("Found the test entry!");
// click the button *(1)
// some expectation
};
});
});
});
如果测试永远不会到达 *(1) 它将成功通过,所以我需要测试它是否到达那里或者是否有合适的条目。由于复杂的 promise 结构,我不确定如何去做。
我怎么知道测试是否运行过? (我可能在这里有一个脑结,解决方案很明显)
编辑:我更新了 plnkr 以实际包含一个测试。如您所见,如果您注释掉测试条目,测试就会成功。
最佳答案
我是 Protractor 的新手,但做了类似的事情,这为我解决了问题:
it('should have Juri in the list', function(){
var data = element.all(by.repeater('person in people').column('person.name'));
data.getText().then(function(text){
expect(text).toContain('Juri');
});
});
甚至更短的形式
it('should have Juri in the list', function(){
var data = element.all(by.repeater('person in people').column('person.name'));
expect(data.getText()).toContain('Juri');
});
(注意,在这种情况下,Protractor.expect 会为您处理 promise )
关于javascript - Protractor :如何检查中继器中是否完全出现一个条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22682645/