Javascript 量角器:如何检查中继器中是否出现条目
我的测试在我正在测试的应用程序中创建一个新条目。测试会插入一条包含时间戳的注释,以便我以后可以识别它 在测试运行的页面上,会显示数据库中所有条目的列表,每个条目旁边都有一个按钮。测试应该获得中继器,测试任务是否在那里,导航到它并单击正确的按钮 我可以导航到该任务并单击按钮,但我对如何测试测试条目是否存在感到困惑Javascript 量角器:如何检查中继器中是否出现条目,javascript,jasmine,protractor,Javascript,Jasmine,Protractor,我的测试在我正在测试的应用程序中创建一个新条目。测试会插入一条包含时间戳的注释,以便我以后可以识别它 在测试运行的页面上,会显示数据库中所有条目的列表,每个条目旁边都有一个按钮。测试应该获得中继器,测试任务是否在那里,导航到它并单击正确的按钮 我可以导航到该任务并单击按钮,但我对如何测试测试条目是否存在感到困惑 it('should start a tasks', function() { repeater = by.repeater('task in taskList');
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),它将成功通过,因此我需要测试它是否达到*(1),或者是否有合适的条目。由于复杂的承诺结构,我不确定如何做到这一点
我怎么知道测试是否运行过?(我这里可能有个脑结,解决办法很明显)
编辑:我更新了plnkr以实际包含一个测试。如您所见,如果注释掉测试条目,测试将成功。如果我理解的话。您希望测试满足某些条件的列表中某个项的存在性,如果未找到该项,则会使预期失败。您可以使用
map
和toContain
的返回值执行此操作:
var hasComment = tasks.map(function(task, index) {
var description = task.findElement(by.className('taskDescription'));
return description.getText().then(function(text) {
var hasTimeStamp = (text.indexOf(timeStampedComment) > -1);
return hasTimeStamp;
});
});
expect(hasComment).toContain(true);
注意
return
语句。这些是将promisehasComment
的解析值作为布尔测试数组的关键,每个测试的结果都有一个时间戳。如果我理解的话。您希望测试满足某些条件的列表中某个项的存在性,如果未找到该项,则会使预期失败。您可以使用map
和toContain
的返回值执行此操作:
var hasComment = tasks.map(function(task, index) {
var description = task.findElement(by.className('taskDescription'));
return description.getText().then(function(text) {
var hasTimeStamp = (text.indexOf(timeStampedComment) > -1);
return hasTimeStamp;
});
});
expect(hasComment).toContain(true);
注意
return
语句。这些是将promisehasComment
的解析值设置为一个布尔测试数组的关键,每个测试的结果都有一个时间戳。我不熟悉Gradurator,但做了类似的事情,解决了我的问题:
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');
});
(注意,在本例中,dragrator.expect为您处理承诺)我对dragrator是新手,但做了类似的操作,为我解决了问题:
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');
});
(注意,在本例中,grandor.expect为您处理承诺)您能为您的应用程序创建一个减少的提琴/弹跳吗?因为通过阅读你的问题,我不清楚你想要测试什么。我同意你不清楚你想要测试什么。也许扩展一下
//你的代码中的一些期望值
?我更新了问题。你能为你的应用程序创建一个简化的提琴/弹琴吗?因为通过阅读你的问题,我不清楚你想要测试什么。我同意你不清楚你想要测试什么。也许扩展一下//你的代码中的一些期望值
?我更新了问题。看起来很棒,非常好!看起来很棒,非常好!