SlideShare una empresa de Scribd logo
1 de 25
TestNG
An Introduction
Abhishek Yadav
https://github.com/abhishekkyd/TestNG-examples
Agenda
 TestNG Overview
 TestNG Plugins for Eclipse
 TestNG Maven Dependency
 TestNG Annotations
 TestNG XML
 TestNG with Selenium
 TestNG Parameters and Data Provider
 TestNG Parallel Execution and Cross Browser Testing
TestNG Overview
 TestNG is a testing framework introducing some new functionality that make
it more powerful and easier to use.
 It is an open source automated testing framework hence no cost required for
implementation.
 It is designed to cover all categories of tests: unit, functional, end-to-end,
integration, etc.
TestNG Overview … continued
 Based on annotations (either Javadoc or JDK5)
 Flexible runtime configuration (XML, not Java)
 Introduces the notion of “test groups” to clearly separate static testing
(implementing the methods) from dynamic (which tests are run)
 Dependent test methods, parallel testing, load testing, partial failure
 Flexible plug-in API (report creation, even changing the core behavior)
 Created by Dr. Cédric Beust (of Google)
TestNG Plugins for Eclipse
 Eclipse
http://beust.com/eclipse
TestNG Maven Dependency
 Maven
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.10</version>
<scope>test</scope>
</dependency>
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
 @BeforeGroups: Run before any test method belonging to the group
 @AfterGroups: Run after all test methods belonging to the group
TestNG Annotations … continued
 @BeforeClass: Run before the first test method in the current class
 @AfterClass: Run after all the test methods in the current class
 @BeforeMethod: Run before each test method
 @AfterMethod: Run after each test method
 @Test: Identify a test method
 @DataProvider: Create parameters to pass to your test methods
 @Factory: Create your own test objects at runtime
TestNG Annotations … continued
 @Test: Identify a test method
groups: The groups this method belongs to
parameters: The parameters that will be passed to your test method, as they are
found in testng.xml
dependsOnGroups: The list of groups this test method depends on.
dependsOnMethods: The list of groups this test method depends on.
enabled: Use to ignore a test
timeOut: How long TestNG should wait before declaring your test method has
failed
TestNG Annotations … continued
@Test(enabled=true,
groups = { “sanity” },
timeOut = 10000)
public void test1() {
// …
}
TestNG Annotations … continued
@Test(enabled=true,
groups = { “regression” },
timeOut = 10000,
dependsOnGroups = { “sanity” })
public void test2() {
// …
}
TestNG Annotations … continued
@Test(enabled=true,
dependsOnMethod = { “test2” })
public void test3() {
// …
}
TestNG XML
 Where all the runtime information goes:
 The test methods, classes, packages
 Which groups should be run (include-groups)
 Which groups should not be run
(exclude-groups)
 Define additional groups (“groups of groups”)
 Whether the tests should be run in parallel
 Parameters
TestNG XML … continued
<test name=“Simple">
<groups>
<run>
<include name=“functest”/>
</run>
</groups>
<classes>
<class name=“SimpleTest” />
</classes>
</test>
TestNG with Selenium
TestNG Parameterized Test
Parameter Test
TestNG Parallel Execution
Firefox
Test1
Chrome
Test1
TestNG Listeners
There are many types of listeners available in TestNG for
example: IAnnotationTransformer, IAnnotationTransformer2, IConfigurable,
IConfigurationListener, IConfigurationListener2, IExecutionListener, IHookable,
IInvokedMethodListener, IInvokedMethodListener2, IMethodInterceptor,
IReporter, ISuiteListener, ITestListener.
TestNG Listeners … continued
 ISuiteListener: It has two method in it onStart() & onFinish(). Whenever a
class implements this listener, TestNG guarantees the end-user that it will
invoke the methods onStart() and onFinish() before and after running a
TestNG Suite. So before TestNG picks up your suite for execution, it first
makes a call to onStart() method and runs whatever has been scripted in this
method. In a similar way, it again makes a call to onFinish() method after a
suite has been run.
TestNG Listeners … continued
 ITestListener: The working of this listener is also exactly the same as
ISuiteListerner but the only difference is that it makes the call before and
after the Test not the Suite. It has seven methods in it.
 onFinish(): Invoked after all the tests have run and all their Configuration
