Hello Everyone, In this series of blog it’s time to look into how to write test cases in cucumber and execution of these test cases.Follow these Steps for the Same.
You can read the previous post related to installation of cucumber: here
Step 1: We will use the test package to define the location of features (Resources folder), step definitions (Java folder) and other files.
Then Create a class CucumberRunnerTest in StepDefinitions package and it will look like:
Step 2: We will write a feature file for eg. Addition of Numbers.
Step 3: We will create a .feature file(Written in Gherkins language) in feature package. ( for creating .feature file, select “File” option in new menu and name the file with <>.feature, which cucumber understands).
Feature file will be look like this:
Step 4: Next step is to add Step Definitions for this feature file. For this we have to Right click on feature file and click Run As –> Cucumber Feature
As we run feature we get this in console output and it would suggest the methods required as part of step definition:
Step 5: Create a FirstStep.java file in package StepDefinitions. Copy Cucumber suggestions from console output, paste them to FirstStep.java file.
Step 6: Replace all the Throws exception with the required code, which will be executed when the test case is run. So we will write code related to our test scenario like this.
Step 7: After completing all these steps we will execute our test cases for this we have two ways to do it:
1. Run the Runner from eclipse. by right clicking the CucumberRunnerTest file –> Run as –> JUnit Test.
This is the OUTPUT:
2. We can execute this framework from terminal as well. Open command prompt. cd to project root directory. And Run following command:
- mvn test (in Ubuntu)
This is the OUTPUT:
3.Run the feature from eclipse. by right clicking the feature file –> Run as –> Cucumber feature.
This is the OUTPUT :
Hope the blog helps you.
1 thought on “Tutorial 2:Introduction on how to write a First Test Script in CUCUMBER2 min read”
Comments are closed.