java - 使用 ExtentReports 3.2 jar java 为一套测试服中的多个 testng 套装/类/多个套装生成报告

标签 java testng extentreports

I'm new to ExtentReports. I have gone through many videos in youtube to generate reports using ExtentReports with above titled conditions but didn't find the exact answer for which I was looking for.

When tried to execute multiple classes in a testng suite it says nullpointerexception For suppose just assume suite contains 3 classes(Test cases). For first class execution goes smoothly. Once it jumps to the second class it says NullPointerException. Below is my code

注意:也尝试过 @BeforeTest 和 @AfterTest...

public class AppInit {

    public ExtentReports reports;
    public ExtentTest testInfo;
    public ExtentHtmlReporter htmlReporter;

    @BeforeSuite
    public void reportSetup() {
        htmlReporter = new ExtentHtmlReporter(new File(System.getProperty("user.dir") + "/AutomationReports.html"));
        htmlReporter.loadXMLConfig(new File(System.getProperty("user.dir") + "/src/resource/XML/Extent-Config.xml"));
        reports = new ExtentReports();
        htmlReporter.setAppendExisting(true);
        reports.setSystemInfo("Environment", "Automation");
        reports.attachReporter(htmlReporter);
    }

    @BeforeMethod
    public void testMethodName(Method method) {
        String testName = method.getName();
        testInfo = reports.createTest(testName);
    }

    @AfterMethod
    public void capture_TestStatus(ITestResult result) {
        try {
            if (result.getStatus() == ITestResult.SUCCESS) {
                testInfo.log(Status.PASS, "Test method " + "'" + result.getName() + "'" + result.getStatus());
            } else if (result.getStatus() == ITestResult.FAILURE) {
                testInfo.log(Status.FAIL, "Test method " + "'" + result.getName() + "'" + result.getStatus());
                testInfo.log(Status.FAIL, "Test error " + result.getThrowable());
            } else if (result.getStatus() == ITestResult.SKIP) {
                testInfo.log(Status.SKIP, "Test method " + "'" + result.getName() + "'" + result.getStatus());
            }

        } catch (Exception e) {    
            e.printStackTrace();    
        }
    }

    @AfterSuite
    public void generateReport() {
        reports.flush();
    }
}

异常/错误

Mar 30, 2018 10:21:07 PM main.java.com.xxx.yyy.framework.LogTestListener log INFO: test.java.com.xxx.yyy.tests.modules.zzz.explore.Attributes#serialNumber starting Mar 30, 2018 10:21:21 PM main.java.com.xxx.yyy.framework.LogTestListener log INFO: test.java.com.xxx.yyy.tests.modules.zzz.explore.Attributes#serialNumber completed Mar 30, 2018 10:21:21 PM main.java.com.xxx.yyy.framework.LogTestListener log INFO: test.java.com.xxx.yyy.tests.modules.zzz.explore.Capacity.aaa#poolName starting Mar 30, 2018 10:21:21 PM main.java.com.xxx.yyy.framework.LogTestListener log INFO: test.java.com.xxx.yyy.tests.modules.zzz.explore.Capacity.aaa#poolName skipped Mar 30, 2018 10:21:21 PM main.java.com.xxx.yyy.framework.LogTestListener log INFO: test.java.com.xxx.yyy.tests.modules.zzz.explore.Capacity.aaa#poolUsable starting Mar 30, 2018 10:21:21 PM main.java.com.xxx.yyy.framework.LogTestListener log INFO: test.java.com.xxx.yyy.tests.modules.zzz.explore.Capacity.aaa#poolUsable skipped Tests run: 9, Failures: 1, Errors: 0, Skipped: 7, Time elapsed: 38.356 sec <<< FAILURE! - in TestSuite testMethodName(test.java.com.xxx.yyy.tests.modules.zzz.explore.Capacity.aaa) Time elapsed: 14.078 sec <<< FAILURE! java.lang.NullPointerException: null at main.java.com.xxx.yyy.framework.AppInit.testMethodName(AppInit.java:178) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80) at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213) at org.testng.internal.Invoker.invokeMethod(Invoker.java:653) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111) at org.testng.TestRunner.privateRun(TestRunner.java:767) at org.testng.TestRunner.run(TestRunner.java:617) at org.testng.SuiteRunner.runTest(SuiteRunner.java:334) at org.testng.SuiteRunner.access$000(SuiteRunner.java:37) at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:368) at org.testng.internal.thread.ThreadUtil$2.call(ThreadUtil.java:64) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:748)

