I need to search through a series of titles that follow the format:
<div class='items'>
* Some | Text *
</div>
or
<div class='items'>
* Some more | Text *
</div>
There are multiple blocks on the page with these patterns, and I want to loop through them all to ensure they contain '* Some [more] | Text *', where [more] is optional and * can be any text.
My current code snippet looks like this:
yield browser
...Some code...
.elements('.items')
.then((elementList)=>{
for(var i = 0; i < elementList.value.length; i++){
this.elementIdText(elementList.value[i].ELEMENT)
.then((currElement)=>{
var str = currElement.value;
if(str.indexOf("Some | Text") == -1 || str.indexOf("Some more | Text") == -1){
assert.ok(false, 'invalid string');
}
})
}
})
However, it appears that the asserts are being ignored because they're inside a for loop, which may cause synchronization issues.
Although I want the program to fail as soon as one of the strings does not match the required pattern, so I thought using a loop was necessary.
Is there a better way to achieve this?
The current behavior shows a console.log inside the for loop:
Command: find element
Command: find element
... n times
log: element 1 text
log: element 2 text
... n times
Instead of the preferred:
Command
log
Command
log
... n times