0% found this document useful (0 votes)
17 views3 pages

TestNG Notes

TestNG is an advanced automation testing framework that allows for features such as parallel execution, dependency management, and detailed reporting. It supports various testing methodologies, including Test Driven Development (TDD), and integrates easily with tools like Maven and Jenkins. TestNG provides customizable reporting through listeners and allows for the execution of failed test cases using the 'testng-failed.xml' file.

Uploaded by

qavasutesting
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views3 pages

TestNG Notes

TestNG is an advanced automation testing framework that allows for features such as parallel execution, dependency management, and detailed reporting. It supports various testing methodologies, including Test Driven Development (TDD), and integrates easily with tools like Maven and Jenkins. TestNG provides customizable reporting through listeners and allows for the execution of failed test cases using the 'testng-failed.xml' file.

Uploaded by

qavasutesting
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

TestNG:

-------

TestNG is an automation testing framework in which NG stands for "Next Generation".


TestNG is inspired from JUnit which uses the annotations (@).

Using TestNG you can generate a proper report, and


you can easily come to know how many test cases are passed, failed and skipped.

The TestNG provides an option, i.e., testng-failed.xml file in test-output folder.


If you want to run only failed test cases means you run this XML file. It will
execute only failed test cases.

*) parallel execution of test method


*) Dependency over one test method over other test method
*) Assign priority to test method
*) Grouping of test method
*) support for parameterizing
*) Allow DDT over @Dataprovider Annotation
*) Checking Expected and actual values
*) Detailed Html Report

TESTNG.XML = To create and handle multiple test classes . to configure the complete
test suite in a single file

Adv :
-----
Multiple test cases can be grouped more easily by converting them into testng.xml
file. (grouped = testng.xml)
In which you can make priorities which test case should be executed
first.

The same test case can be executed multiple times without loops just by using
keyword called 'invocation count. (MultipleTimes = invocation count)

you can execute multiple test cases on multiple browsers, i.e., cross browser
testing. (Multiple Browser)

easily integrated with tools like Maven, Jenkins, etc.


(Integrated)

TestNG is capable of generating HTML-based reports.


(HTML report)

There are three major advantages of TestNG over JUnit:


------------------------------------------------------

Annotations are easier to understand ( @Test annotation)


Test cases can be group ed more easily
Parallel testing is possible

Why do we need Session Handling ?


------------------------------------------
During test execution, the Selenium WebDriver has to interact with the browser all
the time to execute given commands. ()
At the time of execution, it is also possible that, before current execution
completes,
someone else starts execution of another script, in the same machine and in the
same type of browser.

How to run Parallel Tests with Selenium


-------------------------------------------
There are situations where you want to run multiple tests at the same time.

In such cases, one can use "parallel" attribute

Test Case order and Dependency


-----------------------------------------------
You can set order and dependency of Test Case execution.

Suppose you have two test cases , 'testGuru99TC1' and 'testGuru99TC2' and you want
to execute test case 'testGuru99TC2' before 'testGuru99TC1'.
In that case we will use 'dependsOnMethods' attribute to make dependency and order
of execution. (dependsOnMethods)

What is Listeners in TestNG?


---------------------------------------------------
Listener is defined as interface that modifes the default TestNG's behavior

It allows customizing TestNG reports or logs

There are :

ISuiteListener,
ITestListener .
IConfigurable ,
IConfigurationListener ,
IAnnotationTransformer ,
IAnnotationTransformer2

ITestListener has following methods

OnStart- OnStart method is called when any Test starts.


onTestSuccess- onTestSuccess method is called on the success of any Test.
onTestFailure- onTestFailure method is called on the failure of any Test.
onTestSkipped- onTestSkipped method is called on skipped of any Test.
onTestFailedButWithinSuccessPercentage- method is called each time Test fails but
is within success percentage.
onFinish- onFinish method is called after all Tests are executed.

Execute failed test cases using TestNG in Selenium – By using “testng-failed.xml”

Execute failed test cases using TestNG in Selenium – By Implementing TestNG


IRetryAnalyzer

DataProvider :

Same Testcase will run multiple number of times we should use data providers

TEST DRIVEN DEVELOPMENT :

TDD can be defined as a programming practice that instructs developers to write new
code only if an automated test has failed.
This avoids duplication of code. TDD means “Test Driven Development”.
The primary goal of TDD is to make the code clearer, simple and bug-free.

TESTNG :

>TestNG has an inbuilt reporting ability in it.


>After a complete execution of test cases, TestNG generates a test-output folder in
the root of the project.
>In the test-output folder, there are two main reports, index.html, and emailable-
report.html.
>To customize TestNG report we need to implement two interfaces, ITestListener and
IReporter.
>If we need to get a report in between execution, we need ITestListener.
(B/W Execution = ITestLIstener)
>For creating a final report after complete execution, we need to implement
IReporter. (A/F Execution = IReporter)
>Taking the screenshot, in Selenium WebDriver, we need to type cast WebDriver to
TakesScreenShot interface.
>To generate pdf reports we need to add IText jar in the project.
(pdf report = IText jar)

TestNG Listeners are mainly used in generating customized reports and logs. Below
are the list of listeners provided TestNG. Each interface is having different
abstract methods which can be overridden as per our requirement.

IExecutionListener
This TestNG Listener monitors the begining and ending of the TestNG run. This has
two methods onExecutionStarts() and onExecutionEnd(). onExecutionStarts() method
will be invoked before TestNG starts executing the test suites and onExecutionEnd()
method will be invoked after TestNG finishes executing all the test suites.
IAnnotationTransformer
This TestNG Listener allows us to modify TestNG annotations and configure further.
IInvokedMethodListener
This TestNG Listener is for all the methods. It will be invoked before and after of
any method of TestNG.
IMethodInterceptor
This TestNG Listener is used to modify the list of test methods to be run in
TestNG. We can select group of test methods from the given list using this and
ignore other test methods.
IHookable
This TestNG Listener is used to implement your test methods with specific security
manager. If a test class implements this interface, its run() method will be
invoked instead of each @Test method found.
IReporter
This TestNG Listener is used for generating the report at the end of test suite
execution.
ISuiteListener
This TestNG Listener is for test suite and this listener contains two methods
onStart() and onFinish(). onStart() method will be invoked before executing the
Suite and onFinish() will be invoked at the end of the Suite execution.
ITestListener
This TestNG Listener is for test method and this contains methods onStart(),
onFinish(), onTestSuccess(), onTestFailure(), onTestSkipped() and
onTestFailedButWithinSuccessPercentage().

You might also like