Results :

Failed tests: 
test.java.com.xxx.yyy.tests.modules.zzz.explore.Capacity.aaa.testMethodName(test.java.com.xxx.yyy.tests.modules.zzz.explore.Capacity.aaa)
  Run 1: aaa>AppInit.testMethodName:178 » NullPointer
  Run 2: PASS


Tests run: 7, Failures: 1, Errors: 0, Skipped: 5

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 43.588 s
[INFO] Finished at: 2018-03-30T22:21:22+05:30
[INFO] Final Memory: 21M/259M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test

(default-test) on project Framework: There are test failures. [ERROR] [ERROR] Please refer to C:\bbb\Project_Workspace\Framework\target\surefire-reports for the individual test results. [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

在maven中执行单个TestNg套装(具有多个类)。套房看起来像这样

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="ReportLibrary_Inventory_Test" parallel="tests">

    <listeners>
        <listener class-name="main.java.com.xxx.yyy.framework.LogTestListener"/>
    </listeners>

    <parameter name="browser" value="firefox" />
    <parameter name="sUsername" value="aaa" />
    <parameter name="sPassword" value="bbb" />

    <test name="zzz_ReportLibrary_Inventory" enabled="true" preserve-order="true" group-by-instances="true">
        <classes>
            <class name="test.java.com.aaa.yyy.tests.modules.zzz.reportlibrary.inventory.ccc"></class>
            <class name="test.java.com.aaa.yyy.tests.modules.zzz.reportlibrary.inventory.ddd"></class>
            <class name="test.java.com.aaa.yyy.tests.modules.zzz.reportlibrary.inventory.eee"></class>
            <!-- <class name="test.java.com.aaa.yyy.tests.modules.zzz.reportlibrary.inventory.Sample"></class> -->
            <class name="test.java.com.aaa.yyy.tests.modules.zzz.reportlibrary.inventory.fff"></class>
            <!-- <class name="test.java.com.aaa.yyy.tests.modules.zzz.reportlibrary.inventory.ggg"></class> -->
        </classes>
    </test>
</suite>

在maven(pom.xml)中执行多个testng套件

<suiteXmlFiles>
    <!-- <suiteXmlFile>src/resource/TestNg_XML/zzz_ReportLibrary_Inventory.xml</suiteXmlFile> -->
    <!-- <suiteXmlFile>src/resource/TestNg_XML/zzz_ReportLibrary_Summary_TableView.xml</suiteXmlFile> -->
    <suiteXmlFile>src/resource/TestNg_XML/zzz_Explore_Attributes.xml</suiteXmlFile>
    <!-- <suiteXmlFile>src/resource/TestNg_XML/zzz_All.xml</suiteXmlFile> -->
</suiteXmlFiles>

请帮我解决这个问题。我已经没有时间来交付了

提前致谢:)

Appint类代码

package main.java.com.xxx.zzz.framework;

import java.io.File;
import java.lang.reflect.Method;
import java.util.concurrent.TimeUnit;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathFactory;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.w3c.dom.Document;

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

import page.pageactions.LoginPageActions;
import page.pageactions.reportlibrarypageactions.ReportLibraryPageActions;
import test.java.com.xxx.zzz.tests.modules.centralizedManagement.Collecting;
import test.java.com.xxx.zzz.tests.modules.centralizedManagement.Modify_PollingInterval;

public class AppInit {

    public static WebDriver driver;
    public String convertStatus;
    public String className;
    public String testCase_MethodName;
    public final static int Timer_Web_Element_Show = 30;

    public static String retrievedUserEnteredbbbNamezzzUI;

    public ExtentReports reports;
    public ExtentTest testInfo;
    public ExtentHtmlReporter htmlReporter;

