简体   繁体   中英

Unable to run testng.xml SELENIUM

i'm using Selenium WebDriver, eclipse, testng and surefire plugin. I am not able to run testng.xml file from pom.xml. While i'm running pom.xml using mvn test it directly run the file which is in the src/test/java/testCases . Kindly advise on my mistake. Thanks you in advance

My POM file :

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.test.maven</groupId>
    <artifactId>NumberGenerator</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>NumberGenerator</name>
    <!-- <url>http://maven.apache.org</url> -->
    <!-- <dependencies> -->
    <!-- <dependency> -->
    <!-- <groupId>junit</groupId> -->
    <!-- <artifactId>junit</artifactId> -->
    <!-- <version>4.11</version> -->
    <!-- <scope>test</scope> -->
    <!-- </dependency> -->
    <!-- </dependencies> -->

    <!-- <build> -->
    <!-- <plugins> -->
    <!-- <plugin> -->
    <!-- <groupId>org.apache.maven.plugins</groupId> -->
    <!-- <artifactId>maven-compiler-plugin</artifactId> -->
    <!-- <version>2.3.2</version> -->
    <!-- <configuration> -->
    <!-- <source>1.6</source> -->
    <!-- <target>1.6</target> -->
    <!-- </configuration> -->
    <!-- </plugin> -->
    <!-- </plugins> -->
    <!-- </build> -->
    <!-- Source directory configuration -->
    <build>
        <plugins>
            <!-- Following plugin executes the testng tests -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19</version>
                <configuration>
                    <!-- Suite testng xml file to consider for test execution -->
                    <suiteXmlFiles>
                        <suiteXmlFile>testng.xml</suiteXmlFile>
                        <!-- <suiteXmlFile>suites-test-testng.xml</suiteXmlFile> -->
                    </suiteXmlFiles>
                </configuration>
            </plugin>
            <!-- Compiler plugin configures the java version to be usedfor compiling 
                the code -->
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <!-- Dependency libraries to include for compilation -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.9.8</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.10</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

My testng.xml :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Automation_Sobet_WBG_YiWanCai_TestSuite">
  <test name="Testing">
    <classes>
       <class name="src/test/java/testCases.Automation_Sobet_WBG_YiWanCai"/>
    </classes>
  </test>
</suite>

My testCases :

package testCases;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;

import pageObjects.Home_Page;
import pageObjects.ProductListing_Page;
import utility.Constant; 
import utility.Log; 
import appModules.ProductSelectionConfirmation_Action;
import appModules.SignIn_ActionBuilder;

public class Automation_Sobet_WBG_YiWanCai {
    public WebDriver driver;


    // ******************** ABC  **********************//
    @Test(description = "ABC (复式)" , enabled = true)
      public void WBG_FuShi() throws Exception {
          try{
              driver = new FirefoxDriver();
              SignIn_ActionBuilder.Execute(driver);
              ProductListing_Page.select_Title(driver, 1).click();  
              ProductListing_Page.select_Title2(driver, 3).click();
              ProductSelectionConfirmation_Action.Pick_LotteryNum_All_Execute(driver, 6);
              SignIn_ActionBuilder.Logout_Session(driver);
              System.out.println("@ABC PASSES");
          }catch (Exception e){

              Log.error(e.getMessage());
              throw (e);
          }

      }

In your testNG.xml file you have to specify the fully qualified name not the path to your class. This below specified change should do the trick.

<classes>
   <class name="testCases.Automation_Sobet_WBG_YiWanCai"/>
</classes>

Also, I suggest you place the testng.xml file under the path src/test/resources/testng.xml and update it in the POM file as below.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19</version>
    <configuration>
    <!-- Suite testng xml file to consider for test execution -->
        <suiteXmlFiles>
            <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
        </suiteXmlFiles>
    </configuration>
</plugin>

If you are not using JUnit you can remove it from the POM file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM