TestProject Forum
Powered by leading experts in the test automation community

Looking for a way to do a kind of "if not" then "THIS"

So I have a test that goes to a page and looks for new reviews coming in and validates on the words
“less than a minute ago” depending on when the test is run sometimes those words aren’t there, but then the next best thing of “1 minute ago” which is also test pass is there.

So I need a way to have the test run with if finds “less than a minute ago” pass if not looks for “1 minute ago” then pass if neither then it is okay to fail

Thanks
Marcel

Hello @marcel.bauer,
A proper if-else logic in the recorder for your exact scenario will be published starting next week. In the meantime I can suggest you to implement your if-else logic with our sdk as part of a coded test, or using recovery tests:

You’ll need to use the ‘Invert step result’ option and recovery tests while creating your test, you can see this example:

Preparing
On the web page 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 these elements. Lets give them names:

  1. Question
  2. Answer

Parameters

Lets create 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 the web site, since we will use the equals condition.

Now lets create the first steps.
We should get text from the element where the text of the question is and validate what the exact question is there.

  1. Element action to get text from the element.
  2. 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.

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 .

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 .

Thank you, very thorough. I will look this over and give it a try.

Marcel

Hello, we released the Conditions feature which you can achieve if-else statements:

1 Like

Thank you. I will review this and see about using it within my tests. I really appreciate it.

Marcel