Help with Testcase creation with fallbacks

Hallo everyone,

i have a question about a Testcase i want to build, here is what i want:

click button 1
click button 2
click button 3
click button 4

easy to do but what in my testing happens is, that if i click for example click button 2, a popup opens that i need to close, but i dont know if the popup will come on click 2 or click 3. I can solve it with “if” Function, but i dont want to have the “if” fuction after every click exection.

How can i build a case where i can just define what will happen when i click and it shows a popup. I mean smth like that.

if a popup comes do this, then go back where u were before

click button 1
click button 2
click button 3 = popup comes, you go to statement where u need to close the popup then go back to where u were before and continue
click button 4

Best Regards

Something like this might work:

def click(TestObject button){
		WebUI.waitForAlert(1, FailureHandling.OPTIONAL)
        println "Popup closed!" 
	catch(Exception e){
		println "No pop-up!"

click("button 1")
click("button 2")
click("button 3")
click("button 4")
1 Like