ATAL FDP - Cucumber
ATAL FDP - Cucumber
ATAL FDP
Development Frameworks
TDD BDD
• Development Centric approach • Extension of TDD, Works at higher level of
• Write TCs before code is abstraction.
written(author-Developer) • Always ask have we covered all possible
• Test first Approach(Focus: Is my code scenarios.
working correctly?) • Test first Approach(authors-Dev/QA/PO)
• More Collaboration
1.Write 2.(Make the
TCs, code works) 1.Write 2.(Write
Test Fails Test passed TCs, Features/Scenarios)
Test Fails Test passed
3.Refactor
3.Refactor
ATDD
• Higher level of abstraction as compared to BDD/TDD
• Focus on high level requirements.Authors(BA/PO/Dev/QA)
customer
User Stories
Demo(PO/BA)
AT(PO/BA)
BDD
Develop Code
TDD
Refactor
UT to fail
CUCUMBER
Coding Testing
What are BDD and ATDD? Test Last Development
Testing Coding
TDD
BDD Example: Login, Register ,(withdraw and deposit w.r.t ATM software). USER Stories
To make the stories to have a consistent structure and model ,Cucumber uses Gherkin language :
Cucumber is an open source tool for test automation
Feature: Check Login Functionality
Scenario
Given(Prerequisite): User is on login screen
When(Action): User enters valid username and password
And(Some more Action): Clicks on login button
Then(Expected) : User is navigated to home page
Advantages:
• Helps to breakdown story into atomic actions
• Keeps the format consistent
• Makes it easier to understand for all
• Helps in automating the scenario
• Tools for BDD
Cucumber(java/Ruby Framework),SpecFlow(.NET framework)
JBehave(java)
Behat(Php)
Behave(Python)
Lettuce(Python)
Easy B
Fitness
TestLeft
JDave
Steps:
• 1.Create maven project in Eclipse(Open Eclipse,Click ->File->New->
Other->(In Wizards type :maven ->Select maven project)->Next-
>Select create simple project->Next->In Artifact(Write in GroupId-
anyname like cucumber_atal,In artifactId- cucumber_atal->click Finish
Or add maven-
archetype-
quickstart
2.Add maven dependencies(cucumber
java+Cucumber Junit+Junit+Selenium java)
• Google- maven central->select maven repository->in search
type(cucumber java)->click cucumber JVM-java of io.cucumber
Select latest version-6.10.4, click
3.Click and Open pom.xml ,
add tag;<dependencies></dependencies>
4.Click on cucumber java dependency (or select the
dependency)and copy between
;<dependencies></dependencies> in pom.xml ,save(ctrl+s)
Now you will find Maven dependencies
(for indentation-select the contents of pom.xml by Ctrl A then Ctrl I)
5.Create a Folder Features_atal under src/test/resources
• Write click on - src/test/resources->New->Folder->Type folder name(Features_atal)->Finish
6.Under Features_atal Folder create a new feature file-
login.feature(right click (Features_atal) ->New->File->In File name
type -login.feature->Finish
Now ,go to help ->eclipse marketplace->in Find , type cucumber(you will
see cucumber eclipse plugin)->click install->restart eclipse,Now you will
see icon of cucumber in login.feature (sample feature file)
7.Delete the contents of feature file and add new contents. Then right
click on contents->Run As->Run Configuration
After executing the Feature file you will get :
Right Click(src/test/java)->New->Package->(Give any name :com.Demo)->RightClick on
Com.Demo->New->Class-> Name(StepDefLogin.java)->Finish->copy the contents from
console to StepDefLogin.java and remove
throw new io.cucumber.java.PendingException();and replace with
•System.out.println() /short cut ,type syso+ctrl+space bar
Open StepDefLogin.java and type the Step Definition Functions as
shown and save (Hover mouse on annotations to import packages)
Open pom.xml and copy the cucumber-testNG dependency from maven
repository
right click(com.Demo)->New->class->(give name:TestRunner)->Finish-
>now open TestRunner.java and add @cucumberOptions()as shown
and add public class TestRunner extends AbstractTestNGCucumberTests {}
RightClick(testRunner.java)->Run As->TestNG Test->
Note:We can use Junit Also by adding the required plugins
1)Feature File
2)StepDefine.java
3)TestRunner.java
Right Click TestRunner.java->Run As Junit
Html,json and xml reports can be generated
Tags can also be added like =@smoketest
Cucumber+ Selenium(Steps)
1)Create Feature file-→Right Click->Feature-New->File->(SeleniumTest.feature)-
>Finish->delete the contents
Delete the contents and create new feature file as shown :
Go to StepDef package and create a java class-
SeleniumSteps.java
Run the Feature file(seleniumTest.feature)(Run As-> Cucumber
feature or Run Configuration) and copy the missing steps(methods)
into SeleniumSteps.java
SeleniumSteps.java with step definitions
Hover mouse on @Given (click on import io.cucumber.java.Given),Now
replace with import io.cucumber.java.en.*;Also replace When with And
wherever And is not found.(refer feature file and verify)
Delete contents of methods and so that we
can add new required functions
New print Methods added
(System.out.println)
Now Run the feature file to verify (features
are connected to stepdefinitions i.e mapping)
Download chrome driver from google (version of your current chrome browser
should match with the one you download)
to check browser version(click on three dots on top right hand side of the browser
then settings then help the about chrome browser).(Download chromedriver_win32)
• Create a new folder (Drivers) under src/test/resources and copy/drag
the chromedrive.exe
Write the code
• public class SeleniumSteps {
• WebDriver driver=null;
• @Given("Browser is open")
• public void browser_is_open() {
• System.out.println("Inside this step browser is open");
• System.setProperty("webdriver.chrome.driver","C:/Users/HP/eclipse-
workspace/CTNG/src/test/resources/Drivers/chromedriver.exe");
• driver= new ChromeDriver();
• driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
• driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
• driver.manage().window().maximize();
• }
Note-When you copy the path of the driver the double backwards slash are to be replaced
with single forward slash.
If the page has loaded and due to slow network some of the page objects are not uploaded
than if u take action on those objects ,it will result failure so we put some wait time.
pageLoad time- we can increase the page load time if the page loading takes more time in
order to avoid failures
Cont.