当前位置: 首页 > 知识库问答 >
问题:

使用ExtentReports 3.2 jar java为多个testng套件/类/一套件中的多个套件生成报告

陶永望
2023-03-14

我是ExtentReports的新手。我浏览了youtube中的许多视频,使用ExtentReports生成具有上述标题条件的报告,但没有找到我正在寻找的确切答案。

当试图在一个testng套件中执行多个类时,它会说nullpointerexception(假设),假设套件包含3个类(测试用例)。因为一级执行很顺利。一旦跳到第二个类,它就会说NullPointerException。下面是我的代码

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();
    }
}

2018年3月30日10:21:07晚上main.java.com.xxx.yyy.framework.logTestListener日志信息:test.java.com.xxx.yyy.Tests.modules.zzz.explore.attributes#SerialNumber开始于2018年3月30日10:21:21晚上main.java.com.xxx.yyy.framework.logTestListener日志信息:test.java.com.xxx.yyy.modules.framework.logTestListener日志信息:.zzz.explore.capacity.AAA#PoolName starting 2018年3月30日10:21:21 PM main.java.com.xxx.yyy.framework.logTestListener日志信息:test.java.com.xxx.yyy.Tests.modules.zzz.explore.capacity.aaa#PoolName跳过2018年3月30日10:21:21 PM main.java.com.xxx.yyy.modules.zzz.explore.capacity.aaa.logTestListener日志信息:test.java.com.xxx.yyy.Tests.modules.zzz.explore.capacity.aaa#poolusable跳过的测试运行:9,失败S:1,错误:0,跳过:7,经过时间:38.356秒<<<失败!-在TestSuite testMethodName(test.java.com.xxx.yyy.tests.modules.zzz.explore.capacity.aaa)中,时间经过:14.078秒<<<失败!java.lang.nullPointerException:null at main.java.com.xxx.yyy.framework.appinit.testMethodName(appinit.java:178)at sun.reflect.nativeMethodAccessorImpl.Invoke0(原生方法)at在org.testng.internal.invoker.invokeConfigurationMethod(invoker.java:564),在org.testng.internal.invoker.invokeConfigurations(invoker.java:213),在org.testng.internal.invoker.invokeMethod(invoker.java:653),在org.testng.internal.invoker.invokeMethod(invoker.java:901),在testng.internal.testmethodworker.run(testmethodworker.java:111)位于org.testng。privaterun(testrunner.java:767)在org.testng.testrunner.run(testrunner.java:617)在org.testng.suiterunner.runtest(suiterunner.java:334)在org.testng.suiterunner.java:334)在org.testng.suiterunner.access$000(suiterunner.java:37)在org.testng.suiterunner.run(suiterunner.java:368)在a.util.concurrent.ThreadPoolExecutor.runworker(threadPoolExecutor.java:1142)在java.util.concurrent.threadPoolExecutor$worker.run(threadPoolExecutor.java:617)在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)在项目框架上:存在测试失败。[ERROR][ERROR]请参考C:\bbb\project_workspace\framework\target\surefire-reports获得单个测试结果。[ERROR]->[Help 1][ERROR][ERROR]要查看错误的完整堆栈跟踪,请使用-e开关重新运行Maven。[ERROR]使用-x开关重新运行Maven以启用完全调试日志记录。[ERROR][ERROR]有关错误和可能的解决方案的详细信息,请阅读以下文章:[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>
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]
[INFO]-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------in:2.6:resources(default-resources)@aaa----[INFO]使用'UTF-8'编码复制筛选的资源。[INFO]复制14个资源[INFO][INFO]----maven-compiler-plugin:3.1:compile(default-compile)@aaa----[INFO]没有什么要编译的----所有类都是最新的[INFO][INFO]----maven-resources-plugin:2.6:TestResources(default-testResources)@aaa----[INFO]使用'UTF-8'编码复制筛选的资源。[INFO]跳过不存在的资源目录c:\zzz\bbb\aaa\src\test\resources[INFO][INFO]----maven-compiler-plugin:3.1:testcompile(default-testCompile)@aaa----[INFO]检测到更改--重新编译模块![INFO]将13个源文件编译为C:\zzz\bbb\aaa\target\test-classes[INFO][INFO]----maven-surefire-plugin:2.18.1:test(default-test)@aaa----[INFO]Surefire报告目录:C:\zzz\bbb\aaa\target\surefire-reports

结果:

共有1个答案

左丘嘉木
2023-03-14

问题在于使用@beforeSuite@beforeTest注释的方式。

@beforeSuite/@afterSuite每个 标记只能由TestNG执行一次带注释的方法。因此,假设您的 包含两个或多个 标记,即使这样,TestNG也只执行一次。

@beforeSuite/@afterSuite每个 标记只能由TestNG执行一次带注释的方法。假设您的 包含两个或多个类,即使这样,TestNG也只执行一次。

因此,只有对于 中的第一个类,才会执行@beforeSuite@beforeTest。从第二个类开始,它将被跳过,即使第二个类也将该方法作为继承的一部分。

您需要采用不同的机制来使用ExtentReports。我建议您使用TestNG侦听器,其中构建一个实现org.TestNG.isuitelistener的侦听器,并将@beforeSuite/@afterSuite的逻辑移动到该侦听器中,在同一实现中,让您的类也实现org.TestNG.iInvokedMethodListener并将@beforeMethod@afterMethod的逻辑移动到该实现中。

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

 类似资料:
  • 我想在多个浏览器中运行同一组测试用例。为此,我将测试(每个测试针对单个浏览器)放在testng xml的一个套件下。运行之后,我从testng获得一个html报告,如果其中一个浏览器中出现测试失败,它在报告中不可见。还有别的办法吗?

  • 我有一个maven项目,有3个TestNG套件和4个测试类,我想在jenkins中运行一个特定的套件,我搜索了很多,但只找到了一个命令放在goal来指定特定的套件,但当我这样做时,它也会运行所有其他套件。我被困在这里很长时间了,请引导我完成这个过程。我还想知道是否有任何设置我可以这样做,如果我选择一个套件运行,我可以运行该套件的任何特定类。我已附上我的项目结构在这里的形象,任何输入将不胜感激。谢谢

  • 我正在尝试运行配置套件文件的并行测试。测试是针对使用Selenium的web应用程序。套件文件由多个测试组成。每个测试都包含多个测试类。每个测试中的第一个类用于初始化(@beforetest)WebDriver并关闭它(@aftertest)。WebDriver是静态的,以便将其传递给其他类(原因是我们需要从最后一个测试类结束的地方继续测试)。 当套件配置为按顺序运行测试时,测试将成功运行。但是当

  • 主套房.java 对于每个测试套件,都有包含@Test的类 例如 TestSuite1.java TestClass1.java 所以我的问题是如何运行TestSuite1、TestSuite2

  • 我有一个TestNG XML,格式如下: 这个套件有两个类,每个类都有一些@Test方法。现在我想让我的套件以同样的顺序再运行3次,就像它运行一样,即所有的class1方法,然后是class2方法。我怎样才能做到这一点?我正在使用Selenium WebDriver和核心Java来运行我的自动化套件。

  • 我试图用Cucumber,用不同的参数并行运行多个testng套件。对于每个tesng套件,我试图传递不同的浏览器、testinfo等等。我想通过maven命令行选项来实现这一点。我关注了https://rationaleemotions.wordpress.com/2016/03/29/parallel-execution-of-multiple-testng-suites/#comment-1