testng.xml is not running from pom.xml during executing selenium tests

10,090

Yes, The test class should end-up with Test [*Test] for Maven; By default you will see a class name AppTest.

No Changes in TestNG.xml; Make sure your POM file looks similar to the below :) [I have seen you questioning yesterday via Skype group chat]

<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>groupidhere</groupId>
  <artifactId>artifactidhere</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

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

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

  <build>
    <plugins>
    <plugin>
        <inherited>true</inherited>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
           <encoding>UTF-8</encoding>
        </configuration>
    </plugin>

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

  <dependencies>           
    <dependency>
    <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
    </dependency>           
    <dependency>
      <groupId>org.testng</groupId>
      <artifactId>testng</artifactId>
      <version>6.8</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-server</artifactId>
      <version>2.35.0</version>
    </dependency>
    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-java</artifactId>
      <version>2.35.0</version>
      </dependency>
      <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-firefox-driver</artifactId>
      <version>2.35.0</version>
    </dependency>           
  </dependencies>
</project>
Share:
10,090
Ripon Al Wasim
Author by

Ripon Al Wasim

[email protected] skype: ripon_sky

Updated on June 05, 2022

Comments

  • Ripon Al Wasim
    Ripon Al Wasim almost 2 years

    I have created Maven project in Eclipse for executing Selenium tests. I have written a TestSuite as testng.xml. I like to run this testng.xml from pom.xml.

    When I ran pom.xml (Right click pom.xml -> Maven test) the build was success, but no test was run. The test result is as follows:

    T E S T S

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

    My project structure is as follows:

    enter image description here

    My testng.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
    <suite name="Regression Test" verbose="2">
        <test name="Google" preserve-order="true">
            <classes>
                <class name="com.ripon.selenium.google.Abcd" />
                <class name="com.ripon.selenium.google.GoogleTest2" />
            </classes>
        </test>
    </suite>
    

    My 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>com.ripon.test</groupId>
      <artifactId>SeleniumTestMaven</artifactId>
      <version>0.0.1-SNAPSHOT</version>
    
      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      </properties>
    
      <build>
            <resources>
                <resource>
                    <directory>/src/test/resources</directory>
                    <filtering>true</filtering>
                </resource>
            </resources>
            <pluginManagement>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <configuration>
                            <source>1.7</source>
                            <target>1.7</target>
                        </configuration>
                        <version>2.3.2</version>
                    </plugin>
                </plugins>
            </pluginManagement>
        </build>
    
        <profiles>
            <profile>
                <id>selenium-tests</id>
                <build>
                    <plugins>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-surefire-plugin</artifactId>
                            <version>2.12.4</version>
                            <configuration>
                                <suiteXmlFiles>
                                    <suiteXmlFile>/src/test/resources/testng.xml</suiteXmlFile>
                                </suiteXmlFiles>
                            </configuration>
                        </plugin>
                    </plugins>
                </build>
            </profile>
        </profiles>
      <dependencies>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.8.8</version>
            <scope>test</scope>
        </dependency>
    
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.41.0</version>
            <scope>test</scope>
        </dependency>
      </dependencies>
    </project>
    
  • Ripon Al Wasim
    Ripon Al Wasim about 10 years
    Thanks niharika_neo. But It works with or without slash (/). Main issues is for file name: postfix of file should be "Test"
  • niharika_neo
    niharika_neo about 10 years
    As far as I know, the suite xml file is the thing that guides what classes to execute and not the naming conventions. Annotations identify tests. I regularly run tests from classes which do not contain the Test in the class name. I somehow feel your suite xml file is not being referred still.
  • Ripon Al Wasim
    Ripon Al Wasim about 10 years
    When I used Ant and TestNG, class naming convention is not a matter.
  • niharika_neo
    niharika_neo about 10 years
    Yes, I am using maven.
  • Ripon Al Wasim
    Ripon Al Wasim about 10 years
    Is your class name without postfix "Test"?
  • niharika_neo
    niharika_neo about 10 years
    Yep, just to try out i purposefully renamed it to something without a test and the test ran successfully when i did mvn test with my suite xml specified.
  • niharika_neo
    niharika_neo about 10 years
    Can you check if you increase the verbosity in your xml, does it reflect in the output just to see if your xml is being read?
  • Ripon Al Wasim
    Ripon Al Wasim about 10 years
    Can you please provide your pom.xml and testng.xml?
  • niharika_neo
    niharika_neo about 10 years
    <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.16</version> <configuration> <suiteXmlFiles> <suiteXmlFile>src/test/resources/TestNG-Params.xml</su‌​iteXmlFile> </suiteXmlFiles> </configuration> </plugin>
  • niharika_neo
    niharika_neo about 10 years
    Testng xml : <suite name="My Suite1" parallel="methods" thread-count="5" > <test verbose="2" name="Default1 test"> <parameter name="name" value="NotNiharika"></parameter> <parameter name="fname" value="Niharika"></parameter> <classes> <class name="com.nv.demo.testngtests.Params"/> </classes> </test> </suite>
  • niharika_neo
    niharika_neo about 10 years
    Apologies for the delay. Busy day!