methods have been called.
 onStart(): Invoked after the test class is instantiated and before any
configuration method is called.
TestNG Listeners … continued
 onTestFailedButWithinSuccessPercentage(ITestResult result): Invoked each
time a method fails but has been annotated with successPercentage and this
failure still keeps it within the success percentage requested.
 onTestFailure(ITestResult result): Invoked each time a test fails.
 onTestSkipped(ITestResult result): Invoked each time a test is skipped
 onTestStart(ITestResult result): Invoked each time before a test will be
invoked.
TestNG Listeners … continued
 onTestSuccess(ITestResult result): Invoked each time a test succeeds.
 IInvokedMethodListener: The working of this listener is also exactly the same
as ISuiteListerner & ITestListerner and the only difference is that it makes the
call before and after every Method. It has only two methods in it.
 afterInvocattion(): Invoke after each method
 beforeInvocation(): Invoke before each method
Questions
References
 TestNG - http://testng.org/doc/index.html
 TestNG Documentation - http://testng.org/doc/documentation-main.html
 Selenium and TestNG - http://testng.org/doc/selenium.html
Thanks

Más contenido relacionado

La actualidad más candente

Unit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesUnit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesDerek Smith
 
Introduction of TestNG framework and its benefits over Junit framework
Introduction of TestNG framework and its benefits over Junit frameworkIntroduction of TestNG framework and its benefits over Junit framework
Introduction of TestNG framework and its benefits over Junit frameworkBugRaptors
 
TestNG introduction
TestNG introductionTestNG introduction
TestNG introductionDenis Bazhin
 
An Introduction to JUnit 5 and how to use it with Spring boot tests and Mockito
An Introduction to JUnit 5 and how to use it with Spring boot tests and MockitoAn Introduction to JUnit 5 and how to use it with Spring boot tests and Mockito
An Introduction to JUnit 5 and how to use it with Spring boot tests and Mockitoshaunthomas999
 
Automation - web testing with selenium
Automation - web testing with seleniumAutomation - web testing with selenium
Automation - web testing with seleniumTzirla Rozental
 
Data driven Automation Framework with Selenium
Data driven Automation Framework with Selenium Data driven Automation Framework with Selenium
Data driven Automation Framework with Selenium Edureka!
 
Fitnesse - Acceptance testing
Fitnesse - Acceptance testingFitnesse - Acceptance testing
Fitnesse - Acceptance testingvijay_challa
 
Keyword-driven Test Automation Framework
Keyword-driven Test Automation FrameworkKeyword-driven Test Automation Framework
Keyword-driven Test Automation FrameworkMikhail Subach
 
Unit Testing And Mocking
Unit Testing And MockingUnit Testing And Mocking
Unit Testing And MockingJoe Wilson
 
Testing RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured frameworkTesting RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured frameworkMicha Kops
 
Test Automation and Selenium
Test Automation and SeleniumTest Automation and Selenium
Test Automation and SeleniumKarapet Sarkisyan
 
Test Automation
Test AutomationTest Automation
Test Automationrockoder
 
JUnit & Mockito, first steps
JUnit & Mockito, first stepsJUnit & Mockito, first steps
JUnit & Mockito, first stepsRenato Primavera
 

La actualidad más candente (20)

Unit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesUnit Testing Concepts and Best Practices
Unit Testing Concepts and Best Practices
 
Introduction of TestNG framework and its benefits over Junit framework
Introduction of TestNG framework and its benefits over Junit frameworkIntroduction of TestNG framework and its benefits over Junit framework
Introduction of TestNG framework and its benefits over Junit framework
 
TestNG introduction
TestNG introductionTestNG introduction
TestNG introduction
 
JUnit 5
JUnit 5JUnit 5
JUnit 5
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Selenium TestNG
Selenium TestNGSelenium TestNG
Selenium TestNG
 
An Introduction to JUnit 5 and how to use it with Spring boot tests and Mockito
An Introduction to JUnit 5 and how to use it with Spring boot tests and MockitoAn Introduction to JUnit 5 and how to use it with Spring boot tests and Mockito
An Introduction to JUnit 5 and how to use it with Spring boot tests and Mockito
 
Automation - web testing with selenium
Automation - web testing with seleniumAutomation - web testing with selenium
Automation - web testing with selenium
 
