0

My testing XML is like below

<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
    <suite name="ABC">
      <listeners>
        <listener class-name="XYZ.ABC.Listners"/>
      </listeners>  
      <test thread-count="5" name="XYZ">
        <parameter name="myPara" value="PQR "> </parameter>
        <classes>
          <class name="XYZ.ABC.TesttoTest"/>
          <class name="XYZ.ABC.NavigatorCheckTest"/>
        </classes>        
      </test> <!-- Test -->
    </suite> <!-- Suite -->

But this doesn't work (I mean listeners not fired) .

BUT if I add @Listeners(XYZ.ABC.Listners.class) in any of the classes in suite (have 2) it works for both classes.

Listeners class is below:

    package XYZ.ABC;
    
    import org.openqa.selenium.WebDriver;
    import org.testng.ITestContext;
    import org.testng.ITestListener;
    import org.testng.ITestResult;
    
    public class Listners extends TestBase implements ITestListener {
    
        @Override
        public void onFinish(ITestContext arg0) {
            // TODO Auto-generated method stub
            
        }
    
        @Override
        public void onStart(ITestContext arg0) {
            // TODO Auto-generated method stub
            
        }
    
        @Override
        public void onTestFailedButWithinSuccessPercentage(ITestResult arg0) {
            //System.out.println("");
            
        }
    
        @Override
        public void onTestFailure(ITestResult result) {
            System.out.println("Test Failed FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
            
        }
    
        @Override
        public void onTestSkipped(ITestResult arg0) {
            // TODO Auto-generated method stub
            
        }
    
        @Override
        public void onTestStart(ITestResult arg0) {
            // TODO Auto-generated method stub
            
        }
    
        @Override
        public void onTestSuccess(ITestResult result) {
            System.out.println("Test Success PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP");
            
        }
    
    
    }

and TestBase is

    package XYZ.ABC;
    
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.util.Properties;
    import org.apache.commons.io.FileUtils;
    import org.openqa.selenium.OutputType;
    import org.openqa.selenium.TakesScreenshot;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.edge.EdgeDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    
    
    
        public class TestBase {
            public WebDriver driver;
            public Properties prop;
            
            public WebDriver initializeDriver() throws IOException {
                prop = new Properties();
                //System. getProperty("user.dir") => gives current directory 
                FileInputStream fis = new FileInputStream(System.getProperty("user.dir")+"\\GlobConst.properties");
                
                prop.load(fis);
                String browserName = prop.getProperty("browser");
                String urlString   = prop.getProperty("URL");
    
                
                if (browserName.equals("chrome")){
                    System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir")+"\\chromedriver.exe");
                    driver = new ChromeDriver();
                    
                } else if (browserName.equals("firefox")) {
                    driver = new FirefoxDriver();
                    
                } else if (browserName.equals("edge")) {
                    driver = new EdgeDriver();
                }
        
                driver.get(urlString);
                return driver;
            }
            
            public void getScreenShotPath(String testCaseName, WebDriver driver) throws IOException{
                TakesScreenshot ts = (TakesScreenshot) driver;
                File source = ts.getScreenshotAs(OutputType.FILE);
                String destinationFile = System.getProperty("user.dir")+"\\reports\\"+testCaseName+".png";
                FileUtils.copyFile(source, new File(destinationFile));
            }
    
    
    
    
    }

Any Idea what's happening or where to look into?

2
  • 1
    Paste your listener class here Aug 14 '20 at 5:25
  • added Listeners class and TestBase class
    – 1234
    Aug 16 '20 at 21:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.