Selenium extentTestLogs不是extentReport中的首选项

Selenium extentTestLogs不是extentReport中的首选项,selenium,testing,selenium-webdriver,testng.xml,Selenium,Testing,Selenium Webdriver,Testng.xml,我想在测试报告中报告测试日志。我在ItestListner和测试类中也调用了extentReportManager实用程序。在测试类中调用扩展数据块报告对象时,不执行测试,只打开浏览器。但是,当它仅在Itestlistner中调用时,测试将执行。但testName只打印在报告中 有人能帮忙吗 TestClass package com.selenium.tests; import static org.testng.Assert.assertEquals; import java.io.I

我想在测试报告中报告测试日志。我在ItestListner和测试类中也调用了extentReportManager实用程序。在测试类中调用扩展数据块报告对象时,不执行测试,只打开浏览器。但是,当它仅在Itestlistner中调用时,测试将执行。但testName只打印在报告中

有人能帮忙吗

TestClass

 package com.selenium.tests;

import static org.testng.Assert.assertEquals;

import java.io.IOException;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import com.selenium.pageObjects.DashBoard;
import com.selenium.pageObjects.RecentActivity;
import com.selenium.pageObjects.Setting;
import com.selenium.pageObjects.SignIn;
import com.selenium.resources.ExtentReportManager;
import com.selenium.resources.base;

import junit.framework.Assert;

public class IcarxTests extends base {
    public WebDriver driver;
    SignIn signIn;
    String getTitle;
    DashBoard dashboard;
    RecentActivity recentActivity;
    ExtentReports extent = ExtentReportManager.getExtentReport();
    public ExtentTest test;

    @BeforeTest
    public void intializeDriver() throws IOException {

        driver = browserIntilization();
        test.info("browser is launched sucessfully");

        driver.get(prop.getProperty("Application_url"));
        test.info(prop.getProperty("Application_url") + "is launched successfully");
    }

    @Test(priority = 1)
    @Parameters({ "Market", "Language" })
    public void setting(String marketStr, String languageStr) throws IOException, InterruptedException {
        System.out.println("1 test");

        Setting setting = new Setting(driver);
        setting.selectMarket(marketStr);
        test.info(marketStr + "is selected");
        setting.selectLanguage(languageStr);
        test.info(languageStr + "is selected");
        Thread.sleep(5000);
        signIn = setting.navigateSignIn();
        test.info("Navigated to signIn page sucessfully");
        getTitle = signIn.getPageTitle();
        Assert.assertEquals("ICAR-X", getTitle);
        test.log(Status.PASS, "Sigin page tile" +getTitle+" is verified");
    }

    @Test(priority = 2)
    @Parameters({ "dealerID", "userID", "password" })
    public void login_Success(String dealerStr, String userIDStr, String passwordStr) throws InterruptedException {
        System.out.println("2 test");

        signIn.enterDealerID(dealerStr);

        signIn.enterUserID(userIDStr);

        signIn.enterPassword(passwordStr);

        dashboard = signIn.naviagateDashBoard();
        Thread.sleep(5000);

    }
扩展端口实用程序

package com.selenium.resources;

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


public class ExtentReportManager {
    
    public static ExtentSparkReporter reporter;
    public static ExtentReports extent;
    public static ExtentTest test;
    
    public static ExtentReports getExtentReport() {
        
        String filePath = System.getProperty("user.dir")+"\\reports\\extentReport.html";
        ExtentSparkReporter reporter = new ExtentSparkReporter(filePath);
        reporter.config().setDocumentTitle("Automation Test Report");
        reporter.config().setReportName("ICAR Test Automation Report");
        reporter.config().setTheme(Theme.STANDARD);
        ExtentReports extent = new ExtentReports();
        extent.attachReporter(reporter);
                
        return extent;
    }

}

    **ITestListenr code**
    
   

 package com.selenium.listeners;

import java.io.IOException;

import org.openqa.selenium.WebDriver;
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 com.selenium.resources.ExtentReportManager;
import com.selenium.resources.base;

public class Listeners extends base implements ITestListener {
    
    ExtentReports extent = ExtentReportManager.getExtentReport();
    public ExtentTest test;
    

    @Override
    public void onFinish(ITestContext arg0) {
        extent.flush();
        
    }

    @Override
    public void onStart(ITestContext arg0) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public void onTestFailedButWithinSuccessPercentage(ITestResult arg0) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public void onTestFailure(ITestResult result) {
        test.fail(result.getThrowable());
        String testMethod = result.getMethod().getMethodName();
        WebDriver driver = null;
        try {
            driver =(WebDriver)result.getTestClass().getRealClass().getDeclaredField("driver").get(result.getInstance());
        } catch(Exception e)
        {
            
        }
        
        try {
            String destinationPath = getScreenShotPath(testMethod, driver);
            
            test.addScreenCaptureFromPath(destinationPath, testMethod);
            
            
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        test.log(Status.FAIL, testMethod + "Test is Failed");
        
    }

    @Override
    public void onTestSkipped(ITestResult result) {
        String testMethod = result.getMethod().getMethodName();
        test.log(Status.SKIP, testMethod);
        
        
    }

    @Override
    public void onTestStart(ITestResult result) {
        String testMethod = result.getMethod().getMethodName();
        test = extent.createTest(result.getMethod().getMethodName());
        test.log(Status.PASS, testMethod + "Test is Started");
        
        
    }

    @Override
    public void onTestSuccess(ITestResult result) {
        String testMethod = result.getMethod().getMethodName();
        test.log(Status.PASS, testMethod + "Test is Passed");
        
    }

}