0% found this document useful (0 votes)
118 views10 pages

Cucumber Presentation

Cucumber is a tool that executes plain-text functional descriptions as automated tests. It uses a language called Gherkin to describe software behavior in a business-readable way without detailing implementation. Gherkin serves several purposes, including living documentation, executable specifications, and automated tests. Cucumber tests are written by authoring feature files using the Gherkin syntax, which are then executed using Cucumber and linked to step definition files that contain the test code.

Uploaded by

Abhishek Gaur
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)
118 views10 pages

Cucumber Presentation

Cucumber is a tool that executes plain-text functional descriptions as automated tests. It uses a language called Gherkin to describe software behavior in a business-readable way without detailing implementation. Gherkin serves several purposes, including living documentation, executable specifications, and automated tests. Cucumber tests are written by authoring feature files using the Gherkin syntax, which are then executed using Cucumber and linked to step definition files that contain the test code.

Uploaded by

Abhishek Gaur
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/ 10

What is Cucumber?

Cucumber is a tool that executes plain-text functional


descriptions as automated tests.
Here is an example:
How Cucumber works: Gherkin

• Gherkin is the language that Cucumber understands.

• It is a Business Readable, Domain Specific Language that lets you


describe software’s behaviour without detailing how that behaviour is
implemented.

• So everyone can write Gherkin.

• Gherkin serves three purposes – Living documentation, executable


specifications and automated tests. Also,The fourth is a bonus feature
– when it yells in red it’s talking to you, telling you what code you
should write.
Gherkin Example
Feature: Some descriptive text of what is desired

Scenario: Some determinable business situation

Given some precondition


And some other precondition
When some action by the actor
And some other action
And yet another action
Then some testable outcome is achieved
And something else we can check happens too

Scenario: A different situation



Writing Better Gherkin
Describe Behaviour:

Your scenarios should describe the intended behaviour of the system, not the
implementation. In other words, it should describe what, not how. Like :

We should write :

When "Bob" logs in

Instead of :

Given I visit "/login"

When I enter "Bob" in the "user name" field

And I enter "tester" in the "password" field

And I press the "login" button

Then I should see the "welcome" page


Running test
cases
Cucumber Testing Stack
Cucumber Execution Flow
Setup Cucumber-Js and Test a feature

1. Install Node.js and npm


2. Create a working directory
3. Go to your project directory and run :

npm install --save-dev cucumber (to install it locally)


Or , npm install -g cucumber (to install it globally)

4. Before writing first feature, check if a folder with name “node_modules” has been
created in project root directory.

5. Create first feature file with Gherkin syntax and ‘.feature’ as an extension.
The feature file should be in ‘features’ folder inside project root directory.

6. Execute feature file using below command from root directory :


./node_modules/.bin/cucumber.js

7. An output with lot of warnings of unidentified steps will be displayed like :


Contd: Setup Cucumber-Js and Test a feature

8. Create Step defs :

- Create step_definitions folder inside features folder.


- ‘step_definitions’ is the default directory’ . This is the directory that Cucumber.js is
looking by default to find JavaScript files with the same names as features have.
- Create a js file with same name as feature file (and with extesions .js instead of
.feature)

9. Execute again (Repeat step 6). This time , all the tests should be pending because
we’ve not added any actions inside step definitions.
10. Add the actual application behaviour code inside the step_definitions.

11. Cucumber.js gives you the possibility of adding JavaScript support files that can be
loaded before your tests run. By default, Cucumber.js is looking and loading these
JavaScript files that are located inside a folder with name support and this folder
should exist under the features directory.

You might also like