Page Object Model (POM) in cucumber with selenium, testng, maven | end to end example
Go through this blog for the detailed explanation
https://jasper-bi-suite.blogspot.com/...
POM - Page Object Model
It is a design pattern / frame work in selenium.
Using this pattern, we can create object repository for web elements in the UI.
We create a POM class file(Example: HRMLoginPOM.java) for each web page such that it consists of all web elements present in the page.
Testing scripts(Example: HRMLogin.java) uses the the elements from POM class file
Download and install cucumber plug-in in Eclipse from Market Place
Download and install TestNG plug-in in Eclipse from Market Place
Create a new Maven project (say : CucucumberTestNGSeleniumMavenPageObjectModel)
Add the following dependencies in pom.xml
cucumber-java 7.1.0
cucumber-testng 7.1.0
selenium-java 4.3.0
testng 7.1.0
Add the following plug-ins in pom.xml
maven-surefire-plugin 3.0.0-M7
maven-compiler-plugin 3.10.1
Create feature files in
folder: src/test/resources
HRMLogin.feature
Directory.feature
Write code for cucumber runner
folder : src/test/java
package : com.sadakar.testng.runner
class : RunCucumberTest.java
Write code for driver, hooks
folder : src/test/java
package: com.sadakar.common
BasePage.java for driver
Hooks.java for Before and After cucumber hooks
Write code for page objects
folder : src/test/java
package: com.sadakar.pageobjects
HRMLoginPOM.java for HRMLogin page web elements, for instance locating username, password and login button
DirectoryPOM.java for Directory page web element, for instance view directory tab link, search button
Write code for step definitions or say glue code
HRMLogin.java
Directory.java
Run the scenarios from mvn command line
mvn test -Dcucumber.filter.tags="@LoginValidCredentials or @DirectoryTabIsSearchButtonDisplayed"
Run the scenarios from TestNG in elcipse and report analysis
test-output* emailable-report.html
Run the project using testng.xml
Analysis of cucumber report
target * cucumber-reports * cucumberreport.html
Write java, selenium, glue(step definitions), cucumber testng runner class in src/test/java folder
BasePage class for driver
Hooks class for cucumber Before and After hooks.
Step Definition Or Glue Code for the feature files
Cucumber & TestNG runner class, RunCucumberTest.java
Create testng.xml for the project and configure it in pom.xml
Run Tests from TestNG Tests
Run Tests from testng.xml
Run Tests from command line
Test results analysis from Cucumber report
Test results analysis from TestNG report
コメント