Selenium Cucumber BDD FrameWork with Java
Index
Framework Intoduction
POM Structure
BDD Introduction
Hooks
Tags
Page Factory
Background
Thanks
Framework Introduction
What Is Test Automation Frameworks?
- Test automation frameworks are a set of rules and corresponding tools that are used for building test cases. It is designed to help engineering functions work more efficiently.
- The general rules for automation frameworks include coding standards that you can avoid manually entering, test data handling techniques and benefits, accessible storage for the derived test data results, object repositories, and additional information that might be utilized to run the tests in a suitable manner.
Advantages of using Test Automation Frameworks
Reusability of Code.
Low Cost.
Minimal Manual Interference.
Improved Efficiency.
BDD Introduction
What Is BDD?
- BDD is an extension of Test Driven Development TDD.
- like TDD, in BDD we write test first and then add application code.
- TLD (Test Last Development): Coding --> Test Creation--> Test Execution.
- TDD (Test Driven Development): Test Creation --> Test Execution (will fail) --> Coding to passs TC --> Refactor test to remove redundancies.
- Another Diff. is tests are explained as a behaviour of the application and are more user-focused.
What Is BDD?
- For this BDD user stories for every feature to be test. E.g.Login.feature.
- BDD uses human-readable description of the user requirements as the test.
- written in shared language i.e. Gherkin.
- which improves communication between tech and non-tech teams and stakeholders.
Key Feature Of BDD
Keeps the format consistent.
This hepls to breakdown story into atomic actions.
Helps in automating the scenario.
makes it easier to understand for all.
Tools For BDD
Page Object Module Structure (POM)
POM Structure
What Is POM?
- Design pattern to create object repository.
- A class is created for each page to identify web element of that page.
- Also contains methods to do action on the object.
- separates test object and test scripts.
Advantages Of POM
Usability
Maintainability
- Makes Code maintainable.
- Changes and updates are easier.
Reliable
Readability
- improves Overall quanlity and efficiency.
- Improve readability.
- provide a kind of object
documentation at a single place.
Page Factory
What Is Page Factory?
- A Simple and easier implementation of POM in selenium.
- selenium's inbuilt and optimized page object Model Concept.
- As POM, has separation of object and tests.
- uses annotations @Findby to find webelements.
- @FindBy can use id, name css,xpath etc.
- Uses method initElements to initialize web elements.
- on calling initElement menthod all object on that pages gets intialized.
Syntax:public amazonpage_PF(WebDriver driver) { this.driver=driver; PageFactory.initElements(new AjaxElementLocatorFactory(driver,30), this);
Useful Tips For Page Factory
If you are working with an basic website and you know that
locators of element will never going to changes then you can use
@CacheLookup : Once it located locator of element. it will store it into memory
and use from memory instead of searching it over and over again whenever
calling it from any method.
Note: This works for basic web application, but not recommended if you
have Ajax application where DOM changes on user actions.
Useful Tips - Page Factory
- In Ajax application to handle loading time for element and to avoid
'No Element Exception', we can use AjaxElementLocatorFactory Class :timeout for a webelement can be assigned to the object page class with help of AjaxElementLocatorFactory.Syntax:PageFactory.initElements(new AjaxElementLocatorFactory(driver,30), this);
Useful Tips - Page Factory
- With PageFactory, You can also locate a list of elments
Syntax@FindBy(PartialLinkText="Taufique")List<WebElement>mylinks;
- another ways to use @Findby
Syntax @Findby(how = How.ID,using ="name")WebElement abc;
Tags
What Are Tags In Cucumber?
- Features and Scenarios can be marked with Tags.
- Tags use @ symbol with some text e.g.@smokeTest.
- In the test runner we can run specfic tags.
- A feature or scenario can have multiple tags.
- Can run with single OR multiple Tags.
- Can run with Combination of Tags or using AND,OR Conditons.
- Can Skip senarios having specfic Tag.
- E.g. @smoke @regression @important.
Feature:verify Login
Useful Tips- Tags Inheritance
- Tags are inherited by child elements.
- Tags that are placed above a Feature will be inherited by scenario,
scenario Outline or Examples.
- Tags that are places above a scenario outline will be inherited by examples.
Useful Tips- Execution With Tags
- Create and keep ready mulitple TestRunner classes with different combination of Tags OR
- Create Commands with Tags combination as required to be run from commands line
systax:
mvn test -Dcucumber.filter.tags="@smoke and @regression"
Hooks
What Are Hooks?
- Block of code that runs before OR after each scenario.
- Hooks in cucumber are like listeners in TestNG.
- Can define hooks by using annotations @Before @After.
Type's of Hooks
Scenario Hooks - Runs before and after each scenario.
Step Hooks - Runs before and after each step.
Conditinal Hooks - Hooks asscociated with tags for conditional execution. E.g. @After("@smoketest")
Type's Of Hooks
Scenario Hooks - Runs before and after each scenario.
Step Hooks - Runs before and after each step.
Conditinal Hooks - Hooks asscociated with tags for conditional execution. E.g. @After("@smoketest")
Why To Use Hooks?
- To manage the setup and teardown.
- To avoid rewriting the common setup or teardown actions.
- Allow better management of code workflow.
When To Use Hooks?
- Whenever you have some common setup and teardown
actions to be executed before each scenario.
Useful Tips-Hooks
We can use multiple Before and After hooks and also assign order of execution @Before(order=0) @After(order=0)@Before(order=1) @After(order=1)
- Whatever happens in hooks is invisible to people who only read the features.
- only use hooks for low level logic such as starting a browser or deleting data from a database.
- You should consider using a background as a more explicit alertnative,especially if the setup should be readable by non-technical people
- You can keep your function name anything.
Useful Tips-Hooks
- Hooks will get executed even if the test fails
- Need to import the below library
import io.cucumber.java.Before;import io.cucumber.java.After;
Background
What is Background?
- A Step or a group of step that are common to all scenarios in a feature.
- Is defined once in the feature.
- Runs before every scenario of the feature.
Why to use Background?
- To avoid repeating the common steps in every scenario.
- For better readability and maintenance.
- unlike hooks, background is visible to the readers of feature file.
When to use background?
- Whenever there are common repeating steps in a feature.
- whenever you want the common steps to be visible to the readers.
Useful Tips- Background
- You can only have one set of background steps per feature.
- if you need different background steps for different scenarios,
considering breaking up your set of scenarios into more features.
- use background so that all stakeholders can understand the scenario.
- Keep background section short.
Thanks
BBD UI Automation Framework
MOHAMMED TAUFIQUE SHAIKH
Created on September 19, 2021
Start designing with a free template
Discover more than 1500 professional designs like these:
View
Mobile App Dossier
View
Color Shapes Dossier
View
Notes Dossier
View
Futuristic Tech Dossier
View
Crowdfunding Campaign
View
Company Dossier
View
Economy Dossier
Explore all templates
Transcript
Selenium Cucumber BDD FrameWork with Java
Index
Framework Intoduction
POM Structure
BDD Introduction
Hooks
Tags
Page Factory
Background
Thanks
Framework Introduction
What Is Test Automation Frameworks?
Advantages of using Test Automation Frameworks
Reusability of Code.
Low Cost.
Minimal Manual Interference.
Improved Efficiency.
BDD Introduction
What Is BDD?
What Is BDD?
Key Feature Of BDD
Keeps the format consistent.
This hepls to breakdown story into atomic actions.
Helps in automating the scenario.
makes it easier to understand for all.
Tools For BDD
Page Object Module Structure (POM)
POM Structure
What Is POM?
Advantages Of POM
Usability
Maintainability
Reliable
Readability
- Improve readability.
- provide a kind of object
documentation at a single place.Page Factory
What Is Page Factory?
- A Simple and easier implementation of POM in selenium.
- selenium's inbuilt and optimized page object Model Concept.
- As POM, has separation of object and tests.
- uses annotations @Findby to find webelements.
- @FindBy can use id, name css,xpath etc.
- Uses method initElements to initialize web elements.
- on calling initElement menthod all object on that pages gets intialized.
Syntax:public amazonpage_PF(WebDriver driver) { this.driver=driver; PageFactory.initElements(new AjaxElementLocatorFactory(driver,30), this);Useful Tips For Page Factory
- @CacheLookup:
If you are working with an basic website and you know that locators of element will never going to changes then you can use @CacheLookup : Once it located locator of element. it will store it into memory and use from memory instead of searching it over and over again whenever calling it from any method. Note: This works for basic web application, but not recommended if you have Ajax application where DOM changes on user actions.Useful Tips - Page Factory
- In Ajax application to handle loading time for element and to avoid
'No Element Exception', we can use AjaxElementLocatorFactory Class :timeout for a webelement can be assigned to the object page class with help of AjaxElementLocatorFactory.Syntax:PageFactory.initElements(new AjaxElementLocatorFactory(driver,30), this);Useful Tips - Page Factory
- With PageFactory, You can also locate a list of elments
Syntax@FindBy(PartialLinkText="Taufique")List<WebElement>mylinks;- another ways to use @Findby
Syntax @Findby(how = How.ID,using ="name")WebElement abc;Tags
What Are Tags In Cucumber?
- Features and Scenarios can be marked with Tags.
- Tags use @ symbol with some text e.g.@smokeTest.
- In the test runner we can run specfic tags.
- A feature or scenario can have multiple tags.
- Can run with single OR multiple Tags.
- Can run with Combination of Tags or using AND,OR Conditons.
- Can Skip senarios having specfic Tag.
- E.g. @smoke @regression @important.
Feature:verify LoginUseful Tips- Tags Inheritance
- Tags are inherited by child elements.
- Tags that are placed above a Feature will be inherited by scenario,
scenario Outline or Examples.Useful Tips- Execution With Tags
- Create and keep ready mulitple TestRunner classes with different combination of Tags OR
- Create Commands with Tags combination as required to be run from commands line
systax: mvn test -Dcucumber.filter.tags="@smoke and @regression"Hooks
What Are Hooks?
Type's of Hooks
Scenario Hooks - Runs before and after each scenario.
Step Hooks - Runs before and after each step.
Conditinal Hooks - Hooks asscociated with tags for conditional execution. E.g. @After("@smoketest")
Type's Of Hooks
Scenario Hooks - Runs before and after each scenario.
Step Hooks - Runs before and after each step.
Conditinal Hooks - Hooks asscociated with tags for conditional execution. E.g. @After("@smoketest")
Why To Use Hooks?
When To Use Hooks?
- Whenever you have some common setup and teardown
actions to be executed before each scenario.Useful Tips-Hooks
- Odering Hooks
We can use multiple Before and After hooks and also assign order of execution @Before(order=0) @After(order=0)@Before(order=1) @After(order=1)Useful Tips-Hooks
- Hooks will get executed even if the test fails
- Need to import the below library
import io.cucumber.java.Before;import io.cucumber.java.After;Background
What is Background?
Why to use Background?
When to use background?
Useful Tips- Background
- You can only have one set of background steps per feature.
- if you need different background steps for different scenarios,
considering breaking up your set of scenarios into more features.Thanks