    // XML Parser
    public static String resBodyXMLFilesPath;
    public static File file;
    public static DocumentBuilderFactory dbFactory;
    public static DocumentBuilder dBuilder;
    public static Document doc;
    public static XPath xPath;

    @BeforeSuite
    public void reportSetup() {

        htmlReporter = new ExtentHtmlReporter(new File(System.getProperty("user.dir") + "/AutomationReports.html"));
        htmlReporter.loadXMLConfig(new File(System.getProperty("user.dir") + "/src/resource/XML/Extent-Config.xml"));
        reports = new ExtentReports();
        htmlReporter.setAppendExisting(true);
        reports.setSystemInfo("Environment", "Automation");
        reports.attachReporter(htmlReporter);

    }

    @BeforeSuite
    @Parameters({ "browser", "sUsername", "sPassword" })
    public void setup(String browser, String sUsername, String sPassword) throws Exception {

        DataProviders.getPropertyData();
        CommonMethods.deleteFilesFromDirectory("TestCaseResult_FolderPath");
        // CommonMethods.deleteFilesFromDirectory("DownloadedFiles_Path");

        // Check if parameter passed from TestNG is 'firefox'
        if (browser.equalsIgnoreCase("firefox")) {
            FirefoxProfile profile = new FirefoxProfile();
            profile.setPreference("browser.download.folderList", 2);
            profile.setPreference("browser.download.manager.showWhenStarting", false);
            profile.setPreference("browser.download.dir",
                    CommonMethods.relativePath("", "\\src\\resource\\Downloaded_Files"));
            profile.setPreference("browser.helperApps.neverAsk.openFile",
                    "application/log,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;");
            profile.setPreference("browser.helperApps.neverAsk.saveToDisk",
                    "application/log,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;");
            profile.setPreference("browser.helperApps.alwaysAsk.force", false);
            profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
            profile.setPreference("browser.download.manager.focusWhenStarting", false);
            profile.setPreference("browser.download.manager.useWindow", false);
            profile.setPreference("browser.download.manager.showAlertOnComplete", false);
            profile.setPreference("browser.download.manager.closeWhenDone", false);

            // create firefox instance
            // System.setProperty("webdriver.firefox.marionette",
            // ".\\geckodriver.exe");
            driver = new FirefoxDriver(profile);
        }
        // Check if parameter passed as 'chrome'
        else if (browser.equalsIgnoreCase("chrome")) {
            // set path to chromedriver.exe
            System.setProperty("webdriver.chrome.driver",
                    CommonMethods.relativePath("chromedriver.exe", "\\src\\lib\\"));
            // create chrome instance
            driver = new ChromeDriver();
        } else {
            // If no browser passed throw exception
            throw new Exception("Browser is not correct");
        }

        driver.get(CommonMethods.dp_DataCollector("url"));
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

        // Logging into zzz
        LoginPageActions.username(sUsername);
        LoginPageActions.password(sPassword);
        LoginPageActions.loginButton();


          Modify_PollingInterval.modify_TopologyPolling(); System.out.println(
          "Topology polling executed successfully");
          Modify_PollingInterval.modify_PerformancePolling();
          System.out.println("Performance Polling executed successfully");

          System.out.println("Modifying level and log file size started");
          CommonMethods.ssh_ExecuteCommand("Collector_UserName",
          "Collector_Password", "Collector_IP", "Collector_Port",
          "sed -i 's/INFO/FINEST/g' /opt/APG/Collecting/Collector-Manager/yyy-aaa/conf/logging.properties && (>&2 echo 'Success') || (>&2 echo 'Fail')"
          ); CommonMethods.ssh_ExecuteCommand("Collector_UserName",
          "Collector_Password", "Collector_IP", "Collector_Port",
          "sed -i 's/1048576/1000048576/g' /opt/APG/Collecting/Collector-Manager/yyy-aaa/conf/logging.properties  && (>&2 echo 'Success') || (>&2 echo 'Fail')"
          ); System.out.println("Modified level and log file size");

          System.out.println("Re-Starting collector manager started");
          CommonMethods.ssh_ExecuteCommand("Collector_UserName",
          "Collector_Password", "Collector_IP", "Collector_Port",
          "apg-collector-manager-yyy-aaa restart  && (>&2 echo 'Success') || (>&2 echo 'Fail')"
          ); CommonMethods.pauseTime(8); System.out.println(
          "Restarted collector manager");

          System.out.println("Verifying one successful poll");
          CommonMethods.polling_Check("Collector_UserName",
          "Collector_Password", "Collector_IP", "Collector_Port");
          System.out.println("One successful polling is done");

          System.out.println("Downloading the log file");
          CommonMethods.ssh_DownloadLogFile("Collector_UserName",
          "Collector_Password", "Collector_IP", "Collector_Port");
          System.out.println("Downloaded log file");

          CommonMethods.get_ResponceBodyfromLog(CommonMethods.
          retrieveLatestFileName_Downloaded().toString(),
          "CreateNew_LogFile_aaa", "StartPoint_aaa", "EndPoint_aaa");

          Collecting.dataBase_ImportPropertiesTask(); System.out.println(
          "Property store executed successfully");


        // Holding XML data in a doc for parsing it
        resBodyXMLFilesPath = System.getProperty("user.dir") + CommonMethods.dp_DataCollector("CreateNew_LogFile_aaa");
        file = new File(resBodyXMLFilesPath + ".xml");
        dbFactory = DocumentBuilderFactory.newInstance();
        dBuilder = dbFactory.newDocumentBuilder();
        doc = dBuilder.parse(file);
        doc.getDocumentElement().normalize();
        xPath = XPathFactory.newInstance().newXPath();

        retrievedUserEnteredbbbNamezzzUI = ReportLibraryPageActions.retrieveUserEnteredbbbName();
    }

