TestProject Forum

How to run a step until a element with 'abc' ID is visible

Hi. How can I run a step like ‘back button(key event 4)’ multiple time until a Element/App-Page with given ID appears on screen?
I’m trying to implement this because I want to click on back button until my app comes to homePage of the app.

Hello @atharv228.as
You can do that as the following example:
Create a step using press android key action with BACK key.


And then make it a test Call it BACKTest:

You can delete it from your main test, we will use it as a recovery test.
Then go to your home page and select an element, using Is visible action

Change the Step Repeats to the maximum number of times that you will need to press on the BACK key, for example, 10.
image
Now go to On Failure Behavior settings in this step and select the backTest as recovery test, and select Continue.
image

Now what will happen is, when the Agent checks if the element is visible and it is not, the step will fail, every time the step fails the next step will be press the BACK key as a recovery test, if the element is present it will proceed to the next steps because it means it is on your home page now.
The example was done on mobile but we can do the same on the web apps, just need to change actions.

2 Likes

Hi. Thanks for the reply. But the step at which is visible is added, takes a lot of time to execute and after that it gives the error:

“The expected element in step #5 is missing. Don’t worry, TestProject’s AI is looking for another path forward. Hold tight…”

Repeat #1 - Action failed using following locators:
XPATH = TimeoutException: Timeout occurred while trying to perform the action. Element was not found
ID = Timeout occurred while trying to perform the action. Element was not found

Repeat #2 - Action failed using following locators:
XPATH = TimeoutException: Timeout occurred while trying to perform the action. Element was not found
ID = Timeout occurred while trying to perform the action. Element was not found

Repeat #3 - Action failed using following locators:
XPATH = TimeoutException: Timeout occurred while trying to perform the action. Element was not found
ID = Timeout occurred while trying to perform the action. Element was not found

Repeat #3 - Action failed using following locators:
XPATH = TimeoutException: Timeout occurred while trying to perform the action. Element was not found
ID = Timeout occurred while trying to perform the action. Element was not found

Repeat #4 - Action failed using following locators:
XPATH = TimeoutException: Timeout occurred while trying to perform the action. Element was not found
ID = Timeout occurred while trying to perform the action. Element was not found\

To shorten the time, you can leave one locator to the is visible.
Edit the locator and make sure the one you leave manages to locate it.
image
And change the adaptive wait to this step to 1000ms

Did you use “BACKTest” as a recovery test?
You should not get such an error if it fails and if you did it exactly as I showed in the example since when the step fails it does not need to perform the recovery test.
Take a look at the following example:

1 Like

Thanks for explaining again clearly. I am able to come back to home screen, but when it comes back to homescreen it gives me yellow color warning that the element (which is to be found) has not been found. I am adding the logs:-

Message

Repeat #1 - Action failed using following locators:

  1. ID=com.exampleID
    TimeoutException: Timeout occurred while trying to perform the action. Element was not found

Repeat #2 - Action failed using following locators:

  1. ID=com.exampleID
    TimeoutException: Timeout occurred while trying to perform the action. Element was not found

Repeat #3 - No Message
Repeat #4 - No Message
Repeat #5 - No Message
Repeat #6 - No Message
Repeat #7 - No Message
Repeat #8 - No Message
Repeat #9 - No Message
Repeat #10 - No Message

Element

image_description4<android.widget.ImageView>

Searched by ID:com.exampleID

Hey
As I mentioned, since the Agent looking for an element that exists and in your case it’s not because you’re not on the home page then you will get this message and the agent will use the recovery test (“BACKTest”) that will actually click on the back key.
By the third iteration, he was already on the home page so the step pass and you got it “Repeat #3 - No Message”-“Repeat #10 - No Message”.
This is exactly what should happen, it means you did not need more than 2 presses on the back key to go to the home page.
But it does not really matter, because in the end, you have achieved your goal.

1 Like

Thanks for explaining and solving issue.