Data driven Automation Framework with Selenium
Data driven Automation Framework with Selenium Data driven Automation Framework with Selenium
Data driven Automation Framework with Selenium
 
Fitnesse - Acceptance testing
Fitnesse - Acceptance testingFitnesse - Acceptance testing
Fitnesse - Acceptance testing
 
Selenium WebDriver training
Selenium WebDriver trainingSelenium WebDriver training
Selenium WebDriver training
 
Keyword-driven Test Automation Framework
Keyword-driven Test Automation FrameworkKeyword-driven Test Automation Framework
Keyword-driven Test Automation Framework
 
Unit Testing And Mocking
Unit Testing And MockingUnit Testing And Mocking
Unit Testing And Mocking
 
Testing RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured frameworkTesting RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured framework
 
Test Automation and Selenium
Test Automation and SeleniumTest Automation and Selenium
Test Automation and Selenium
 
Automation testing
Automation testingAutomation testing
Automation testing
 
Test Automation
Test AutomationTest Automation
Test Automation
 
JUnit & Mockito, first steps
JUnit & Mockito, first stepsJUnit & Mockito, first steps
JUnit & Mockito, first steps
 
Selenium
SeleniumSelenium
Selenium
 
Test ng
Test ngTest ng
Test ng
 

Similar a TestNG Session presented in PB (20)

Test ng for testers
Test ng for testersTest ng for testers
Test ng for testers
 
Testing with Junit4
Testing with Junit4Testing with Junit4
Testing with Junit4
 
Unit testing php-unit - phing - selenium_v2
Unit testing   php-unit - phing - selenium_v2Unit testing   php-unit - phing - selenium_v2
Unit testing php-unit - phing - selenium_v2
 
Test ng tutorial
Test ng tutorialTest ng tutorial
Test ng tutorial
 
unit 1 (1).pptx
unit 1 (1).pptxunit 1 (1).pptx
unit 1 (1).pptx
 
Junit
JunitJunit
Junit
 
Unit test
Unit testUnit test
Unit test
 
Unit Testing in Java
Unit Testing in JavaUnit Testing in Java
Unit Testing in Java
 
J unit presentation
J unit presentationJ unit presentation
J unit presentation
 
JUnit Presentation
JUnit PresentationJUnit Presentation
JUnit Presentation
 
.Net Unit Testing with Visual Studio 2010
.Net Unit Testing with Visual Studio 2010.Net Unit Testing with Visual Studio 2010
.Net Unit Testing with Visual Studio 2010
 
8-testing.pptx
8-testing.pptx8-testing.pptx
8-testing.pptx
 
Introduction to JUnit
Introduction to JUnitIntroduction to JUnit
Introduction to JUnit
 
Unit testing
Unit testingUnit testing
Unit testing
 
Dev labs alliance top 20 testng interview questions for sdet
Dev labs alliance top 20 testng interview questions for sdetDev labs alliance top 20 testng interview questions for sdet
Dev labs alliance top 20 testng interview questions for sdet
 
What is new in JUnit5
What is new in JUnit5What is new in JUnit5
What is new in JUnit5
 
Junit
JunitJunit
Junit
 
JUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkJUnit- A Unit Testing Framework
JUnit- A Unit Testing Framework
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Automated Unit Testing
Automated Unit TestingAutomated Unit Testing
Automated Unit Testing
 

Último

