Pages

Cucumber Cheatsheet

              cucumber cheatsheetCheatsheet
What is BDD?
  • Behavior-driven development (BDD) is a software development methodology in which an application is specified and designed by describing how its behavior should appear to an outside observer.
  • In BDD, tests were written in plain descriptive English type grammar.
What is Cucumber?
  • Cucumber is designed to help bridges between technical and non-technical members of s/w team with BDD
  • Cucumber helps business stakeholders to get involved in writing acceptance tests and then dev team would work/code to pass acceptance tests
  • It will define application behavior in plain meaningful English text using a simple grammar defined by a language called Gherkin
  • Cucumber scenarios can easily understand by anyone regardless of technical knowledge.(Product owners,Business analyst,users,testers,non-testers, UX designers etc.,.)

 LAYERS OF CUCUMBER ?


Layers of cucumber
What is Feature File ?

In every project, we will write our scenarios. So in cucumber, we will write our scenarios/tests in feature file (sample.feature) using Gherkin keywords. (will discuss more gherkin in next posts) A feature file will be created using .feature extension to file.

Step Definitions:
Where we will write our code (code is depended on library what we use like java/ruby/python etc.,.)
We define each and every step by writing code.

Support Library:
Cucumber framework can design not only using java library and many other like ruby,perl,jruby,scala etc.

What is Gherkin ? 
Gherkin is simple and structured language which uses regular plain English language to describe the scenarios and requirements.
Gherkin contains set of keywords which are used to write our automated tests.

Feature
Given
When
And
Then
But
Background
Scenario Outline Examples
These are main keywords we will use while writing our scenarios.Will see in next posts how these keywords will be used in feature file.
Cucumber JUnit runner class
In order to execute any scenario in cucumber, we have use cucumber uses JUnit annotation @RunWith(). As cucumber uses JUnit we have to create runner class(say Runner.java).In runner class we have to specify @RunWith() annotation, then which tells JUnit what is the runner class.
@RunWith(Cucumber.class)
@CucumberOptions(
        features = {"src/main/java/features/sample.feature"},
        glue = {"stepdefinitions"},
        plugin = {"pretty", "json:target/cucumber-reports.json", "html:src/output/report.html",
                "junit:target/cucumber-reports/cucumber.xml"},
        tags = "@smoke",
        monochrome = false)
public class Runner {
}
Cucumber Hooks File
@Before Annotation:
  • The code we write in @Before annotation will be executed before the execution of all scenarios.
  • In @Before annotation, we write code for setup the environment like Web driver setup, launch browser, browser maximize, open the DB connections, etc.,.
  • Get the currently executing scenario name
  • We can use also use Hooks(@Before,@After) in any class.
@After Annotation:
  • The code we write in @After annotation will be executed after the execution of all scenarios.
  • In @After annotation, we write code for the teardown of environment like close the driver, quit the driver, close DB connections, taking screenshots, taking test reports, etc.,.
  • Get the status of the currently executed scenario.
  • We can use also use Hooks(@Before,@After) in any class.
monochrome in Cucumber?

monochrome:

In cucumber, monochrome is used to display console output in color format or not.
It will take 2 values:
False: 
Its default value is false.
It will print console output with color(s).
True:
It will print console output without color(s).
 cucumber Tags?

In cucumber, we can execute only specific scenarios by using cucumber tags.

 @smoke
  Scenario: This is Smoke Scenario
    Given I am in Smoke Scenario
Cucumber Tags?
In cucumber, we can execute only specific scenarios by using cucumber tags.
cucumber @tags


No comments:

Post a Comment

Please comment below to feedback or ask questions.