2

Before talking about the issue, I want to explain something first. I have a basic project with 4 files:

The project contains:

1.testbase01.java: contains information to preparing for initial parameter of testing like: get driver before testing...

2.test01.java: contains some tests and this class extends from testbase01.java

3.test01.xml: contains parameter for test file test01.java

4.pom.xml: contains where to store test report, which xml suite is called for testing, which listener is using...

The flow is:

I use 'mvn test' to run project Test is run but the report is failed. It cannot generate report to specified folder as I configured in pom.xml (timestamp). I found that if I change the report folder to a fixed name (my report for example), it works.

Can you help me to fix this issue?

I dont know where to fix it.

Thank you

The issue is:

    -------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running TestSuite
...
... TestNG 6.8.2beta_20130330_0839 by Cédric Beust (cedric@beust.com)
...

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>
Hoang Vo
  • 75
  • 1
  • 8

1 Answers1

2

Did you try using ReportNG with default settings like described in this tutorial?I see some differences in your settings, so make that work for default settings and then you add your own configuration so you will what exactly caused your error.

One note - convention for naming Java classes is Camel Case with first letter in capital.

Petr Mensik
  • 26,874
  • 17
  • 90
  • 115