Test Suite is failing when getting rowcount on a table

Hi, I am on Katalon Studio v8.6.8 and been working on a script that works on a table. It is working until there is a UI change and need to update the xpath for the table, which I already did. It is working for couple of weeks. Then it fails, the script needs to count the rows and return the no. of rows for a certain logic but it seems it only returns 1 or 0 and sometimes it returns the correct no. of rows. It is just failing locally but when it is executed on bamboo / server it is passing without failures. Do you have any idea what might causes this? Thanks!

1 Like

This is the keyword I am using to get the row count. Hope this helps!

image

Hi there,

Thank you very much for your topic. Please note that it may take a little while before a member of our community or from Katalon team responds to you.

Thanks!

I had problems with some tables because I did not give my script enough time for the table to properly finish forming. My script would keep “blowing up”. What I did was to put in a “wait” statement until a cell in the first data line was visible. Note, not a header line (i.e <th>, but a data line <td>.

Secondly, your Keyword needs the final line to be “return numRows”, like

def Integer getHtmlTableRows(TestObject table, String outerTagName) {
    WebElement mailList = WebUI.findWebElement(table)
    List<WebElement> selectedRows = mailList.findElements(By.xpath(outerTagName + "/tr"))
    int numRows = selectedRows.size()
    return numRows
}

Edit: or you can just return the “size”, like:

List<WebElement> selectedRows = mailList.findElements(By.xpath(outerTagName + "/tr"))
return selectedRows.size()
2 Likes

Actually, it doesn’t need a return statement.

  See 3.2.1 Method definition

At a glance, his code looks fine. However, for clarity, adding an explicit return statement is arguably the better practice.

2 Likes

I updated the code and put a wait and return the selectedRow.size(). Still encountering an intermittent return of 1, but atleast now not all of the test cases are failing. Still this is only encountered locally but when executing on the server, there is no problem. Thanks for your help!

image

Have you seen a screenshot that proves there is only one row?

If you’re still seeing the issue you initially reported, this issue is not resolved.

yeah. unfortunately still encountering this issue.

@null Your problem is network-related. Locally, both the browser and the “network” (i.e you’re running locally) are way faster. You need to introduce delays before allowing any interactions to take place. Also, make sure the structures (e.g. tables) are present by waiting for them to complete.

The solution is in your hands. Dig in and find the thing(s) that’s making your test flaky.