Create Feature File and Step Definition File in Cucumber - Way2Automation
Create Feature File and Step Definition File in Cucumber - Way2Automation
o Configure the cucumber feature
Finish
Notice below that feature file gets created with some default features.
This is due to the cucumber plugin that we had installed in the
previous tutorial
You can also see some of the comments (lines 1-18) that describe
some of the keywords for your ready reference.
Let us remove the sample features (line#19 onwards)
Now hit spacebar to create whitespace. Notice that the color changes
Let us now write the ‘Given’ keyword which defines some pre-condition
Next we will write ‘Then’ statement that defines an outcome
So this was our first scenario. Likewise, you can write any number of
scenarios for search feature.
Configure the cucumber feature
Let us see how to configure cucumber feature
Right click feature file > Run As > Run Configurations
See below. Expand ‘Cucumber Feature’ and select New_configuration.
Click ‘Browse’ button and select the path of the feature file
The below message would be seen in console:
Create Step Definition
Recall the cucumber framework design that we had discussed in
previous tutorial. In a step definition file, we map the Give/When/Then
steps using @ annotations
Next, go to the console and copy the code snippets
Right now there are 3 errors. Press Ctrl+Shift+o to import
Given/When/Then
Next, whatever is the step name "Search field should be present on the
Way2Automation website", cucumber will generate the same method
name
Note: You can change the method name to any other desired name,
example search_field_should_be_present_on_the_website(). However,
the step name CANNOT be changed. So, you cannot change the step
name to @Given("Search field should be present on the website").
Next, the string that we mentioned within double quotes in the ‘When’
step, translates to {string} in the step definition file. Similalrly, the
integer we mentioned in the ‘When’ step, translates to {int} in the step
definition file. Also, cucumber automatically generates 2 method
parameters: String, Integer
Next, you can change the variable names as seen below
Similarly, you can change the variable name in @Then method
One thing that you notice in the step definition file is that, cucumber
automatically generates an exception. The reason being, we have not
yet written any java code for the respective steps.
So, when you now run the feature file, the console shows the same
Exception
To resolve this, let us remove the exception from the step def file, see
below
Whatever course name and price you have written in the feature file,
the same gets passed to ‘courseName’ and ‘price’ variables
respectively in step def file.
Next, let us again run the feature file
Notice the console output, all 3 steps got passed this time. There are
no exceptions.
Also notice that the respective course name and price gets passed to
the SOPs, see below. You can also see the respective Give/When/Then
steps in the console below. The course name mentioned in
When/Then steps matches with the course names in respective SOPs
Leave a Comment
Your email address will not be published. Required fields are marked *
Type here..
Name*
Email*
Website
Save my name, email, and website in this browser for the next time I comment.
Post Comment »
Search
Recent Posts
Identify Nth element using Playwright Java
Download a File using Playwright Java
Create and upload a new file during runtime using Playwright Java
Post API Request using Playwright Java
Keypress and GET Request API testing in Playwright Java
Archives
November 2022
October 2022
September 2022
August 2022
July 2022
March 2022
February 2022
January 2022
December 2021
November 2021
October 2021
September 2021
Categories
Behave BDD
Cucumber BDD
Cypress
DevOps
Playwright JAVA
Playwright JS
Selenium 4.0
Selenium C#
Selenium Java
Worked with various CMM level orgranizations. Involved in setting up of manual and
automation testing teams. Implemented various automation projects using Selenium,
Webservices REST APIs, QTP, SOAP UI, Cypress, Robot Framework, Protractor, JMeter etc.
IMPORTANT LINKS
Home
About Us
Member Login
Lifetime Membership
Buy Now
Careers
Contact Us
COURSES
Selenium Java
Selenium Python
Selenium Python
API Testing
DevOps
Jmeter
Manual Testing
Appium Java
Appium Python
Robot Framework
ABOUT US
CDR Complex, 3rd Floor, Naya Bans Market, Sector 15, Noida, Near sec-16 Metro Station
+91 97111-11-558
+91 97111-91-558
[email protected]
[email protected]