TestProject Forum
Powered by leading experts in the test automation community

Can TestProject handle if else conditions?

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 :+1:

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 :slight_smile:

Preparing
On the webpage we have 2 elements we should keep:

  1. Element that contains text, which is the secret question
  2. Element where we should type the answer. Some text area.

We should save this elements. Lets give them names

  1. Question
  2. Answer

Quick guide to creating elements on TestProject

Parameters

Lets create now parameters that will contain the questions and answers.
We need 3 Parameters for questions.
For example:

  1. Name of your pet
  2. City where you live
  3. 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.

Quick guide to Parameters on TestProject

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.

  1. Element action to get text from the element.
  2. Validate retrieved text to parameter
Example

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.
2019-09-10_13h59_27

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

  1. Repeat step - that will automatically rerun the step which caused fail.
  2. Continue - which basically continue to next step of the test after recovery test is completed
  3. 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.
2019-09-10_14h38_22

2019-09-10_14h43_33

And add them as recoveries to our steps in the test

And done :slight_smile:

So the scheme of how it works:

  1. Get text
  2. Validate it. If we have match - fail this step so we can do another Test.
  3. Add recovery step to run Type text for each case we have.