0% found this document useful (0 votes)
16 views5 pages

Cucumber

Cucumber is an automation testing tool that supports behavior driven development. It allows writing test scenarios in a language called Gherkin. Tests are defined using keywords and scenarios are executed to generate reports. Feature files define scenarios using Gherkin, Java classes implement scenario steps, and a runner class is used to execute the tests.

Uploaded by

abuthurab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views5 pages

Cucumber

Cucumber is an automation testing tool that supports behavior driven development. It allows writing test scenarios in a language called Gherkin. Tests are defined using keywords and scenarios are executed to generate reports. Feature files define scenarios using Gherkin, Java classes implement scenario steps, and a runner class is used to execute the tests.

Uploaded by

abuthurab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

What is Cucumber?

How to
use it?
Cucumber testing is an automation tool that supports the Behavior Driven Development
(BDD) approach.
Cucumber allows you to write test scenarios in a understandable language called
Gherkin. Gherkin enables you to define test scenarios with keywords such as Feature,
Scenario, Given, When, Then, And, But.
Cucumber can automatically execute these scenarios and report the results also can be
used with various programming languages like Ruby, Python, Java, Javascript, etc.

Feature File:
To use Cucumber testing, you first need to define the feature you want to test as a
“Feature:”

💡 For example, something like “Login to the Amazon site and search for a
product.”

Next, you create scenarios to test this feature.

💡 For example, scenarios like “User logs in with email and password and
searches for a product.”

Then, you need to describe each step of these scenarios using keywords like Given,
When, Then, And, But.

What is Cucumber? How to use it? 1


💡 For instance, “Given Amazon page is loaded, When User enters email and
password and logs in, Then Home page is displayed, And User searches for a
product, Then Search results are displayed.”

This way, you can easily write and read your test scenarios.

Java Class Implementing Steps:


Next, you need to create a Java class that performs the steps in this feature file. You
can create this class under the “Steps” package.

💡 For example, you can create a Java class like the one below:

What is Cucumber? How to use it? 2


What is Cucumber? How to use it? 3
In this Java class, we’ve labeled the steps from the feature file using annotations
(@Given, @When, @And, @Then, ) matching the names. Additionally, we extended
this class from the BaseStep class created under the “Base” package.
This class contains methods using Selenium WebDriver to perform operations like
opening a web page, clicking elements, entering data, and checking elements. We can
use these methods by calling them from the BaseStep class.

Test Runner Class:


Finally, you need to create a Runner class to run your test scenarios. You can create
this class under the “Runner” package.

💡 For example, you can create a Runner class like the one below:

In this Runner class, we specified where the feature files and Java classes are located.
Additionally, using the Cucumber library, we configured the necessary settings to run
our test scenario.

The advantages of using Cucumber testing:

# You can write your test scenarios in a clear and natural language, Gherkin. This
allows you to share and get approval for your test scenarios from people who may not

What is Cucumber? How to use it? 4


know how to code.

# You can separate your test scenarios and code. This means that when you need to
change your test scenarios, you don’t have to change your code. Similarly, when you
need to change your code, you don’t have to change your test scenarios.
# You can reuse your test scenarios and code. This eliminates the need to repeatedly
write similar test scenarios or code.

I hope this helps you better understand and use Cucumber. See you!

What is Cucumber? How to use it? 5

You might also like