简体   繁体   English

未生成范围报告

[英]Extent Report not being generated

I tried generating an extent report with a listener, extentreportgen, base class, and the main test class but it isn't being generated.我尝试使用侦听器、extentreportgen、基础 class 和主要测试 class 生成范围报告,但它没有生成。 I don't know what's wrong, I would appreciate the help.The first is my main test class, the second is my listeners class, the third is my Base class, and the last one is my extent report gen class. I don't know what's wrong, I would appreciate the help.The first is my main test class, the second is my listeners class, the third is my Base class, and the last one is my extent report gen class.

Log in main test code登录主测试代码


import java.io.IOException;

import org.testng.annotations.Test;

import extentListners.Listeners;
import pages.loginPage;

public class LoginTest extends Listeners{
    
    @Test
    public void LogInTest() throws IOException {
    driver = initialiseDriver();
    loginPage log = new loginPage(driver);

    log.user("pooja@katchintech.com");
    log.pass("Cust@123");
    log.loginbt();
    log.logoutbt();
    driver.quit();
    }
}

Listeners class听众 class


import org.testng.ITestContext;
import org.testng.ITestListener;
import org.testng.ITestResult;

import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;

import resources.BaseClass;

public class Listeners extends BaseClass implements ITestListener{
    ExtentReports extent = ExtentReportGen.ExtentReportGenerator();
    
    public static ExtentTest test;
    
    @Override
    public void onTestStart(ITestResult result) {
        System.out.println("Test case :"+result.getName());
        test = extent.createTest(result.getName());
    }

    public void onTestSuccess(ITestResult result) {
        System.out.println("Test case passed :"+result.getName());
        test.log(Status.PASS, "Test case passed");
    }

    @Override
    public void onTestFailure(ITestResult result) {
        System.out.println("Test case failed :"+result.getName());

        test.fail(result.getThrowable());
    }

    @Override
    public void onTestSkipped(ITestResult result) {

    }

    @Override
    public void onTestFailedButWithinSuccessPercentage(ITestResult result) {

    }

    @Override
    public void onTestFailedWithTimeout(ITestResult result) {

    }

    @Override
    public void onStart(ITestContext context) {
        System.out.println("Execution started :"+context.getName());
    }

    @Override
    public void onFinish(ITestContext context) {
        System.out.println("Execution finished :"+context.getName());
        extent.flush();
    }
}

BaseClass基类


import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeTest;

import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.reporter.ExtentSparkReporter;

import io.github.bonigarcia.wdm.WebDriverManager;

public class BaseClass {
    public WebDriver driver;
    public ExtentReports extent = new ExtentReports();
    public ExtentSparkReporter spark;
    public ExtentTest test;
    
    @BeforeTest
    public WebDriver initialiseDriver() throws IOException {
        Properties prop = new Properties();
        FileInputStream fis = new FileInputStream("C:\\Users\\thora\\eclipse-workspace\\Biskane_NEW\\src\\main\\java\\resources\\data.properties");
        prop.load(fis);
        String browsername = prop.getProperty("browser");
        
        switch(browsername){ 
        case "chrome":
            WebDriverManager.chromedriver().setup();
            driver = new ChromeDriver();
            driver.get("https://qa.biskane.com/login");
            driver.manage().window().maximize();
            break;
        case "firefox":
            WebDriverManager.firefoxdriver().setup();
            driver = new FirefoxDriver();
            driver.get("https://qa.biskane.com/login");
            driver.manage().window().maximize();
            break;
        case "edge":
            WebDriverManager.edgedriver().setup();
            driver = new EdgeDriver();
            driver.get("https://qa.biskane.com/login");
            driver.manage().window().maximize();
            break;
        default:
            System.out.println("browser: " + browsername + " is invalid, launching FireFox browser as browser of choice..");
            WebDriverManager.firefoxdriver().setup();
            driver = new FirefoxDriver();
            driver.get("https://qa.biskane.com/login");
            driver.manage().window().maximize();
            break;
        }
        return driver;
    }
}

ExtentReportGen class ExtentReportGen class


import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.reporter.ExtentHtmlReporter;
import com.aventstack.extentreports.reporter.configuration.Theme;

public class ExtentReportGen {

    static ExtentReports extent ;
    
    public static ExtentReports ExtentReportGenerator() {
        String path = System.getProperty("user.dir")+"//ExtentReports//Biskanereport.html";

        ExtentHtmlReporter reporter = new ExtentHtmlReporter(path);


        reporter.config().setReportName("BiskaneTestReport");

        reporter.config().setTheme(Theme.STANDARD);

        extent = new ExtentReports();

        extent.attachReporter(reporter);

        extent.setSystemInfo("OS", "Windows");

        extent.setSystemInfo("Organization name", "Appzlogic");

        extent.setSystemInfo("Executed by", "...);


        return extent;
    }

}

I also have another problem where when I run the log in test class it opens 2 chrome windows, can you guys help me solve that?我还有另一个问题,当我运行登录测试 class 时,它会打开 2 chrome windows,你们能帮我解决这个问题吗?

Please try the below codes,请尝试以下代码,

   package com.auto.framework;
    
    import com.relevantcodes.extentreports.ExtentReports;
    import com.relevantcodes.extentreports.ExtentTest;
    import com.relevantcodes.extentreports.LogStatus;
    
    public class SampleReport {
    
        public static ExtentReports report;
        public static ThreadLocal<ExtentTest> test1 = new ThreadLocal<ExtentTest>();
    
        public static void startReporting() {
    
            report = new ExtentReports(
                    System.getProperty("user.dir") + "\\test-output\\extentReport\\ExtentReportResults.html");
    
        }
    
        public static void startTest(String testcaseName) {
            test1.set(report.startTest(testcaseName));
    
        }
    
        public static void endTest() {
            report.endTest(test1.get());
        }
    
        public static void endReporting() {
            report.flush();
        }
    
        public static void log(LogStatus logStatus, String msg) {
    
            test1.get().log(logStatus, msg);

        }
    
    }



Listeners :

    import org.testng.ITestContext;
import org.testng.ITestListener;
import org.testng.ITestResult;

import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;

import resources.BaseClass;

public class Listeners extends BaseClass implements ITestListener{
   
    
    @Override
    public void onTestStart(ITestResult result) {
        System.out.println("Test case :"+result.getName());
       SampleReport.startReporting();
    SampleReport.startTest(method.getName());
    }

    public void onTestSuccess(ITestResult result) {
        System.out.println("Test case passed :"+result.getName());
       SampleReport.log(LogStatus.PASS,"Test case passed");
    }

    @Override
    public void onTestFailure(ITestResult result) {
        System.out.println("Test case failed :"+result.getName());

       SampleReport.log(LogStatus.FAIL,"Test case failed ");
    }

    @Override
    public void onTestSkipped(ITestResult result) {

    }

    @Override
    public void onTestFailedButWithinSuccessPercentage(ITestResult result) {

    }

    @Override
    public void onTestFailedWithTimeout(ITestResult result) {

    }

    @Override
    public void onStart(ITestContext context) {
        System.out.println("Execution started :"+context.getName());
    }

    @Override
    public void onFinish(ITestContext context) {
        System.out.println("Execution finished :"+context.getName());
       SampleReport.endTest();
    SampleReport.endReporting();
    }
}

Have you tried debugging the test and see if the methods in the Listeners class has been called and if the those methods are executed or not?您是否尝试过调试测试并查看 Listeners class 中的方法是否已被调用以及这些方法是否已执行?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM