I am having trouble with filtering a ElementArrayFinder of <tr>
elements more than once in my page object. The second filter is being called right after the first one. In the following code, I am first verifying that a number is in the table, and then filtering it again to click on it. The reason i don't just combine these is because they are in functions that rely on the parameter batchNumber of the function, and could be different.
Filter:
function verifyBatchInList(batchNumber){
BATCH_LIST_TABLE.filter(function(elem, i){
return elem.element(by.xpath('./td[1]')).getText().then(function(text){
text = text.trim();
return text === batchNumber;
});
}).then(function(results){
if(results.length < 1){
throw new Error('Could not find batch "'+batchNumber+'" in batch list');
}
});
}
function editBatch(batchNumber){
selectBatch(batchNumber);
EDIT_BUTTON.click(); //this never happens
}
function selectBatch(batchNumber){
BATCH_LIST_TABLE.filter(function(elem, i){ //this function never runs
return elem.element(by.xpath('./td[1]')).getText().then(function(text){
text = text.trim();
return batchNumber === text;
});
}).then(function(results){ //this never runs either
if(results.length < 1){
throw new Error('Could not find batch "'+batchNumber+'" in batch list');
}
results[0].click();
});
When i put a breakpoint inside of the filter function, it only gets there the first iteration, but not the second. The spec running it looks like this.
it('can commit batch', function(){
page.addSpecimens.getBatchId().then(function(text){
batchIds[0] = text.split(' ')[0];
page.addSpecimens.commitBatch();
page = new pages.batchList();
browser.sleep(2000); //for page to load, just temporary
page.verifyBatchInList(batchIds[0]); //this works fine
});
});
it('can edit batch',function(){
page.editBatch(batchIds[0]); //this runs, but never actually filters
});
The html is just a table with the first td being the batch number.