subin
subin

Reputation: 71

TestNG test result console is blank only if I run the test cases using Maven(Test)

I have created a maven project for my automation selenium script and added all the required dependencies to pom.xml. If I do the maven build(Test), test cases which I mentioned in TestNG.xml is running fine. But TestNG test result console is blank. It doesn't say any information about how many cases got executed and how many passed? Though Eclipse console output is having the test status.

TestNG.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite guice-stage="DEVELOPMENT" name="Default suite" >
  <test verbose="2" name="Default test" >
    <classes >
      <class name="automation.BrowserNavigation"/>
    </classes>
  </test> <!-- Default test -->
</suite> <!-- Default suite -->
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>TupasRegression</groupId>
  <artifactId>TupasRegression</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <resources>
      <resource>
        <directory>src</directory>

      </resource>
    </resources>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.5.1</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>

      <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19.1</version>
    <configuration>
        <suiteXmlFiles>
            <suiteXmlFile>src/TestNG.xml</suiteXmlFile>
        </suiteXmlFiles>
    </configuration>
</plugin>
    </plugins>

  </build>

  <profiles>

</profiles>
<dependencies>
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>2.53.0</version>
</dependency>
  <dependency>
              <groupId>org.apache.poi</groupId>
              <artifactId>poi</artifactId>
              <version>3.14</version>
              <scope>compile</scope>
           </dependency>
           <dependency>
              <groupId>org.apache.poi</groupId>
              <artifactId>poi-examples</artifactId>
              <version>3.14</version>
              <scope>compile</scope>
           </dependency>
               <dependency>
              <groupId>org.apache.poi</groupId>
              <artifactId>poi-excelant</artifactId>
              <version>3.14</version>
              <scope>compile</scope>
           </dependency>



          <dependency>
                 <groupId>org.apache.poi</groupId>
                 <artifactId>poi-ooxml</artifactId>
                 <version>3.14</version>
                 <scope>compile</scope>
          </dependency>
          <dependency>
                 <groupId>org.apache.poi</groupId>
                 <artifactId>poi-ooxml-schemas</artifactId>
                 <version>3.14</version>
                 <scope>compile</scope>
          </dependency>
          <dependency>
                 <groupId>org.apache.poi</groupId>
                 <artifactId>poi-scratchpad</artifactId>
                 <version>3.14</version>
                 <scope>compile</scope>
          </dependency>




<!-- </dependency> -->


          <dependency>
                 <groupId>org.apache.poi</groupId>
                 <artifactId>openxml4j</artifactId>
                 <version>1.0-beta</version>
          </dependency>

     <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.3.1</version>
        </dependency>


</dependencies>
</project>

Eclipse Console Output TestNG result page

Upvotes: 1

Views: 2678

Answers (3)

Peter
Peter

Reputation: 11

It is possible to show the test results in the Maven build console output.

1) create a testng.xml file, which outlines your test classes.

To do in eclipse you right click your maven project then select TESTNG > Convert to TestNG.

2) Update your Maven POM file to include the relevant dependencies and plugins. The key configuration is the Maven surefire plugin which is configured to point to your testng.xml file.

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.45.0</version>
    </dependency>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.8</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <!-- Following plugin executes the testng tests -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.14.1</version>
            <configuration>
                <!-- Suite testng xml file to consider for test execution -->
                <suiteXmlFiles>
                    <suiteXmlFile>testng.xml</suiteXmlFile>

                </suiteXmlFiles>
            </configuration>
        </plugin>
        <!-- Compiler plugin configures the java version to be usedfor compiling 
            the code -->
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
        </plugin>
    </plugins>
</build>

3) Run a Maven test and the TestNG results will appear in the Maven output console.

Upvotes: 0

niharika_neo
niharika_neo

Reputation: 8531

The testng console that you show in the screenshot will not show any results - that is a testng plugin provided console and it will only show results if you choose to run your tests or suite with the Run As -> TestNG (suite/test) options.

When you are running through maven, the testng plugin doesn't get exercised and hence you do not see anything in the console. If you need results of this run, you need to check the test-results folder in the target folder generated by maven.

Upvotes: 2

Tung Thanh
Tung Thanh

Reputation: 36

I had the same problem. I think my answer is not the way to fix it, but you can see how many cases got executed and how many passed in the index.html by running it on browser, this file is in test-output folder. Each time you run testcases, TestNG will update this file.

Upvotes: 0

Related Questions