Hi. I’m stuck in my test where i have the Reset password page. I have there a secret question which can be one of 3 different questions. It is random. Can i somehow create if else conditions to make the correct answer typed whatever the question appears?
Hi Sunil! Glad to see you here
It is possible. But first i’d want to recommend to do it by the coded test, using TestProject SDK.
I’ll add a step-by-step explanation below. It’s simpler than it could looks like for the first time
Preparing
On the webpage we have 2 elements we should keep:
- Element that contains text, which is the secret question
- Element where we should type the answer. Some text area.
We should save this elements. Lets give them names
- Question
- Answer
Parameters
Lets create now parameters that will contain the questions and answers.
We need 3 Parameters for questions.
For example:
- Name of your pet
- City where you live
- Favorite flavor of ice cream.
Note that values (questions in our case) should be the same as they appears on web site, since we will use equals condition.
Now lets create first steps.
We should get text from the element where the text of the question is and validate what exact question there.
- Element action to get text from the element.
- Validate retrieved text to parameter
We need to add 3 like this one, since we have 3 different question. Only difference in steps will be in the validation. We already have validation to Question1. Lets create 2 more, for Question 2 and 3.
Now we have our IF.
We will have 2 failed and 1 passed step since only 1 out of 3 will always match the question.
But we can invert this and make the failed steps show as passed and passed as failed.
How to invert step result example
We just need to open the step and go down where we can see this action to invert step result.
Now if step validates the ‘Name of your pet’ and answer was the same - step will be reverted from passed to failed, so we can do something in this case.
And here comes the Recovery test.
Quick guide to recovery tests
You can literally understand this as “Run selected test if this exact step was failed”.
The nice example is when the Web page loads, you expect to see a button to click.
But there was error and button not appears. So click action was failed.
Here we adding recovery test, which we created before, that have 1 action - refresh page.
So we will have this : if page loaded with errors and button can’t be clicked - it triggers our recovery test.
It’s possibe to select
- Repeat step - that will automatically rerun the step which caused fail.
- Continue - which basically continue to next step of the test after recovery test is completed
- Fail - it will literally end the test execution after recovery completes.
Now lets create 3 new small tests which will have only 1 action - Type text in element where we need to type the answer.

And add them as recoveries to our steps in the test
And done
So the scheme of how it works:
- Get text
- Validate it. If we have match - fail this step so we can do another Test.
- Add recovery step to run Type text for each case we have.
Hi @Sunil ,
From now on you can also enjoy a new capability built-in to TestProject’s recorder, enabling if-else conditions. You can read more about how to utilize it here:
https://intercom.help/testprojectio/en/articles/3788681-if-else-logic
Good tasks, hoping that everyone is well, I would like to see what version of TestProject you are using since the search for elements does not appear in the version that I have. Thank you very much in advance.
I figured out a way to perform ‘else’ functionality using recovery tests.
Just form 2 different tests from the steps you want to perform in the ‘if’ and ‘else’ blocks.
Condition for the if block can be given using the ‘conditions’ functionality in advanced options inside the steps.
Just add the ‘else’ block test as a recovery test for the ‘if’ block test.
Hope this helps everyone who visits this thread.