Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement 'if' in Gherkin

I am trying to convert Selenium test to Gherkin. Is there way to implement if statements in Gherkin?

Example : assume the code is written in the below format. I am just writing description as below. Please understand the part after double slash is the actual Selenium code:

// launch the application 
// login to application
// navigate to page
String str;
if(str== "XYZ")
{
    // verify title
}
//verify text field 1
//verify test field 2
//verify select box

For this I am trying to write code in Gherkin as follows

Given user launches the application
When user login with valid credentials
and navigate to required page
When String str is "XYZ"
Then verify title
And verify text field 1
And verify test field 2
And verify select box

but this code is incorrect because if the str is not equal to "XYZ" we want that title should not be verified but other verification like text field1,2 and select box should be verified.

like image 528
Akash Chavan Avatar asked Jan 30 '23 21:01

Akash Chavan


1 Answers

You don't implement if in Gherkin.

Gherkin is about communication and those you want to communicate with, non coders, don't know what an if statement is. They don't care either.

The solution? Two scenarios to cover both cases.

like image 102
Thomas Sundberg Avatar answered May 06 '23 10:05

Thomas Sundberg