0% found this document useful (0 votes)
453 views15 pages

TestNG, POM, POF - Overview

The document provides an introduction to Maven, TestNG, POM and POF. It discusses Maven as a build automation tool used for Java projects that utilizes a POM file. It then describes TestNG as an automated testing framework that can be configured with annotations and XML and supports features like parameters, data providers, and listeners. It also introduces the Page Object Model (POM) pattern for separating test steps from page objects and the Page Object Factory (POF) for initializing page objects without finding elements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
453 views15 pages

TestNG, POM, POF - Overview

The document provides an introduction to Maven, TestNG, POM and POF. It discusses Maven as a build automation tool used for Java projects that utilizes a POM file. It then describes TestNG as an automated testing framework that can be configured with annotations and XML and supports features like parameters, data providers, and listeners. It also introduces the Page Object Model (POM) pattern for separating test steps from page objects and the Page Object Factory (POF) for initializing page objects without finding elements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Maven, TestNG, POM and POF

- An Introduction

Uma Shankar
Agenda

 Maven Overview
 TestNG Overview
 TestNG Annotations
 TestNG XML
 TestNG Parameters and Data Provider
 TestNG Listeners
 TestNG Parallel Execution
Maven Overview

 Maven is a build automation tool used primarily for Java projects


 A POM XML file is used to define the project being built,
dependencies required, build order, directories, configurations
and required plug-ins
 Maven downloads Java libraries and plug-ins defined in POM
from one or more repositories such as the Maven 2 Central
Repository and stores them in a local cache.
(C:/Users/{username}/.m2)
TestNG Overview
 TestNg was created by Cedric Beust in 2004
 It was created to make end-to-end testing easier
 TestNG is a testing framework more powerful and easier to use than
Junit/Nunit.
 It is an open-source automated testing framework/library.
 It is designed to cover all categories of tests: unit, functional, end-to-end,
integration, etc.
 It can be configured with annotations, which makes it easier to use.
 Flexible runtime configuration (XML, not Java).
 Introduced the notion of “test groups” determine which tests to run
dynamically.
TestNG Annotations

 @BeforeSuite: Run before all tests in this suite have run


 @AfterSuite: Run after all tests in this suite have run
 @BeforeTest: Run before any test method belonging to the class
 @AfterTest: Run after all the test methods belonging to the class
 @BeforeClass: Run before any test method belonging to the class
 @AfterClass: Run after all the test methods belonging to the class
 @BeforeMethod: Run before each test method will run
 @AfterMethod: Run after each test method will run
 @BeforeGroups: Run before any test method belonging to the group
 @AfterGroups: Run after all test methods belonging to the group
TestNG XML

 The TestNG XML contains all the test methods, classes, packages
that need to be executed
 The TestNG XML can be used to specify which configurations
that need to be created
 We can configure which groups should be run (include-groups)
and which groups should not be run (exclude-groups)
 Thread Count, failure policy, parallel tests etc., can be configured
Sample TestNG XML

<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >


<suite name="TestNgDemo" parallel="classes">
<groups>
<run>
<include name="dataProviderTests"/>
</run>
</groups>
<listeners>
<listener class-name="Listeners.TestListener"></listener>
</listeners>
<test name="TestNgTests">
<classes>
<class name="DemoTest1"></class>
<class name="DemoTest2"></class>
<class name="DemoTest3"></class>
</classes>
</test>
</suite>
TestNG Parameters and Data Provider

Parameterization
 One of the important features of TestNG is parameterization.
 This feature allows users to pass parameters to tests as arguments.
 There are two ways through which we can pass parameter values to
TestNG tests.
Types of parameterization:
 Using @Parameters
 Using @DataProvider
TestNG Listeners

There are several interfaces that allow you to modify TestNG's behavior.
These interfaces are called "TestNG Listeners". Here are a few listeners:
 ITestListener
 ISuiteListener
 IAnnotationTransformer
 IAnnotationTransformer2
 IHookable
 IInvokedMethodListener
 IMethodInterceptor
 IReporter
TestNG Listeners - ITestListener

ITestListener: The Listener makes the call before and after the Test
not the Suite. It has seven methods in it.
 onTestSuccess: Invoked after any test is successful
 onTestFailure: Invoked after any test fails
 onTestFailedButWithinSuccessPercentage: Invoked after test
method fails but has been annotated with successPercentage
 onTestSkipped(ITestResult result): Invoked each time a test is
skipped
POM – Page Object Model

Page Object Model (POM) is a design pattern widely used by


Selenium Testers.
 Each Page will have Page Object class.
 The Page Object class will act as an object repository and will
hold the required web element objects
 This method will contain methods which operate on these web
elements
 This is used to separate test steps from page operations
 It promotes reusability of Page Elements
POF – Page Object Factory

Page Object Factory (POF) is a Factory class used to initialize and


instantiate Page Objects
 It helps initialize Page class elements without using
“FindElement(s).”
 With Page Factory, we use annotations @FindBy to find the Web
Element
 We use initElements method to initialize web elements/Page
objects
 @FindBy can accept tagName, partialLinkText, name, linkText,
id, css, className, xpath as attributes
Questions
References
 Maven - https://mvnrepository.com/
 Maven download - https://maven.apache.org/download.cgi
 TestNG - http://testng.org/doc/index.html
 TestNG Doc - http://testng.org/doc/documentation-main.html
 Selenium and TestNG - http://testng.org/doc/selenium.html
 TestNg Maven - https://mvnrepository.com/artifact/org.testng/testng
 Selenium Maven -
https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java
Thank you!

You might also like