0

我已经构建了一个使用 Selenium Grid 和 TestNG 的小型测试框架,我想让它支持 ExtentReports 3 的并行执行报告,并根据将要运行的 TestSuite 的名称创建一个本地动态命名的文件。最后的想法是运行一个包含多个类的 TestSuite,每个类只包含 1 个测试,由 @Test 注释定义。

<suite>
 <test name="environment1">
  <parameter name="X" value="Y"/>
 <classes>
  <class name="Class containing Test A"/>
  <class name="Class containing Test B"/>
  <class name="Class containing Test C"/>
 </classes>
 </test>
</suite>

这些测试是 UI 测试,整个测试套件可能需要大约 2 小时才能完成。当一个 TestSuite 完成时,将生成一个 ExtentReport html 报告,其中包含每个测试的结果。

我想要做的是开始运行一个测试套件,然后开始运行另一个相同的测试套件,与第一个测试套件的执行并行,但是在不同的环境中,当它们完成时我想要两个不同的报告。目前,如果我尝试简单地执行此操作,一份报告将覆盖另一份报告。

有人可以给我一些关于如何实现这个目标的指导吗?

我已经尝试实现此处显示的示例:http: //extentreports.com/docs/versions/3/java/#extent-testng-report-builder 但是,Eclipse 通知我 The method createNode(String) is undefined for the type Object 在此处输入图像描述

下面,我提供了我的基本测试配置文件:

import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Parameters;

import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.markuputils.ExtentColor;
import com.aventstack.extentreports.markuputils.MarkupHelper;
import com.aventstack.extentreports.reporter.ExtentHtmlReporter;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.PageFactory;
import org.testng.ITestResult;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;

public class TestSuiteBase {
    protected WebDriver driver;
    protected SearchPageFactory search;
    public static ExtentHtmlReporter htmlreporter;
    public static ExtentReports extent;
    public static ExtentTest test;

    @BeforeSuite
    public void SetUp() {
        htmlreporter = new ExtentHtmlReporter(System.getProperty("user.dir") + "/test-output/MyReport.html");
        System.out.println(System.getProperty("user.dir"));
        extent = new ExtentReports();
        extent.attachReporter(htmlreporter);
    }

    @Parameters({ "platform","browser", "url" })
    @BeforeClass(alwaysRun=true)
    public void setup(String platform, String browser, String url) throws MalformedURLException
    {       
        driver = getDriverInstance(platform, browser, url);
        search = PageFactory.initElements(driver, SearchPageFactory.class);
    }

    public static WebDriver getDriverInstance(String platform, String browser, String url)
            throws MalformedURLException {

        String nodeURL = "http://localhost:4444/wd/hub";
        WebDriver driver = null;
        DesiredCapabilities capabilities = new DesiredCapabilities();

        // Platforms
        if (platform.equalsIgnoreCase("Windows")) {
            capabilities.setPlatform(Platform.WINDOWS);
        }
        if (platform.equalsIgnoreCase("MAC")) {
            capabilities.setPlatform(Platform.MAC);
        }
        // Browsers
        if (browser.equalsIgnoreCase("chrome")) {
            capabilities = DesiredCapabilities.chrome();
        }
        if (browser.equalsIgnoreCase("firefox")) {
            capabilities = DesiredCapabilities.firefox();
        }
        if (browser.equalsIgnoreCase("ie")) {
            capabilities = DesiredCapabilities.internetExplorer();
        }

        driver = new RemoteWebDriver(new URL(nodeURL), capabilities);

        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        // Open the Application
        driver.get(url);
        return driver;
    }

    @AfterMethod
    public void getResult(ITestResult result) {
        if (result.getStatus()== ITestResult.FAILURE) {
            test.fail(MarkupHelper.createLabel(result.getName() + " Test case failed ", ExtentColor.RED));
            test.fail(result.getThrowable());
        } else if (result.getStatus()== ITestResult.SUCCESS){
            test.pass(MarkupHelper.createLabel(result.getName() + " Test case failed ", ExtentColor.GREEN));
        } else {
            test.skip(MarkupHelper.createLabel(result.getName() + " Test case failed ", ExtentColor.YELLOW));
            test.skip(result.getThrowable());
        }
    }

    @AfterSuite
    public void testDown() {
        extent.flush();
    }

    @AfterClass
    public void afterClass() {
        driver.quit();
    }
}

我是编程和自动化领域的新手,因此,对于这项工作的任何帮助或建议,特别是或一般来说,将不胜感激。先感谢您!

4

1 回答 1

0

如果您为每个班级提供相同的报告名称,根据班级功能为每个报告提供不同的名称,则可能会发生这种情况。

所有这三个类都应包含唯一的报告名称,

 <class name="Class containing Test A"/>
 <class name="Class containing Test B"/>
 <class name="Class containing Test C"/>
于 2018-06-05T04:50:07.130 回答