What Is Cucumber?: Why Use Cucumber With Selenium?
What Is Cucumber?: Why Use Cucumber With Selenium?
What Is Cucumber?: Why Use Cucumber With Selenium?
What is Selenium?
Selenium is an automation tool for Functional Testing of the web-based application. Selenium
supports different language like java, ruby, python C#, etc.
Scenario 3: Enter login Credential on Guru99 & reset the value. Do this for 3 sets of
data.
Most of the organizations use Selenium for functional testing. These organizations which are
using Selenium want to integrate Cucumber with selenium as Cucumber makes it easy to
read and to understand the application flow.
Cucumber tool is based on the Behavior Driven Development framework that acts as the
bridge between the following people:
Selenium-server-standalone
Cucumber-core
Cucumber-html
Cucumber-java
Cucumber-junit
Cucumber-jvm-deps
Cucumber-reporting
Hemcrest-core
Gherkin
Junit
You need to search files and download them one by one individually.
For example, we will show you to download one of the jar files, i.e., "Cucumber-core."
Click on the above download link. It redirects to the below site. Now search the particular jar,
i.e. 'Cucumber Core' as shown screenshot below:
Note: For your ease, we have bundled the jar files required to be download from Maven here.
With time these jars maybe updated and become incompatible. You are requested to
download them using the method illustrated above.
Create Java project with the name "CucumberWithSelenium" as shown in the below
screenshot.
For creating feature file first create features folder as shown below screenshot.
Now Enter Folder name 'Features' and click on 'Finish' Button.
Now, create feature file in the 'Features' folder with the name of "MyTest.feature" - Process is
similar to creating a folder
Note: You may need to install the Cucumber Eclipse Plugin for this to work. Goto -- Helps-
>Install New Software->copy paste the link http://cucumber.github.io/cucumber-
eclipse/update-site/ and install
Below lines are written in 'MyTest.feature' file using the Gherkin language as shown below:
Code Explanation
Here we create 'TestRunner' package and then 'Runner.java' class file under it.
package TestRunner;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(features="Features",glue={"StepDefinition"})
public class Runner
{
In the above code we run the cucumber test by using the following annotations:
@RunWith() annotation tells about the test runner class to start executing our tests.
@CucmberOptions() annotation is used to set some properties for our cucumber test like
feature file, step definition, etc.
Now here we create 'StepDefinition' package and then 'Steps.java' script file under it. Here we
actually write a selenium script to carry out the test under Cucumber methods.
package StepDefinition;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
In the above code, the class is created with the name 'Steps.' Cucumber annotation is used to
map with feature file. Each annotation method is defined:
@Given annotation define method to open firefox and launch the application
Below is the screenshot of the 'Steps.java' script and project tree, how it looks like.
Note: Step definition is nothing but the steps you want to perform under this cucumber
method.
The user can execute this script from Test runner script, i.e. 'Runner.java' as shown in below
screenshot.
Step 8) Analyze the output.
On executing the 'Runner.java' script, it displays the text on the console. It is the same text
defined in 'Steps.java' script.
For Scenario 2 we need to update only 'Steps.java' script. Here we actually write the selenium
script as shown below steps. First, we need to add Selenium jar file to this project.
Step 1) Here we update the 'Steps.java' script as shown in the below code and screenshot.
package StepDefinition;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
WebDriver driver;
Browser launched.
Here we update the feature file with 'Scenario Outline' and 'examples' syntax.
Examples:
|username |password |
|User1 |password1 |
|User2 |password2 |
|User3 |password3 |
Here we update the methods as to pass the parameters, updated script shown below:
package StepDefinition;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
WebDriver driver;
Below screen shows the successful execution of the script and time taken by each set of data.
Browser launched.
Conclusion.
Cucumber is a very popular BDD tool. It is easy to read and can be understood by all
stakeholders including technical and non-technical person.
1. Create feature file in which define the feature and scenarios step by step using
Gherkin language.
2. Create Testrunner file. In this file, we integrated Cucumber with selenium. We execute
this script.
3. Creat Step definition, the actual selenium script defined under this package.
Prev
Report a Bug
Next
In this tutorial, we will see how to identify the following form elements Radio Button Check
Box...
Read more
SELENIUM
Intellij is an IDE that helps you to write better and faster code. Intellij can be used in the...
Read more
SELENIUM
The test report is the most important feature of the Selenium framework. In Selenium,
Testng..