FInd duplicate test obj by looping?

Hey guys,
So I’m trying to write the looping statement for the test to search for all the same/similar elements in a page and perform a delete. Almost like a data cleanup process.

So this is what I’m trying to do…

  1. search for testobect x, if the testobj x exists in the UI → delete that testobj
    and loop that function so it does it until all the testobj are deleted.

currently I’m using the if statements… which works but not the best way. but I know there’s a better loop statements that can do the same. anyone?

1 Like

I am not sure what you want to do but let me show you my previous development which might interest you:

1 Like

just trying to delete all the testOjects in the UI. Basically, I’m using if statements… if statement will only repeat as many times as i say it…

so was asking if there’s a way to just use loop function to run my delete function according to how many of the testobject are found in the UI. Like if there’s 5 of the testobj, it would go thru the delete function 5 x until all the testobj are deleted.

1 Like

Can you share the test code you’ve written so far? I think there’s some confusion of terms here.

1 Like

So I’m basically checking if there’s the testobj on the page and if there is delete it… im basically duplicating the if statements 3 times… i mean it works if there’s 3 or less of those objects…
but was wondering if there’s a better smarter way of doing this. if we can apply some sort of loop functions after getting the total count of those test objects and for each count, execute that delete test case.

if (WebUI.verifyElementPresent(findTestObject('AMR financials/financial_asset'), 5, 
	FailureHandling.OPTIONAL)) {
	WebUI.click(findTestObject('AMR financials/financial_asset'))
	WebUI.callTestCase(findTestCase('X -Reusable_functions/delete_financials'), [:],
		FailureHandling.STOP_ON_FAILURE)

} else {
    WebUI.closeBrowser()

    
}
if (WebUI.verifyElementPresent(findTestObject('AMR financials/financial_asset'), 5,
	FailureHandling.OPTIONAL)) {
	WebUI.click(findTestObject('AMR financials/financial_asset'))
	WebUI.callTestCase(findTestCase('X -Reusable_functions/delete_financials'), [:],
		FailureHandling.STOP_ON_FAILURE)

	} else {
		WebUI.closeBrowser()
		
}

if (WebUI.verifyElementPresent(findTestObject('AMR financials/financial_asset'), 5,
	FailureHandling.OPTIONAL)) {
	WebUI.click(findTestObject('AMR financials/financial_asset'))
	WebUI.callTestCase(findTestCase('X -Reusable_functions/delete_financials'), [:],
		FailureHandling.STOP_ON_FAILURE)

} else {
	WebUI.closeBrowser()
	
}

1 Like

Thanks, and what exactly are you doing in the “delete_financials” test case? Can you share that code?

1 Like

While you collect that, again I think there’s some confusion of terms here. Like when you say delete “test objects”. In the Katalon world, a “test object” is just a container for a locator that is eventually used to find an element in the web page that you are automating. I.e. test objects are all of the stuff in your Object Repository in Katalon. So when you say you want to delete those, that would mean deleting those items from Katalon itself, which I don’t think makes any sense. So if you can share your delete test case we can see what exactly you mean by delete test objects.

1 Like

ya my bad… i cross-use the term web elements and testobj… i’m deleting the elements “financial_asset” from the UI. That’s basically what the delete_financials tc is. It’s a tc made up of several steps to delete the financials that’s in the UI.
So in this case, if I have 3 of those elements on that page, it would delete them one after the other.

Got it, thanks, give me a second I’ll get you some code.

while (WebUI.verifyElementPresent(findTestObject('AMR financials/financial_asset'), 5, 
	FailureHandling.OPTIONAL)) {
    WebUI.click(findTestObject('AMR financials/financial_asset'))
    WebUI.callTestCase(findTestCase('X -Reusable_functions/delete_financials'), [:],
		FailureHandling.STOP_ON_FAILURE)
}

Give that a try.

3 Likes

well, simple wasn’t it. i was so focused on getting the total count of all the elements and using the for int = loop method I saw someone else doing it, that this went over my head.

Thanks! Much cleaner and simpler! :smiley:

2 Likes

The simplest answers are usually the best ones :smile: glad it’s working!

1 Like