(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate AgentsRyan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate AgentsRyan Mahoney
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 

Último (20)

(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate AgentsRyan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 

TestNG Session presented in PB

  • 2. Agenda  TestNG Overview  TestNG Plugins for Eclipse  TestNG Maven Dependency  TestNG Annotations  TestNG XML  TestNG with Selenium  TestNG Parameters and Data Provider  TestNG Parallel Execution and Cross Browser Testing
  • 3. TestNG Overview  TestNG is a testing framework introducing some new functionality that make it more powerful and easier to use.  It is an open source automated testing framework hence no cost required for implementation.  It is designed to cover all categories of tests: unit, functional, end-to-end, integration, etc.
  • 4. TestNG Overview … continued  Based on annotations (either Javadoc or JDK5)  Flexible runtime configuration (XML, not Java)  Introduces the notion of “test groups” to clearly separate static testing (implementing the methods) from dynamic (which tests are run)  Dependent test methods, parallel testing, load testing, partial failure  Flexible plug-in API (report creation, even changing the core behavior)  Created by Dr. Cédric Beust (of Google)
  • 5. TestNG Plugins for Eclipse  Eclipse http://beust.com/eclipse
  • 6. TestNG Maven Dependency  Maven <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>6.9.10</version> <scope>test</scope> </dependency>
  • 7. 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  @BeforeGroups: Run before any test method belonging to the group  @AfterGroups: Run after all test methods belonging to the group
  • 8. TestNG Annotations … continued  @BeforeClass: Run before the first test method in the current class  @AfterClass: Run after all the test methods in the current class  @BeforeMethod: Run before each test method  @AfterMethod: Run after each test method  @Test: Identify a test method  @DataProvider: Create parameters to pass to your test methods  @Factory: Create your own test objects at runtime
  • 9. TestNG Annotations … continued  @Test: Identify a test method groups: The groups this method belongs to parameters: The parameters that will be passed to your test method, as they are found in testng.xml dependsOnGroups: The list of groups this test method depends on. dependsOnMethods: The list of groups this test method depends on. enabled: Use to ignore a test timeOut: How long TestNG should wait before declaring your test method has failed
  • 10. TestNG Annotations … continued @Test(enabled=true, groups = { “sanity” }, timeOut = 10000) public void test1() { // … }
  • 11. TestNG Annotations … continued @Test(enabled=true, groups = { “regression” }, timeOut = 10000, dependsOnGroups = { “sanity” }) public void test2() { // … }
  • 12. TestNG Annotations … continued @Test(enabled=true, dependsOnMethod = { “test2” }) public void test3() { // … }
  • 13. TestNG XML  Where all the runtime information goes:  The test methods, classes, packages  Which groups should be run (include-groups)  Which groups should not be run (exclude-groups)  Define additional groups (“groups of groups”)  Whether the tests should be run in parallel  Parameters
  • 14. TestNG XML … continued <test name=“Simple"> <groups> <run> <include name=“functest”/> </run> </groups> <classes> <class name=“SimpleTest” /> </classes> </test>
  • 18. TestNG Listeners There are many types of listeners available in TestNG for example: IAnnotationTransformer, IAnnotationTransformer2, IConfigurable, IConfigurationListener, IConfigurationListener2, IExecutionListener, IHookable, IInvokedMethodListener, IInvokedMethodListener2, IMethodInterceptor, IReporter, ISuiteListener, ITestListener.
  • 19. TestNG Listeners … continued  ISuiteListener: It has two method in it onStart() & onFinish(). Whenever a class implements this listener, TestNG guarantees the end-user that it will invoke the methods onStart() and onFinish() before and after running a TestNG Suite. So before TestNG picks up your suite for execution, it first makes a call to onStart() method and runs whatever has been scripted in this method. In a similar way, it again makes a call to onFinish() method after a suite has been run.
  • 20. TestNG Listeners … continued  ITestListener: The working of this listener is also exactly the same as ISuiteListerner but the only difference is that it makes the call before and after the Test not the Suite. It has seven methods in it.  onFinish(): Invoked after all the tests have run and all their Configuration methods have been called.  onStart(): Invoked after the test class is instantiated and before any configuration method is called.
  • 21. TestNG Listeners … continued  onTestFailedButWithinSuccessPercentage(ITestResult result): Invoked each time a method fails but has been annotated with successPercentage and this failure still keeps it within the success percentage requested.  onTestFailure(ITestResult result): Invoked each time a test fails.  onTestSkipped(ITestResult result): Invoked each time a test is skipped  onTestStart(ITestResult result): Invoked each time before a test will be invoked.
  • 22. TestNG Listeners … continued  onTestSuccess(ITestResult result): Invoked each time a test succeeds.  IInvokedMethodListener: The working of this listener is also exactly the same as ISuiteListerner & ITestListerner and the only difference is that it makes the call before and after every Method. It has only two methods in it.  afterInvocattion(): Invoke after each method  beforeInvocation(): Invoke before each method
  • 24. References  TestNG - http://testng.org/doc/index.html  TestNG Documentation - http://testng.org/doc/documentation-main.html  Selenium and TestNG - http://testng.org/doc/selenium.html