maven - 将报告生成到时间戳文件夹时失败

标签 maven webdriver testng reportng

在讨论这个问题之前,我想先解释一下。 我有一个包含 4 个文件的基本项目:

该项目包含:

1.testbase01.java:包含准备测试初始参数的信息,例如:测试前获取驱动程序...

2.test01.java:包含一些测试,该类扩展自testbase01.java

3.test01.xml:包含测试文件test01.java的参数

4.pom.xml:包含测试报告存储位置、调用哪个xml套件进行测试、使用哪个监听器...

流程是:

我使用“mvn test”来运行项目 测试已运行但报告失败。 它无法将报告生成到我在 pom.xml (时间戳)中配置的指定文件夹。 我发现如果我将报告文件夹更改为固定名称(例如我的报告),它就可以工作。

你能帮我解决这个问题吗?

我不知道在哪里修复它。

谢谢

问题是:

    -------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running TestSuite
...
... TestNG 6.8.2beta_20130330_0839 by Cédric Beust (<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a2c1c7c6d0cbc1e2c0c7d7d1d68cc1cdcf" rel="noreferrer noopener nofollow">[email protected]</a>)
...

LOCAL URL IS http://192.168.10.26:8000/enigma/candidate/index#candidates
NAME= Hoang
[TestNG] Reporter org.uncommons.reportng.JUnitXMLReporter@584534b2 failed
org.uncommons.reportng.ReportNGException: Failed generating JUnit XML report.
    at org.uncommons.reportng.JUnitXMLReporter.generateReport(JUnitXMLReporter.java:83)
    at org.testng.TestNG.generateReports(TestNG.java:1115)
    at org.testng.TestNG.run(TestNG.java:1074)
    at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:217)
    at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:84)
    at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:92)
    at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:200)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
**Caused by: java.io.FileNotFoundException: D:\WORK\Workspace\bmp\test.reports\20131003-1346\xml\testsample.test01_results.xml (The system cannot find the path specified)**
    at java.io.FileOutputStream.open(Native Method)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:212)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:165)
    at java.io.FileWriter.<init>(FileWriter.java:90)
    at org.uncommons.reportng.AbstractReporter.generateFile(AbstractReporter.java:99)
    at org.uncommons.reportng.JUnitXMLReporter.generateReport(JUnitXMLReporter.java:77)
    ... 8 more
[TestNG] Reporter org.uncommons.reportng.HTMLReporter@41ce5a9 failed
org.uncommons.reportng.ReportNGException: Failed generating HTML report.
This is my first test
This is my second test
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 20.441 sec - in TestSuite
    at org.uncommons.reportng.HTMLReporter.generateReport(HTMLReporter.java:117)
    at org.testng.TestNG.generateReports(TestNG.java:1115)
    at org.testng.TestNG.run(TestNG.java:1074)
    at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:217)
    at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:84)
    at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:92)
    at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:200)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
Caused by: java.io.FileNotFoundException: D:\WORK\Workspace\bmp\test.reports\20131003-1346\html\index.html (The system cannot find the path specified)
    at java.io.FileOutputStream.open(Native Method)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:212)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:165)
    at java.io.FileWriter.<init>(FileWriter.java:90)
    at org.uncommons.reportng.AbstractReporter.generateFile(AbstractReporter.java:99)
    at org.uncommons.reportng.HTMLReporter.createFrameset(HTMLReporter.java:129)
    at org.uncommons.reportng.HTMLReporter.generateReport(HTMLReporter.java:104)
    ... 8 more

1.testbase01.java:

package common;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.ITestContext;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Parameters;

public class testbase01{ 

    @Parameters({"localurl"})
    @BeforeSuite(alwaysRun = true)
    public void beforeSuite(ITestContext context, String localurl){
    // get all UI controls
        System.out.println("LOCAL URL IS "+localurl);
        try
        {
            //init web driver
            WebDriver driver = new FirefoxDriver();
            driver.get(localurl);       

            // add driver into context. This is used for ScreenshotHTMLReporter
            context.setAttribute("driver", driver);     
        }
        catch (Exception ex)
        {
            Assert.assertTrue(false,ex.getMessage());
        }   
    }
}

2.test01.java:

package testsample;

import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

import common.TestBase;
import common.testbase01;

public class test01 extends testbase01 {

    @Parameters({"user"})
    @Test
    public void getUser(String user)
    {
        System.out.println("NAME= " + user);
    }

    @Test
    public void test01_no01()
    {
        System.out.println("This is my first test");

    }

    @Test
    public void test01_no02()
    {
        System.out.println("This is my second test");
    }

}

3.test01.xml:

<?xml version="1.0" encoding="UTF-8"?>
<suite name="test01" verbose="3" parallel="false">  
    <parameter name="localurl" value="http://192.168.10.26:8000/enigma/candidate/index#candidates"/>
    <test name="test01">        
        <parameter name="user" value="Hoang"/>
        <classes>
            <class name="testsample.test01"/>
        </classes>
    </test> 
</suite>

4.pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>BasicMavenProj</groupId>
    <artifactId>bmp</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <timestamp>${maven.build.timestamp}</timestamp>
        <maven.build.timestamp.format>yyyyMMdd-HHmm</maven.build.timestamp.format>
        <test.suite.dir>test.suites</test.suite.dir>
        <test.report.dir>test.reports</test.report.dir>
    </properties>


    <dependencies>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.8.5</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.33.0</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-server</artifactId>
            <version>2.33.0</version>
        </dependency>
        <dependency>
            <groupId>org.uncommons</groupId>
            <artifactId>reportng</artifactId>
            <version>1.1.2</version>
            <exclusions>
                <exclusion>
                    <groupId>org.testng</groupId>
                    <artifactId>testng</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
        <groupId>com.google.inject</groupId>
        <artifactId>guice</artifactId>
        <version>3.0</version>      
    </dependency>

    <dependency>
        <groupId>velocity</groupId>
        <artifactId>velocity</artifactId>
        <version>1.4</version>  
    </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.16</version>
                 <executions>
                    <execution>         
                        <goals>
                            <goal>test</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>${test.suite.dir}/test01.xml</suiteXmlFile>
                    </suiteXmlFiles>
                    <reportsDirectory>${test.report.dir}/${timestamp}</reportsDirectory>
                    <properties>
                    <property>
                        <name>usedefaultlisteners</name>
                        <value>false</value>
                    </property>
                     <property>
                        <name>listener</name>
                        <value>org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter</value>
                        <!-- <value>com.validant.enigma3.reports.ScreenshotHTMLReporter,org.uncommons.reportng.JUnitXMLReporter</value>-->
                    </property>
                </properties>

                <systemPropertyVariables>

                    <test.screenshot.dir>${test.report.dir}/${timestamp}</test.screenshot.dir>

                </systemPropertyVariables>


                </configuration>
            </plugin>       
        </plugins>      
    </build>

</project>

最佳答案

您是否尝试使用 ReportNG 以及 this 中所述的默认设置教程?我发现您的设置存在一些差异,因此请使其适用于默认设置,然后添加您自己的配置,以便您了解到底是什么导致了错误。

需要注意的是,Java 类的命名约定是 Camel Case第一个字母大写。

关于maven - 将报告生成到时间戳文件夹时失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19150742/

相关文章:

java - 在 Maven 子模块中使用 Spring @PropertySource

maven - 安装使用 mvn 原型(prototype) :create-from-project 创建的多模块原型(prototype)时出错

python-3.x - Selenium 与 Python-unittest - 测试返回进程已完成,退出代码为 0,并且不执行任何操作

angularjs - Protractor (WebDriverJS)无法切换到窗口。 nameOrHandle 未定义

python - 如何解决 PyTest 中的陈旧元素异常

Maven gwt :compile forks to a different Xmx

java - hibernatespatial 版本 4 的 Maven 存储库是否已关闭?

java - 尽管通过 @Test(testName = "sth") 设置测试名称,ITestResult getTestName() 返回 null

java - Mac 上的 TestNG 异常 : Cannot find class in classpath. ..!

java - 在 TestNG 和 Gradle 中包含(不排除)组