Tutorial Agenda: 1 Exclude-Include
Tutorial Agenda: 1 Exclude-Include
Part 5
Tutorial Agenda
1> Exclude-Include:- TestNG
provides the feature of
enabling and disabling
the test cases. We can
disable a set of test
cases from getting
executed.
For example, we have
scenario where a
serious bug occurs in a
feature due to certain
tests, so we need
to disable the test
cases from being
executed.
You can disable or exclude the test
cases by using the enable attribute
to the @Test annotation and assign
False value to the enable attribute.
Syntax: @Test(enabled=false)
We can achieve this thing in two way
as below:
1> We can add value in the @Test
annotation as below:
Example:
Result:
2> We can add Exclude tag into
the testng.xml file:
Example:
Result:
Result as described
above:
😀 TIME TO IMPLEMENT the Same
IN YOUR ECLIPSE NOW😀
3> TestNG Listeners:
TestNG provides
the @Listeners annotation which
listens to every event that occurs in
a selenium code.
Listeners are activated either before
the test or after the test case.
It is an interface that modifies the
TestNG behavior. For example,
when you are running a test case
either through selenium or appium
and suddenly a test case fails.
We need a screenshot of the test
case that has been failed, to achieve
such scenario, TestNG provides a
mechanism, i.e., Listeners. When
the test case failure occurs, then it is
redirected to the new block written
for the screenshot.
Listeners are implemented by
the ITestListener interface.
An ITestListener interface has the
following methods:
Below is the description of all
listeners methods:
onTestStart(): An onTestStart() is
invoked only when any test method
gets started.
onTestSuccess(): Method is
executed on the success of a test
method.
onTestFailure(): Method is invoked
when test method fails.
onTestSkipped(): Method run only
when any test method has been
skipped.
onTestFailedButWithinSuccessPerc
entage():Method is invoked each
time when the test method fails but
within success percentage.
onStart(): Method is executed on the
start of any test method.
onFinish(): Method is invoked when
any test case finishes its execution.
Let's Implement this:
First, We need to create one
Listener class which contains all
methods definition and print line
information.
Sample Definition should be as
below:
Below is the definition of all method
on above class.
Ankit Prajapati
QA Automation Lead 10+ Year Industry Experience in Enterprise Projects. Automation QA Expert | Selenium | Java | TestNG |
Maven | Jenkins | API Testing | BDD Cucumber Online Trainer & Planner
No comments:
Post a Comment
Links to this post
Create a Link
Older PostHome