Search code examples
mavenselenium-webdrivertestngpom.xmlmaven-surefire-plugin

TestNG tests are not getting run when I execute testng.xml using POM file using maven-surefire


0 tests are getting run, when I execute testng.xml using POM file using Maven-surefire.

I am running few selenium tests using testng.xml. When I run testng.xml file as TestNG test Suite, then it runs fine.

But, when I include testng.xml file (as below) then its not running :

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.14.1</version>
    <configuration>
        <suiteXmlFiles>
            <suiteXmlFile>testng.xml</suiteXmlFile>
        </suiteXmlFiles>
    </configuration>
</plugin>

Below is my POM file snippet:

    <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>SAPAutomation</groupId>
    <artifactId>SAPAutomation</artifactId>
    <!-- <version>3.2</version> -->
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>SAPAutomation</name>
    <url>http://maven.apache.org</url>

    <!-- For javadocs -->
    <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-eclipse-plugin</artifactId>
            <version>2.17</version>
            <configuration>
                <downloadSources>true</downloadSources>
                <downloadJavadocs>true</downloadJavadocs>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.14.1</version>
            <configuration>
                <suiteXmlFiles>
                    <suiteXmlFile>testng.xml</suiteXmlFile>
                </suiteXmlFiles>
            </configuration>
        </plugin>

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.3</version>
        <configuration>
            <source>1.8</source>
            <target>1.8</target>
        </configuration>
    </plugin>

     <!-- To exclude unwanted Package ex:  com.SAPAutomation.TEMP etc-->
     <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.6</version>
        <configuration>
          <excludes>
            <exclude>**/com/SAPAutomation/Temp/*</exclude>
          </excludes>
        </configuration>
      </plugin>
    </plugins>
    </build>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-picocontainer</artifactId>
            <version>1.1.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>1.1.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
              <groupId>org.seleniumhq.selenium</groupId>
              <artifactId>selenium-server</artifactId>
              <version>2.45.0</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-firefox-driver</artifactId>
            <version>2.45.0</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.11</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.11</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>1.9.2</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-core-asl</artifactId>
            <version>1.9.2</version>
        </dependency>
        <dependency>
            <groupId>com.googlecode.json-simple</groupId>
            <artifactId>json-simple</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.8.15</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>net.sourceforge.jtds</groupId>
            <artifactId>jtds</artifactId>
            <version>1.3.1</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
        </dependency>
        <dependency>
            <groupId>com.github.detro.ghostdriver</groupId>
            <artifactId>phantomjsdriver</artifactId>
            <version>1.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.codeartisans.thirdparties.swing</groupId>
            <artifactId>org-openide-util</artifactId>
            <version>8.6.2</version>
        </dependency>


    <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc14-10.2.0.4.0</artifactId>
            <version>10.2.0.4.0</version>
            <scope>system</scope>
            <systemPath>${basedir}/src/lib/ojdbc14.jar</systemPath>
      <!--      <systemPath>${java.home}/lib/ojdbc14.jar</systemPath> -->
      </dependency>

    <dependency>
        <groupId>org.monte.screenrecorder</groupId>
        <artifactId>MonteScreenRecorder</artifactId>
        <version>10</version>
        <scope>system</scope>
        <systemPath>${basedir}/src/lib/MonteScreenRecorder.jar</systemPath>
        <!-- <systemPath>${java.home}/lib/ojdbc14.jar</systemPath> -->
    </dependency>   

<!--        <repositories>
            <repository>
                <id>ojdbc14</id>
                <url>http://www.oracle.com/technetwork/apps-tech/jdbc-10201-088211.html</url>
            </repository>
        </repositories> -->

    </dependencies>
</project>

My testng.xml file:

<suite name="Suite" parallel="tests">
        <listeners>
            <listener class-name="com.SAPAutomation.Listners.RetryListener"/>
        </listeners>

  <test name="Test1">
        <parameter name="TestCaseId" value="TC1" />
        <classes>
          <class name="com.xyz.abc.MyAutomationTestByXML"/>
        </classes>
      </test> 

    <test name="Test2">
        <parameter name="TestCaseId" value="TC2" />
        <classes>
          <class name="com.xyz.abc.MyAutomationTestByXML"/>
        </classes>
    </test> 


    <test name="Test3">
        <parameter name="TestCaseId" value="TC3" />
        <classes>
          <class name="com.xyz.abc.MyAutomationTestByXML"/>
        </classes>
    </test> 
</suite>

Test result of running Pom.xml:

[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for SAPAutomation:SAPAutomation:jar:0.0.1-SNAPSHOT
[WARNING] 'dependencies.dependency.systemPath' for com.oracle:ojdbc14-10.2.0.4.0:jar should not point at files within the project directory, ${basedir}/src/lib/ojdbc14.jar will be unresolvable by dependent projects @ line 153, column 16
[WARNING] 'dependencies.dependency.systemPath' for org.monte.screenrecorder:MonteScreenRecorder:jar should not point at files within the project directory, ${basedir}/src/lib/MonteScreenRecorder.jar will be unresolvable by dependent projects @ line 162, column 15
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO] 
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building SAPAutomation 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ SAPAutomation ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\AutomationWorkSpace\SAPAutomation\src\main\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) @ SAPAutomation ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ SAPAutomation ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.3:testCompile (default-testCompile) @ SAPAutomation ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 35 source files to C:\AutomationWorkSpace\SAPAutomation\target\test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.14.1:test (default-test) @ SAPAutomation ---
[INFO] Surefire report directory: C:\AutomationWorkSpace\SAPAutomation\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running TestSuite
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.496 sec

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.137 s
[INFO] Finished at: 2015-04-09T15:01:01+00:00
[INFO] Final Memory: 24M/277M
[INFO] ------------------------------------------------------------------------

Kindly advise.

Issue still persists, even after giving full path of Testng.xml in my POM.xml file.

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.14.1</version>
            <configuration>
                <suiteXmlFiles>
                    <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
                </suiteXmlFiles>
            </configuration>
        </plugin>

[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for SAPAutomation:SAPAutomation:jar:0.0.1-SNAPSHOT
[WARNING] 'dependencies.dependency.systemPath' for com.oracle:ojdbc14-10.2.0.4.0:jar should not point at files within the project directory, ${basedir}/src/lib/ojdbc14.jar will be unresolvable by dependent projects @ line 154, column 16
[WARNING] 'dependencies.dependency.systemPath' for org.monte.screenrecorder:MonteScreenRecorder:jar should not point at files within the project directory, ${basedir}/src/lib/MonteScreenRecorder.jar will be unresolvable by dependent projects @ line 163, column 15
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO] 
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building SAPAutomation 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ SAPAutomation ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\AutomationWorkSpace\SAPAutomation\src\main\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) @ SAPAutomation ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ SAPAutomation ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 3 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.3:testCompile (default-testCompile) @ SAPAutomation ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 35 source files to C:\AutomationWorkSpace\SAPAutomation\target\test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.14.1:test (default-test) @ SAPAutomation ---
[INFO] Surefire report directory: C:\AutomationWorkSpace\SAPAutomation\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running TestSuite
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.501 sec

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.402 s
[INFO] Finished at: 2015-04-14T17:31:11+00:00
[INFO] Final Memory: 22M/167M
[INFO] ------------------------------------------------------------------------

Solution

  • You can place your testng.xml file under project directly with your pom file then it will execute your test suite.