Selenium Framework for Beginners 20 | What are TestNG Listeners | How to use TestNG Listeners

preview_player
Показать описание
Today we will learn
1 What are TestNG listeners
2 Types of listeners
3 How to use TestNG listeners
at class level
at suite level (multiple classes)
4 Selenium test example

helpful tips

What are TestNG Listeners

Listeners are components in TestNG that listens ( keep a track ) of test execution and helps to perform actions at multiple stages of test execution

Example
OnStart
OnFinish
OnSuccess
OnFailure
Etc…

Listeners are interfaces in TestNG library

How to use TestNG listeners

Step 1 Create a new package and new Class

Step 2 Implement ITestListener interface

public class TestNGListener implements ITestListener

Step 3 Add unimplemented methods of ITestListener interface

Step 4 Create a Demo class and provide annotation
@Listeners(packageName.ClassName)

Step 5 Run and validate

How to use at Suite Level (multiple classes)

Step 3 Run and validate

Adding more listeners from TestNG

You can implement more listener interfaces in your existing class and add implemented methods

REFERENCES

#SeleniumJavaFramework #SeleniumTutorials #TestNGListeners #SeleniumForBeginners

PLAYLISTS

SELENIUM JAVA FRAMEWORK BEGINNERS

KATALON STUDIO

SELENIUM BEGINNERS

SELENIUM TIPS

SELENIUM PYTHON

SELENIUM BUILDER

JAVA

JAVA TIPS & TRICKS

JENKINS

JENKINS TIPS & TRICKS

JMETER BEGINNER

JMETER INTERMEDIATE

JMETER ADVANCED

JMETER TIPS & TRICKS

SOAPUI

POSTMAN

GIT & GITHUB

DOCKER

ROBOT FRAMEWORK

WEB SERVICES (API)

REDIS BEGINNER TUTORIALS

MAVEN

MISC

TOOLS & TIPS

QnA FRIDAY

SUNDAY SPECIAL

ALL PLAYLISTS

Like on FACEBOOK :

Follow on TWITTER:

Subscribe on YOUTUBE :

________ ONLINE COURSES TO LEARN ________

Never Stop Learning
Raghav
Рекомендации по теме
Комментарии
Автор

As always sir "the best explanation one can get"

ankitchoudhary
Автор

sir you are great you have explained it so well and in such an easy manner, big thanks from my side :)

lavbhatt
Автор

Sir you are great..can you post a video how to use sauce labs for mobile testing.you have posted for web and it's very helpful.

sipunrocks
Автор

Hello. How can I get auto suggest umimplement methods After I typed implements ITestListeners Interface.

sokoeurnchhay
Автор

You are a Gem. I really appreciate all the work you are doing. Thank you so much.

NishantRanjan
Автор

Would you use listeners with Extent reporter? So if a test fails, you can say take a screenshot to add to the report?

FazSaber
Автор

Hi Sir, I've imported ITestListener package, still it is not showing any red line under the classname 'Listener'. so I'm not able to add unimplemented methods. Please help me where I'm going wrong?

srija_sk
Автор

Hi Raghav, I am not getting to error to add unimplemented method for ITestListner. Can you please let me know. I have restarted eclipse. But still getting same error. Please help.

muzisadventure
Автор

Hi Sir,


I am facing below error when I run the test from xml.


Caused by: unable to find valid certification path to requested target

yogisingh
Автор

Hi Raghav, I am also not able to get all the unimplemented methods by default, what to do?

srivenkatanathann
Автор

Hi Raghav, I m following all the steps as you mentioned in video but I m not getting any error to add the unimplemented methods...I also restarted eclipse...but issue remains same...my testNG version is "7.1.0".

package Listeners;

import org.testng.ITestListener;

public class TestNGListeners implements ITestListener {

}

nistan
Автор

Hi Raghav Sir,
Can we use listeners in cucumber framework project just like TestNG??
I have one test case with 3 scenarios in cucumber project.
and if two scenario failed then I want two different .png files in my screenshot folder.I m able to get one png file with hooks in Screenshot folder without using listener in below example
But what to do if two scenario failed.
e.g
@After
public void teardown(Scenario scenario) throws IOException {
System.out.println("close browser");
if (scenario.isFailed()) {
File scrFile =
FileUtils.copyFile(scrFile, new
}
driver.close();

}

nistan
Автор

Hi Raghav,


how can I add listeners to my extent report ?

JRYES
Автор

Hello raghav,


can I add listeners to each cases in the switch statements? (I am using a keyword framework) If that is possible, how can I add those? thanks

kevinsantillan
Автор

Hello sir plz help to know which is the best certification for jmeter or make a video for which certification is good for fresher QA. Plz plz Sir

abhinavanand
Автор

Sir... For Assertion, you are importing junit package instead of TestNG package

ilavarasansriraman
Автор

Hi Sir,
I have followed all the steps as explained in this video but when I execute with the testng.xml it shows the output twice....as below:
Started: test1
Started: test1
I am inside test1
Successful: test1
Successful: test1
Started: test2
Started: test2
I am inside test2
failed: test2
failed: test2
Started: test3
Started: test3
I am inside test3
Skipped: test3
Skipped: test3
Tests Completed: Test
Tests Completed: Test


Suite
Total tests run: 3, Failures: 1, Skips: 1


But when I execute directly from the Class then it shows the proper output as shown in your video.
Can you please help me out here..

nedhishetty
Автор

Hi Raghav,


I followed your video to 14.30 but statement from listener is not printed in Console.


Please see my code and result below and let me know what I am missing here.


Thank You,

package listeners;


import org.testng.ITestContext;
import org.testng.ITestNGListener;
import org.testng.ITestResult;


public class TestNGListeners implements ITestNGListener{


public void onTestStart(ITestResult result) {
Test started :" +result.getName());
}


public void onTestSuccess(ITestResult result) {
Test is successful :" +result.getName());


}


public void onTestFailure(ITestResult result) {
Test failed :" +result.getName());
}


public void onTestSkipped(ITestResult result) {
Test skipped :" +result.getName());
}


public void result) {


}


public void onStart(ITestContext context){


}


public void onFinish(ITestContext context){
Tests finish :" +context.getName());


}
}



package listeners;


import static org.testng.Assert.assertTrue;


import org.testng.Assert;
import
import org.testng.annotations.Test;



public class TestNGListenerDemo {


@Test
public void test1() {


System.out.println("I am inside test1.");
}

@Test
public void test2() {


System.out.println("I am inside test2.");
//Assert.assertTrue(false);
}

@Test
public void test3() {


System.out.println("I am inside test3.");
}
}





Console.


[RemoteTestNG] detected TestNG version 7.0.1
I am inside test1.
I am inside test2.
I am inside test3.
PASSED: test1
PASSED: test2
PASSED: test3



Default test
Tests run: 3, Failures: 0, Skips: 0






Default suite
Total tests run: 3, Passes: 3, Failures: 0, Skips: 0

surajsurya
Автор

Hii sir,
When i am trying this code on my System. He takes only "ITestListener" and import that..but He not Showing any kind of error at Class Name. ( I mean Can't add unimplemented methods).
So for that what will i do.

ganeshswami
Автор

Bro Small help
I'm going to learn selenium web driver with java

current generation its okay or could you suggest me any language and
I'm learn through institute

waiting for your reply

arunachalamp