Cucumber Presentation

Download as pdf or txt
Download as pdf or txt
You are on page 1of 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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy