Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
数据块报告4-Java_Java_Report_Extent - Fatal编程技术网

数据块报告4-Java

数据块报告4-Java,java,report,extent,Java,Report,Extent,尝试生成一个区段报告,这将允许我运行一套测试类,并将输出作为一个报告 下面我的当前代码运行fin,它将运行我的testNG.xml文件并成功运行我套件中的所有测试类。然而,扩展报告本身似乎只保存最后运行的测试用例。我一辈子都不知道如何阻止它被覆盖,而是附加到它上面。较旧版本的数据块报告使用htmlreporter.setAppendExisting(true);但这在范围4中并不存在 public class ExtentManager { ExtentHtmlReporter html

尝试生成一个区段报告,这将允许我运行一套测试类,并将输出作为一个报告

下面我的当前代码运行fin,它将运行我的testNG.xml文件并成功运行我套件中的所有测试类。然而,扩展报告本身似乎只保存最后运行的测试用例。我一辈子都不知道如何阻止它被覆盖,而是附加到它上面。较旧版本的数据块报告使用htmlreporter.setAppendExisting(true);但这在范围4中并不存在

public class ExtentManager {
    ExtentHtmlReporter htmlReporter;
    ExtentReports extent;
    ExtentTest parentTest;
    ExtentTest childTest;
    DriverManager driverManager;
    WebDriver driver;
    Screenshot screenshot;
    Properties config;
    String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());

    /** Suite test as it will run, with Before/After instructions*/
    @BeforeTest
    public void beforeTest() throws IOException {
        /**Create extent reports and configure html report*/
        htmlReporter = new ExtentHtmlReporter(".//reports/ExtentReport"+timeStamp+".html");
        extent = new ExtentReports();
        extent.attachReporter(htmlReporter);
        htmlReporter.config().setTheme(Theme.DARK);
        htmlReporter.config().setDocumentTitle("Automation Testing");
        htmlReporter.config().setReportName("My Report");
        htmlReporter.config().setAutoCreateRelativePathMedia(true);
        htmlReporter.config().setTimeStampFormat("HH:mm:ss");
        screenshot = new Screenshot();
        config = new Properties();
        FileInputStream fis = new FileInputStream(System.getProperty("user.dir") + "/src/main/resources/Config.properties");
        config.load(fis);
    }

    public ExtentReports getExtent(){
        if(extent != null){
            return this.extent;
        } else {
            return new ExtentReports();
        }
    }

    @BeforeClass
    public void beforeClass() {
        /**Setup parent test, all child tests to follow
         *will attach to it for html report*/
        extent = getExtent();
        parentTest = extent.createTest(getClass().getSimpleName());
        driverManager = new DriverManager();
        driver = driverManager.getWebDriver();
        driver.manage().timeouts().pageLoadTimeout(15, TimeUnit.SECONDS);
    }

    @AfterMethod
    public void getResult(ITestResult result) throws IOException {
        if (result.getStatus() == ITestResult.SUCCESS){
            childTest.log(Status.PASS, MarkupHelper.createLabel("Test Case: " + result.getName() + " PASSED", ExtentColor.GREEN));
        }else if(result.getStatus() == ITestResult.FAILURE){
            String screenshotPath = screenshot.getScreenshot(driver, result.getName());
            childTest.log(Status.FAIL, MarkupHelper.createLabel("Test Case: " + result.getName() + " FAILED", ExtentColor.RED));
            childTest.fail(result.getThrowable().getMessage());
            childTest.log(Status.WARNING, "Error screenshot captured and stored @ " + screenshotPath);
            childTest.addScreenCaptureFromPath(screenshotPath);
        }else if(result.getStatus() == ITestResult.SKIP){
            childTest.log(Status.SKIP, MarkupHelper.createLabel("Test Case: " + result.getName() + " SKIPPED", ExtentColor.AMBER));
            childTest.log(Status.SKIP, "Skipped test: " + result.getName());
        }
    }

    @AfterTest
    public void afterTest(){
        driverManager.quitWebDriver();
    }

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

您可以使用数据块报告适配器,无需编写任何代码,请参阅下面的文章。在您的情况下,您将需要使用TestNG适配器-


试试这个:`

您可以使用扩展报告适配器,这样就不需要编写任何代码了,请查看下面的文章。在您的情况下,您将需要使用TestNG适配器-


试试这个:`

我的代码也放在@BeforeSuite中,这没有什么区别。因此,由于上面的代码不起作用,我暂时恢复到extent reports 3,并使用htmlReporter.setAppendExisting(true)使用v3;我的代码也放在@BeforeSuite中,这没有什么区别。因此,由于上面的代码不起作用,我暂时恢复到extent reports 3,并使用htmlReporter.setAppendExisting(true)使用v3;
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="sanity_tests" parallel="false" verbose="10">
    <test name="test1" parallel="false" preserve-order="true" verbose="10">
        <classes>
            <class name="com.testFramework.Tests.test1"/>
        </classes>
    </test>
    <test name="test2" parallel="false" preserve-order="true" verbose="10">
        <classes>
            <class name="com.testFramework.Tests.test2"/>
        </classes>
    </test>

</suite>