Playing the test case multiple times

Hi everyone - I am a total noob and Katalon and trying to find my way through.
I am only using the Chrome/Firefox addon of Katalon - although if needed can try to work in studio.
what I am trying to do is a simple script that will do a specific sequence of clicks on a webpage then choose the last record from the last page and hit save.
I managed to get it to choose the last record on a page. However the page number is static in the setup. But the biggest issue is that I would like it to play in a loop.
Every page has max 10 records.

This is the script:
WebUI.openBrowser(‘https://www.google.com/’)
def driver = DriverFactory.getWebDriver()
String baseUrl = “https://www.google.com/
selenium = new WebDriverBackedSelenium(driver, baseUrl)
selenium.open(“BDO : Logowanie”)
Thread.sleep(NaN);
selenium.click(“link=Nowy wpis”)
Thread.sleep(NaN);
selenium.click(“//div[@id=‘_HeaderCard’]/div/div/div/div[2]/div/label”)
Thread.sleep(NaN);
selenium.click(“id=kpoCardNumber”)
Thread.sleep(NaN);
selenium.click(“link=12”)
Thread.sleep(NaN);
selenium.click(“//tr[last()]/td[3]”)
Thread.sleep(NaN);
selenium.click(“link=Zapisz”)

  • selenium.click(“link=12”) - this part is the page number… not sure how to make it look for the last one, but can live with that.

I’m also attacking how the web view looks, if it helps…

But have no idea how to loop it…any help would be really much much appreciated :slight_smile:

The syntax of the for loop is below. The int is a data type, in this case, an Integer. The variable, cnt, can be almost anything starting with a character, such as x, y2 or even, myMotherInLaw. Then you have to have the semi-colon to split the format into sections–starting count section, in this case, from zero; then the maximum number of loops section, in this case, 10; and finally how to increment the count section–in this case, by one.

for (int cnt=0; cnt < 10; cnt++) {
//your code to loop in here
}

https://www.seleniumeasy.com/java-tutorials/looping-statements-java-selenium-webdriver-examples

You can use the loop counter in your code only within the loop if you declare it as I have shown.

More on Loop Counter

If you declare the loop counter as I have done, then after the final curly bracket, the loop counter does NOT exist. However, if needed, you move the initializer to the top of your program but don’t re-initialize it within your program.
You could even start your loop at 12 and then increment up to 22 and use the counter as your page reference/link.

Since your loop counter increments by one, you might be able to use this in your page link.

for (int cnt=0; cnt < 10; cnt++) {
Thread.sleep(NaN);
selenium.click("link=Nowy wpis")
Thread.sleep(NaN);
selenium.click("//div[@id=’_HeaderCard’]/div/div/div/div[2]/div/label")
Thread.sleep(NaN);
selenium.click("id=kpoCardNumber")
Thread.sleep(NaN);
def var = 12 + cnt;
selenium.click("link=" + var.toString())
Thread.sleep(NaN)
selenium.click("//tr[last()]/td[3]")
Thread.sleep(NaN);
selenium.click("link=Zapisz")
}

Yet the code you presented is Groovy code using Katalon Studio WebUI APIs. :confused:

I’ll move this thread to the correct forum category.

Where did you get this code from? Nan, in Java, is a result returned from arithmetic expressions that produced a value defined as “Not a Number”. It’s certainly not a public type you can pass to a method (successfully).

If you have more code above, where you have declared NaN something like this:

int NaN = 42 // DO NOT DO THIS

I strongly advise you to change the name of your variable.

Sorry I didn’t address your question. Before we can help you properly, I need to 1, understand what you’re presenting to me, 2, which product you’re actually using.

Here is the printscreen from the addon itself…

Thanks I am just note sure if I can put this in the web add-on not studio version. If I can can you tell me where? Should I put it as a command and a single step?

Np to be honest I went to the export section in the add-on and copy pasted the code as I thought it will be easier. If it’s not I will paste a print screen from the add-on itself :slight_smile:

As for the NaN I think it’s from the Pause command - to be able to track it and give the website a moment to load everything I have a pause after each step :slight_smile:

I think you’re confusing two different things. You cannot share code between the Katalon Recorde plugin and Katalon Studio.

The code you posted in your first post if for Katalon Studio (but that NaN is an issue).

The code provided by @grylion54 is for Katalon Studio.

The last “printscreen” you posted is for Katalon Recorder.

Katalon Studio and Katalon Recorder are completely different animals. They cannot share test cases.

Clear?

Yes it’s clear and I would like to know if I can do a loop in the Katalon Recorder. And regarding the code as I said I have right now only the Katalon Recorder in browsers. And the code I posted is from the web prowess plugin, I just clicked on the export button in it.

So getting back to the root - is it possible to set a loop in the browser plugin or I should try doing it from scratch in the Studio standalone app?

see if this can help you:

I googled it out yesterday. And took a look at the examples. And while I understand how it works (on the amazon page) I have no idea how to put it in my steps ;/

I hope this view will be easier - I changed the export “target”:

open | https://rejestr-bdo.mos.gov.pl/WasteRegister/WasteRecordCard/Details/TransferedWaste/b2730448-37a2-4d5e-9456-0e64b265c07d |
pause | | 1000
click | link=Nowy wpis |
pause | | 1000
click | //div[@id=’_HeaderCard’]/div/div/div/div[2]/div/label |
pause | | 1000
click | id=kpoCardNumber |
pause | | 1000
click | link=12 |
pause | | 1000
click | //tr[last()]/td[3] |
pause | | 1000
click | link=Zapisz |

First of all, delete every pause command and just use slider instead. Your test will be smaller (files) and you have easy control over this speed.
In case of this loop, i’m not entirely sure what you wnat to achive because you said that you wnat some specific clicks a nd go to last record. I assume that you want to go through every row on every page.

Maybe number of rows on page is in URL? If yes it would be easier to set it to something like 1000 so you will have every row on one page wich will be easier to go through all of them. If it isn’t possible:

Considering that You always have 10 rows and unknown number of pages you need 2 loops one inside another. First loop will go through all the pages and second, inner loop will go through every row.
First get the number of pages - in case from screenshot it will be 12 and save in variable like “numberOfPages” set variable “numberofRows” to 10.
Use while loop - Katalon does not have for loop build in.
When you have this 2 variables:

while | numberOfPages > 0
while | numberOfRows > 0
{some action on single row - be sure to go back to list if your action is clicking something}
storeEval | numberOfRows - 1 | numberOfRows
endWhile
storeEval | numberOfPages - 1 | numberOfPages
storeEval | 10 | numberOfRows // you have to restore number of rows to 10 for next page
endWhile