If & while methods

update 25 nov 2024


1 - Introduction

The behaviour of your application or website can be random sometimes. For example, a window pop up to activate notifications or the cookies preferences window can appear at the beginning of the functional journey.

The functional journey can contains dynamic content or the need of a repetitive action.

For that, you can use the instruction if and the loop while.

2 - Focus condition “if”

When you want to test your application or your website, it sometimes happens that the actions to be performed are not exactly the same at each measurement iteration. You can use the "if" command to execute GDSL commands only if a condition exists or does not exist.

List of if commands

# exists text if,exists,text,Votre vie privée # not exists text if,notExists,text,Votre vie privée # exists id if,exists,id,0_183215-toggle-cookie # not exists id if,notExists,id,0_183215-toggle-cookie

Use case

We want to configure “airbnb” cookies options.

If the popup “Votre vie privée” is displayed, we click on button “Préférences de cookies”

Then we scroll and select cookie “sécurité” and “ cookie “ Airbnb”

Then we click on button “Enregistrer”

Example :

if,exists,text,Votre vie privée clickByText,Préférences de cookies waitUntilText,Votre confidentialité swipeDownward clickByText,Sécurité clickByText,Airbnb clickByText,Enregistrer fi

You could use measureStart and measureStop inside or outside the if/if but be careful to stop all started measurements.

3 - Focus loop “while”

You can use a while command to repeat some actions

List of while commands

# exists text while,exists,text,Message # not exists text while,notExists,text,Message # exists id while,exists,id,com.google.android.apps.messaging:id/message_text_and_info # not exists id while,notExists,id,com.google.android.apps.messaging:id/message_text_and_info

Use case

We want to delete all sms from the conversation. For this, as long as there is a message, we long click on it and we click on delete it.

Example :

The while loop runs 20 laps maximum. At the end of the 20 laps, if the while condition is not find, an error is launched