I was trying to write a test case to verify context on the page.
There are several iterating, the content for a single page could be merged by the solution from: How to use scriptAll to find all the <div> with id or style attributes in Karate
There is one more issue with this scenario - the content has been cut off into multiple pages. There is no button available to go to next page unless pressing Enter key.
Also the only way to identify if it has come to the end of the context is from following section:
<div id="msgList" class="test">
<table>
<tbody>
<tr class="infoText">
<td class="Type">reminder</td>
<td class="Text">99 more data to view</td>
<td class="messageNumber">#12345</td>
</tr>
</tbody>
</table>
<div id="message" style="display:none;">reminder more data to view</div>
</div>
It will change as below until coming to the last page:
<div id="msgList" class="test">
<table>
<tbody>
<tr>
<td class="Type">23456</td>
<td class="Text">enter your input</td>
</tr>
</tbody>
</table>
<div id="message" style="display:none;">23456 enter your input</div>
</div>
EDITED: or ('.messageNumber' still displaying - but with different value)
<div id="msgList" class="test">
<table>
<tbody>
<tr>
<td class="Type">reminder</td>
<td class="Text">66 no more data to view</td>
<td class="messageNumber">#98765</td>
</tr>
</tbody>
</table>
<div id="message" style="display:none;">random text</div>
</div>
Just wondering is there a way to use conditional logic to loop through all pages and merge the content(with solution extracting context from each single page) together for assertion?
The format for each page is exactly the same.
EDITED: Eventually made it work with a js function
* def allData = []
* def loopContent =
"""
function() {
while (allData) {
let list = locateAll('form div', x => { let id = x.attribute('id'); return id ? id.startsWith('line1_R') : false });
let data = list.map(x => x.text.trim());
let msgText = script('.Text','_.textContent').trim();
if (msgText != "reminder more data to view"){
allData.push(data);
return allData;
}
else if(msgText == "reminder more data to view){
allData.push(data);
input('body', Key.ENTER);
}
else{
karate.fail("Content not being looped properly");
}
}
}
"""
* def letterContent = loopContent()
* print letterContent
Many thanks