I want to count the positions and see if it matches with the total
Here is my code:
WebUI.click(findTestObject(‘Object Repository/Page_Dashboard/a_Rostering’))
I do have a concern that your test case is clicking the same td_MAG and td_ every time as they are all the same testObjects. Also that if the total is not 42:30, your test case won’t be able to find the td_4230 testObject. But that is not the problem you are trying to solve at the moment.
Let’s see if this works.
The following is written under the assumption that:
The rows ‘MAG’ = 8.5
There is only 1 Total on the page
Not all td rows needs to be clicked on to get the text the td contains
Add the following below your td_4230 and run and send through any errors
//Sets expected total
String expectedTotal = calculateTotal()
//Sets actual total
String actualTotal = WebUI.executeJavaScript('return document.querySelectorAll(\'[data-field*="Week"]\').innerText', [])
//Compares actual total to expected total
WebUI.verifyMatch(actualTotal, expectedTotal, false)
//Method to calculate the expected total and return its value
def calculateTotal() {
Integer tdCount = WebUI.executeJavaScript('return document.querySelectorAll(\'[role="gridcell"]\').length', [])
Double total = 0.0
for(def i = 0; i < tdCount; i++) {
if(WebUI.executeJavaScript('return document.querySelectorAll(\'[role="gridcell"]\')[' + i + '].innerText', []) == 'MAG') {
total = total + 8.5
}
}
String strTotal = total.toString()
if(strTotal.substring(strTotal.indexOf('.')) == '.50') {
strTotal = strTotal.replace('.50', ':30')
}else {
strTotal = strTotal.replace('.00', ':00')
}
return strTotal
}