    @BeforeMethod
    public void testMethodName(Method method) {

        String testName = method.getName();
        testInfo = reports.createTest(testName);

    }

    @AfterMethod
    public void capture_TestStatus(ITestResult result) {

        try {


            if (result.getStatus() == ITestResult.SUCCESS) {
                testInfo.log(Status.PASS, "Test method " + "'" + result.getName() + "'" + result.getStatus());
            } else if (result.getStatus() == ITestResult.FAILURE) {
                testInfo.log(Status.FAIL, "Test method " + "'" + result.getName() + "'" + result.getStatus());
                testInfo.log(Status.FAIL, "Test error " + result.getThrowable());
            } else if (result.getStatus() == ITestResult.SKIP) {
                testInfo.log(Status.SKIP, "Test method " + "'" + result.getName() + "'" + result.getStatus());
            }



        } catch (Exception e) {

            e.printStackTrace();

        }



    }

    @AfterSuite
    public void generateReport() {

        reports.flush();

    }

    @AfterSuite
    public void tearDown() {

        CommonMethods.pauseTime(5);

        // reports.flush();

        driver.quit();

    }

}

按照建议修改代码

public class AppInit implements ISuiteListener, IInvokedMethodListener {
    public void onStart(ISuite suite){

            //Extent Reports
            htmlReporter = new ExtentHtmlReporter(new File(System.getProperty("user.dir") + "/AutomationReports.html"));
            htmlReporter.loadXMLConfig(new File(System.getProperty("user.dir") + "/src/resource/XML/Extent-Config.xml"));
            reports = new ExtentReports();
            htmlReporter.setAppendExisting(true);
            reports.setSystemInfo("Environment", "Automation");
            reports.attachReporter(htmlReporter);

            DataProviders.getPropertyData();
            CommonMethods.deleteFilesFromDirectory("TestCaseResult_FolderPath");
            // CommonMethods.deleteFilesFromDirectory("DownloadedFiles_Path");

            // Check if parameter passed from TestNG is 'firefox'
            String getBrowserInput = suite.getParameter("browser");
            if (getBrowserInput.equalsIgnoreCase("firefox")) {
                FirefoxProfile profile = new FirefoxProfile();
                profile.setPreference("browser.download.folderList", 2);
                profile.setPreference("browser.download.manager.showWhenStarting", false);
                profile.setPreference("browser.download.dir",
                        CommonMethods.relativePath("", "\\src\\resource\\Downloaded_Files"));
                profile.setPreference("browser.helperApps.neverAsk.openFile",
                        "application/log,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;");
                profile.setPreference("browser.helperApps.neverAsk.saveToDisk",
                        "application/log,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;");
                profile.setPreference("browser.helperApps.alwaysAsk.force", false);
                profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
                profile.setPreference("browser.download.manager.focusWhenStarting", false);
                profile.setPreference("browser.download.manager.useWindow", false);
                profile.setPreference("browser.download.manager.showAlertOnComplete", false);
                profile.setPreference("browser.download.manager.closeWhenDone", false);

                // create firefox instance
                // System.setProperty("webdriver.firefox.marionette",
                // ".\\geckodriver.exe");
                driver = new FirefoxDriver(profile);
            }
            // Check if parameter passed as 'chrome'
            else if (getBrowserInput.equalsIgnoreCase("chrome")) {
                // set path to chromedriver.exe
                System.setProperty("webdriver.chrome.driver",
                        CommonMethods.relativePath("chromedriver.exe", "\\src\\lib\\"));
                // create chrome instance
                driver = new ChromeDriver();
            } else {
                // If no browser passed throw exception
                try {
                    throw new Exception("Browser is not correct");
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }

            driver.get(CommonMethods.dp_DataCollector("url"));
            driver.manage().window().maximize();
            driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

            // Logging into aaa
            String getUserName = suite.getParameter("sUsername");
            String getPassword = suite.getParameter("sPassword");
            LoginPageActions.username(getUserName);
            LoginPageActions.password(getPassword);
            LoginPageActions.loginButton();

            resBodyXMLFilesPath = System.getProperty("user.dir") + CommonMethods.dp_DataCollector("CreateNew_LogFile_bbb");
            file = new File(resBodyXMLFilesPath + ".xml");
            dbFactory = DocumentBuilderFactory.newInstance();
            try {
                dBuilder = dbFactory.newDocumentBuilder();
            } catch (ParserConfigurationException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            try {
                doc = dBuilder.parse(file);
            } catch (SAXException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            doc.getDocumentElement().normalize();
            xPath = XPathFactory.newInstance().newXPath();

            retrievedUserEnteredcccNameaaaUI = ReportLibraryPageActions.retrieveUserEnteredcccName();

        }

        public void onFinish(ISuite suite) {

            CommonMethods.pauseTime(5);

             reports.flush();

            driver.quit();

        }

        public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {

            String testName = method.getTestMethod().getMethodName();
            testInfo = reports.createTest(testName);

        }

        public void afterInvocation(IInvokedMethod method, ITestResult testResult) {
            if (testResult.getStatus() == ITestResult.SUCCESS) {
                testInfo.log(Status.PASS, "Test method " + "'" + testResult.getName() + "'" + testResult.getStatus());
            } else if (testResult.getStatus() == ITestResult.FAILURE) {
                testInfo.log(Status.FAIL, "Test method " + "'" + testResult.getName() + "'" + testResult.getStatus());
                testInfo.log(Status.FAIL, "Test error " + testResult.getThrowable());
            } else if (testResult.getStatus() == ITestResult.SKIP) {
                testInfo.log(Status.SKIP, "Test method " + "'" + testResult.getName() + "'" + testResult.getStatus());
            }

        }
}

删除监听器后的输出

[INFO] Scanning for projects... [INFO]
[INFO] ------------------------------------------------------------------------ [INFO] Building aaa 3.7-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ aaa --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 14 resources [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ aaa --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ aaa --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] skip non existing resourceDirectory C:\zzz\bbb\aaa\src\test\resources [INFO] [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ aaa --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 13 source files to C:\zzz\bbb\aaa\target\test-classes [INFO] [INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ aaa --- [INFO] Surefire report directory: C:\zzz\bbb\aaa\target\surefire-reports

------------------------------------------------------- T E S T S ------------------------------------------------------- Running TestSuite java.lang.NullPointerException at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:210) at org.openqa.selenium.support.ui.FluentWait.(FluentWait.java:94) at org.openqa.selenium.support.ui.WebDriverWait.(WebDriverWait.java:70) at org.openqa.selenium.support.ui.WebDriverWait.(WebDriverWait.java:44) at page.pageactions.CommonMethodsPageActions.clickOnUI(CommonMethodsPageActions.java:24) at test.java.com.xxx.yyy.tests.modules.ccc_ddd.reportlibrary.inventory.eee.poolName(eee.java:19) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80) at org.testng.internal.Invoker.invokeMethod(Invoker.java:714) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111) at org.testng.TestRunner.privateRun(TestRunner.java:767) at org.testng.TestRunner.run(TestRunner.java:617) at org.testng.SuiteRunner.runTest(SuiteRunner.java:334) at org.testng.SuiteRunner.access$000(SuiteRunner.java:37) at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:368) at org.testng.internal.thread.ThreadUtil$2.call(ThreadUtil.java:64) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:748) Tests run: 2, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 4.799 sec <<< FAILURE! - in TestSuite diskName(test.java.com.xxx.yyy.tests.modules.ccc_ddd.reportlibrary.inventory.disks) Time elapsed: 2.071 sec <<< FAILURE! java.lang.NullPointerException: null at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:210) at org.openqa.selenium.support.ui.FluentWait.(FluentWait.java:94) at org.openqa.selenium.support.ui.WebDriverWait.(WebDriverWait.java:70) at org.openqa.selenium.support.ui.WebDriverWait.(WebDriverWait.java:44) at page.pageactions.CommonMethodsPageActions.clickOnUI(CommonMethodsPageActions.java:24) at test.java.com.xxx.yyy.tests.modules.ccc_ddd.reportlibrary.inventory.disks.diskName(disks.java:21)

