Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Cucumber BDD Framework
Anne Quinkenstein
Anne Quinkenstein

Posted on • Edited on

     

Cucumber BDD Framework

Basics of Behaviour Driver Development

Often there is a Problem of Secifying the needs of the Business, communicate it to Development and Testing. There are mismatches between their perceptions.

-> write a Requirement in a formal standard/ template in a language which is a common words. Dev, QA and Business can express the Requriment in that language.

Image description

Scenario template

In order to (achieve something/ Business Outcome)
as a (user)
i want to do (this).

Example:
In oder to pay credit card payment
as a NetBanking sole owner who has credit section access
i want to navigate to credit card section, enter amount and process my payment.

Dev uses this scenario to develop & tester uses it to write testcases(positiv & negativ /Payment is not happening)

Testcases

Given (what you need to have to perform an action)
When (performs action)
Then (desired outcome for the user)

Example:
Given: An account with sero balance
When: i navigate to Credit card Payment Section and click to submit by giving amount
Then: it should show a warning - funds

Given : An account with sufficent balance who does not have credit card
When: I navigate to Credit card Payment Section and amount
Then :You don't have to access /warning message

Business values are easy detectable. (in scenario)
Testcases are countable for each scenario.
Using a standard template for both manual and automation testing.

Cucumber Framework Architecture & Core Functionalities

Setup

Install Cucmber Plugin into eclipse from eclipse market place
Cucumber expects a Selenium scaletton, optains by Maven
Open a Maven Project with quickstart template (maven-architect-template)
Artifactid and GroupId(Projectname)
Maven: libaries in pom.xml: Cucumber JVM Java && Cucumber JVM JUnit

Cucmber Core Functionalities

Feature File - "When i click on button"
StepDefinition File - mapped Code to click button
JUnit TestRunner - triggers all Testcase (related Documents)

Feature File

under src/test/java create Package features
inside create "file" - zB Login.feature (provide .feature)

Feature:ApplicationLoginScenario:HomepagedefaultloginGivenUserisonlandingpageWhenUserislogginginwithusernameandpasswordThenhomepageispopulatedAndallinfosaboutyoubillsisdisplayed
Enter fullscreen modeExit fullscreen mode

AddOn in Eclipse to highlight the cucumer Syntax: Natural 0.7...

Image description
-> no defition found (no code implementation yet)

StepDefinition File

under src/test/java create Package stepDefinition
under this, stepDefition Java Class

@Given("^User is on landing page$")publicvoiduser_is_on_landing_lage(){//navigate to the landing page }@When("^User is logging in with username and password$")publicvoiduser_is_logging_in(){...}@Then("^home page is populated$")publicvoidhome_page_is_populated(){...}@And("^all infos about you bills is displayed$")publicvoidall_infos_about_bills_are_displayed(){...}
Enter fullscreen modeExit fullscreen mode

create mapping stepDefinition
install Extention from Chrome Webstore: Tidy Gherkin app
Image description chrome://apps -> click, an window will open where you can paste your feature file and get the tidy cucumber java (or ...) code
(adjust package-/classname accourdingly to your code)

or just run tests and copy code from the konsole

jump from a featurefile-sentence -> to stepDefinition: Crtl + Click

Running Tests with TestRunner File (JUnit)

preferable under the same roof with the stepDefinitions Package src/test/java create Package cucumberOptions and in there class TestRunner
Annotations:

@RunWith(Cucumber.class)@CUcumberOptions(features="src/test/java/features",glue="stepDefinitions")
Enter fullscreen modeExit fullscreen mode

packages stepDefitions + cucumberOptions should have same parents

variables
feature file: put it in double quotes -Code: display it as regular expression in Annotation of function + passed as arguments in Method (so nr. of arguments should match nr. of parameters)

Parameterization

ScenarioOutline:Given...WhenUserenters<username>and<password>Then...Examples:|username|password||Elfriede|1234||else|2345|
Enter fullscreen modeExit fullscreen mode

Arrows < ... > makes Cucumber look in the Example Section for the values. it matches with the column names + takes the first row - second test will take second row
test will run the nr of rows which are filled

Running Tests with TestRunner File (TestNG, Maven)

get dependencies from Maven with searching for "Cucumber Testng lastet maven dependency" for pom.xml
Cucumber JVN: TestNG .... (cucumber java, cucumber Junit + cucumber Testng versions should be the same)

you need to extend the TestRunner class with AbstractTestNGCucumberTests as it is explainedhere

@RunWith(Cucumber.class)@CucumberOptions(features="src/test/java/features",glue="stepDefinitions")publicclassTestRunnerextendsAbstractTestNGCucumberTests{}
Enter fullscreen modeExit fullscreen mode

Top comments(1)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
swarnim_badholiya_071de73 profile image
Swarnim Badholiya
  • Joined

Great breakdown of the Cucumber BDD framework! Behavior-driven development (BDD) is a game-changer for improving collaboration between developers, testers, and business stakeholders. For those looking for more insights on implementing BDD effectively, check out our guide here:ajackus.com/hire-cucumber-testers

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Software Engineer (Java)
  • Location
    Berlin, Germany
  • Work
    Testautomation Engineer at Telecolumbus
  • Joined

More fromAnne Quinkenstein

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp