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

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 ม.ค. 2025

ความคิดเห็น • 70

  • @ankitchoudhary9
    @ankitchoudhary9 3 ปีที่แล้ว +1

    As always sir "the best explanation one can get"

    • @RaghavPal
      @RaghavPal  3 ปีที่แล้ว

      Thanks a lot Ankit

  • @lavbhatt6512
    @lavbhatt6512 4 ปีที่แล้ว

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

    • @RaghavPal
      @RaghavPal  4 ปีที่แล้ว

      You are most welcome Lav

  • @NishantRanjan2811
    @NishantRanjan2811 2 ปีที่แล้ว

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

    • @RaghavPal
      @RaghavPal  2 ปีที่แล้ว +1

      You are so welcome Nishant

  • @vaishalilahudkar2795
    @vaishalilahudkar2795 3 ปีที่แล้ว

    Its a very useful.Thanks

    • @RaghavPal
      @RaghavPal  3 ปีที่แล้ว

      Most welcome Vaishali

  • @sokoeurnchhay3463
    @sokoeurnchhay3463 4 หลายเดือนก่อน

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

    • @RaghavPal
      @RaghavPal  4 หลายเดือนก่อน

      When you implement the ITestListener interface in your TestNG listener class, you can use the IDE's auto-complete feature to generate the unimplemented methods.
      Here are the steps to get the auto-suggested unimplemented methods:
      Type implements ITestListener after your class name.
      Place the cursor after the implements ITestListener text.
      Press Ctrl + Space (Windows/Linux) or Cmd + Space (Mac) to trigger the auto-complete feature.
      Select the "Implement methods" option from the dropdown list.
      Your IDE will generate all the unimplemented methods of the ITestListener interface.
      Alternatively, you can also use the "Implement/Override Methods" feature in your IDE:
      Place the cursor on the class name.
      Right-click and select "Generate" (or press Alt + Insert in IntelliJ IDEA).
      Select "Implement methods" (or "Override methods" in some IDEs).
      Choose the ITestListener interface from the list.
      Select all the methods you want to implement.
      The unimplemented methods of the ITestListener interface will be generated, including:
      onStart(ITestContext context)
      onFinish(ITestContext context)
      onTestStart(ITestResult result)
      onTestSuccess(ITestResult result)
      onTestFailure(ITestResult result)
      onTestSkipped(ITestResult result)
      onTestFailedButWithinSuccessPercentage(ITestResult result)
      You can then implement these methods to create your custom TestNG listener.

  • @sipun123rocks
    @sipun123rocks 4 ปีที่แล้ว

    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.

    • @RaghavPal
      @RaghavPal  4 ปีที่แล้ว

      I will try to do that Jayaprakash

  • @tannislearn5454
    @tannislearn5454 4 ปีที่แล้ว +1

    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 {

    }

    • @tannislearn5454
      @tannislearn5454 4 ปีที่แล้ว +10

      My issue is resolved now after using below steps:
      Right click(on the Listeners class from ProjectExplorer ) -> go to source-> click on overide/implement methods -> select the check boxes for the ITest listener (make sure all check box inside it should be checked )->click on oK. That's it !!! :)

    • @RaghavPal
      @RaghavPal  4 ปีที่แล้ว

      So happy to know you resolved it

    • @arpitaslittleworld
      @arpitaslittleworld 4 ปีที่แล้ว +2

      @@tannislearn5454 thanks a lot for posting the solution here.. i was actually in search of this.. much appreciated.

    • @zahidullaghouri4532
      @zahidullaghouri4532 3 ปีที่แล้ว

      @@tannislearn5454 thanks brother... was searching it from an hour you solved my problem

    • @TheSoleNemesis
      @TheSoleNemesis 3 ปีที่แล้ว

      @@tannislearn5454 Brilliant. I had the same issue twice but after reading your comment I was able to resolve the issue as well. Thank you so much!

  • @srivenkatanathann1630
    @srivenkatanathann1630 3 ปีที่แล้ว

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

    • @RaghavPal
      @RaghavPal  3 ปีที่แล้ว

      will need to see if you have added the required lib and did the setup properly

  • @muzisadventure7660
    @muzisadventure7660 3 ปีที่แล้ว

    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.

    • @RaghavPal
      @RaghavPal  3 ปีที่แล้ว

      Just check if all the required dependencies are added in pom.xml

  • @srija_sk
    @srija_sk 3 ปีที่แล้ว

    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?

    • @RaghavPal
      @RaghavPal  3 ปีที่แล้ว +1

      Hi, will need to check the logs and troubleshoot

  • @Faz540
    @Faz540 6 ปีที่แล้ว

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

    • @RaghavPal
      @RaghavPal  6 ปีที่แล้ว

      Yes that is very much practiced Paul

  • @tannislearn5454
    @tannislearn5454 4 ปีที่แล้ว

    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 = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
    FileUtils.copyFile(scrFile, new File("D:\\EclipseProjectWorkspace\\FBuzzSuite_Cucumber\\Screenshots\\Test.png"));
    }
    driver.close();

    }

    • @RaghavPal
      @RaghavPal  4 ปีที่แล้ว

      Yes, you can use. You can also check hooks
      cucumber.io/docs/cucumber/api/#hooks

  • @ganeshswami7909
    @ganeshswami7909 4 ปีที่แล้ว

    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.

    • @RaghavPal
      @RaghavPal  4 ปีที่แล้ว +1

      Hi Ganesh, sorry for late reply. Will need to check more details on this

    • @ganeshswami7909
      @ganeshswami7909 4 ปีที่แล้ว

      @@RaghavPal Thank You sir,
      & Sir, Now Solve this Issue.
      and I am Watching Your Videos on Cucumber BDD Framework.
      👍👍

  • @yogisingh170
    @yogisingh170 5 ปีที่แล้ว

    Hi Sir,
    I am facing below error when I run the test from xml.
    Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

    • @RaghavPal
      @RaghavPal  5 ปีที่แล้ว

      Hi Yogi, this should help - stackoverflow.com/questions/49339698/org-testng-testngexception-sun-security-provider-certpath-suncertpathbuilderexc

  • @kevinsantillan8518
    @kevinsantillan8518 5 ปีที่แล้ว

    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

    • @RaghavPal
      @RaghavPal  5 ปีที่แล้ว

      Hi Kevin, I did not completely got you. What exactly is the scenario and what do you want to achieve

    • @kevinsantillan8518
      @kevinsantillan8518 5 ปีที่แล้ว

      @@RaghavPal Hi Raghav. I have created a test method with switch statements (it has multiple cases) and those cases are called by an excel file using the keywords inside the file. So can I add the listeners to the multiple cases of that switch statement?

    • @RaghavPal
      @RaghavPal  5 ปีที่แล้ว

      You can as per your need Kevin

  • @surajsurya1414
    @surajsurya1414 4 ปีที่แล้ว

    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) {
    System.out.println("********* Test started :" +result.getName());
    }
    public void onTestSuccess(ITestResult result) {
    System.out.println("********* Test is successful :" +result.getName());
    }
    public void onTestFailure(ITestResult result) {
    System.out.println("********* Test failed :" +result.getName());
    }
    public void onTestSkipped(ITestResult result) {
    System.out.println("********* Test skipped :" +result.getName());
    }
    public void onTestFailedButWithinSuccessPercentage(ITestResult result) {
    }
    public void onStart(ITestContext context){
    }
    public void onFinish(ITestContext context){
    System.out.println("********* Tests finish :" +context.getName());
    }
    }
    ---------------------------------
    package listeners;
    import static org.testng.Assert.assertTrue;
    import org.testng.Assert;
    import org.testng.annotations.Listeners;
    import org.testng.annotations.Test;
    @Listeners(listeners.TestNGListeners.class)
    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
    ===============================================

    • @RaghavPal
      @RaghavPal  4 ปีที่แล้ว

      Hi Suraj, I will have to check the setup for this. Just re-check with all the steps

    • @surajsurya1414
      @surajsurya1414 4 ปีที่แล้ว

      @@RaghavPal Hi Raghav,
      Just to let you know I find some typo mistake in my code. My problem is solved now.
      Thank you for your quick response.
      You are great.

  • @ilavarasansriraman4140
    @ilavarasansriraman4140 4 ปีที่แล้ว

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

    • @RaghavPal
      @RaghavPal  4 ปีที่แล้ว

      Hi Ilavarasan, where exactly, pls mention the time stamp, I will correct it

    • @ilavarasansriraman4140
      @ilavarasansriraman4140 4 ปีที่แล้ว

      @@RaghavPal time => 14:50

    • @RaghavPal
      @RaghavPal  4 ปีที่แล้ว +1

      Okay, I cannot update the existing video but will take care for next one

    • @ilavarasansriraman4140
      @ilavarasansriraman4140 4 ปีที่แล้ว

      @@RaghavPal okay sir

  • @786Muhaimin
    @786Muhaimin 4 ปีที่แล้ว

    I don't know why, but when I don't get the error to add the unimplemented methods, I've configured my framework properly with TestNG, any suggestions?

    • @RaghavPal
      @RaghavPal  4 ปีที่แล้ว

      You can try to restart Eclipse and check

    • @kshipra4504
      @kshipra4504 2 ปีที่แล้ว

      @@RaghavPal I am also facing this same issue. Even, restarting did not help.

  • @shardasstudio6505
    @shardasstudio6505 5 ปีที่แล้ว

    hi sir, m facing below error while running testng suite file.

    • @RaghavPal
      @RaghavPal  5 ปีที่แล้ว +1

      What is the error Shardha

    • @shardasstudio6505
      @shardasstudio6505 5 ปีที่แล้ว

      Hi Sir, i have created testng suite, when i run this testng suite , m facing below error.
      [RemoteTestNG] detected TestNG version 6.14.2
      org.testng.TestNGException:
      Listener listener.TestNGListener was not found in project's classpath
      at org.testng.TestNG.addListeners(TestNG.java:946)
      at org.testng.TestNG.initializeConfiguration(TestNG.java:912)
      at org.testng.TestNG.initializeEverything(TestNG.java:996)
      at org.testng.remote.support.RemoteTestNG6_12.initialize(RemoteTestNG6_12.java:22)
      at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:97)
      at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
      at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

    • @RaghavPal
      @RaghavPal  5 ปีที่แล้ว

      Looks like name is incorrect. Pls check this stackoverflow.com/questions/33875603/testng-listener-was-not-found

  • @abhinavanand4076
    @abhinavanand4076 6 ปีที่แล้ว

    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

    • @RaghavPal
      @RaghavPal  6 ปีที่แล้ว

      Abhinav, do not post the same comment on different videos. I can see all the comments from different videos at once. So this is just duplicate for me.
      As i told earlier for JMeter as of now there is VSkills certification and it is enough. It's a open source tool and so we do not have a specific certification from any org/body for it.
      I will make a video on it as well

    • @abhinavanand4076
      @abhinavanand4076 6 ปีที่แล้ว

      Automation Step by Step - Raghav Pal Thank u sir and i am sorry sir for duplicate comments, i did't get any comment regarding Vskills so i do this, i m really sorry for this behaviour 😔😔😔😔

    • @RaghavPal
      @RaghavPal  6 ปีที่แล้ว

      Thats okay Abhinav, just wanted to let you know as I was getting too many duplicate comments. And I will soon create a video where I will explain this. It will help others too.

  • @nedhishetty1315
    @nedhishetty1315 4 ปีที่แล้ว

    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:
    ************Test Started: test1
    ************Test Started: test1
    I am inside test1
    ************Test Successful: test1
    ************Test Successful: test1
    ************Test Started: test2
    ************Test Started: test2
    I am inside test2
    ************Test failed: test2
    ************Test failed: test2
    ************Test Started: test3
    ************Test Started: test3
    I am inside test3
    ************Test Skipped: test3
    ************Test Skipped: test3
    ************All Tests Completed: Test
    ************All 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..

    • @RaghavPal
      @RaghavPal  4 ปีที่แล้ว

      Hi Nedhi, check this can help stackoverflow.com/questions/20715802/how-do-i-get-a-testng-report-to-show-console-output

  • @arunachalamp1683
    @arunachalamp1683 3 ปีที่แล้ว

    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

    • @RaghavPal
      @RaghavPal  3 ปีที่แล้ว +1

      You can learn from this or any online tutorials and Java is good to start with

    • @arunachalamp1683
      @arunachalamp1683 3 ปีที่แล้ว

      @@RaghavPal Thank you bro

  • @maharaj92
    @maharaj92 3 ปีที่แล้ว

    Not able to use groups if listeners is getting usedIt throwing error

    • @RaghavPal
      @RaghavPal  3 ปีที่แล้ว

      Hi Aniket, will need to check on this

  • @JRYES
    @JRYES 5 ปีที่แล้ว

    Hi Raghav,
    how can I add listeners to my extent report ?

    • @RaghavPal
      @RaghavPal  5 ปีที่แล้ว

      Hi Jerome, just check this article may help - www.seleniumeasy.com/selenium-tutorials/extent-reports-using-testng-listeners

  • @Deniz-ss1sv
    @Deniz-ss1sv 3 ปีที่แล้ว

    :)