Results :

Failed tests: disks.diskName:21 » NullPointer

Tests run: 2, Failures: 1, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 9.667 s [INFO] Finished at: 2018-04-03T18:47:16+05:30 [INFO] Final Memory: 21M/259M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test (default-test) on project aaa: There are test failures. [ERROR] [ERROR] Please refer to C:\zzz\bbb\aaa\target\surefire-reports for the individual test results. [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

最佳答案

问题在于您使用 @BeforeSuite 的方式和@BeforeTest注释。

@BeforeSuite/@AfterSuite带注释的方法每个 <suite> 仅执行一次由 TestNG 标记。假设您的 <suite>包含两个或多个 <test>标签,即使这样 TestNG 也只会执行一次。

@BeforeSuite/@AfterSuite带注释的方法每个 <test> 仅执行一次由 TestNG 标记。假设您的 <test>包含两个或多个类,即使这样 TestNG 也只会执行它们一次。

看起来你所有的测试类基本上都扩展了类 AppInit .

所以仅适用于您的 <test> 中的第一个类@BeforeSuite@BeforeTest将被执行。从第二个类开始,它将被跳过,即使第二个类也具有该方法作为继承的一部分。

您需要采用不同的机制来使用 ExtentReports 。我建议您使用 TestNG 监听器,其中构建一个实现 org.testng.ISuiteListener 的监听器并移动您的@BeforeSuite/@AfterSuite逻辑到此监听器中,并在同一实现中,让您的类也实现 org.testng.IInvokedMethodListener并移动您的@BeforeMethod/@AfterMethod此实现中的逻辑。

最后,将此监听器连接到您的套件中。

关于java - 使用 ExtentReports 3.2 jar java 为一套测试服中的多个 testng 套装/类/多个套装生成报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49578543/

相关文章:

java - Java 中整数到 int[] 的转换

java - 如何以编程方式为 TestNG 创建测试?

java - 如何增加 ExtentReports 4.0.9 中屏幕截图缩略图的大小

selenium - 屏幕截图在 klov 报告中不可见

java - Maven 在 Java 7 项目中提示 "use -source 7 or higher to enable diamond operator"

java - 在 JAXB 生成中创建对象

java - TestNG - @BeforeMethod 用于特定方法

java - 用ant合并多个html文件

java - 如何在jsp页面调用jasper报表

java - Junit4 和 TestNG 在与 Maven 的一个项目中