无法运行testng.xml SELENIUM

时间:2015-11-03 03:54:58

标签: java maven selenium automation

我正在使用Selenium WebDriver,eclipse,testng和surefire插件。我无法从pom.xml运行testng.xml文件。当我使用mvn test运行pom.xml时,它直接运行 src / test / java / testCases 中的文件。请告知我的错误。提前谢谢你

我的POM文件:

<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>

我的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>

我的测试用例:

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);
          }

      }

1 个答案:

答案 0 :(得分:0)

在testNG.xml文件中,您必须指定完全限定名称,而不是类的路径。以下指定的更改应该可以解决问题。

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

另外,我建议您将testng.xml文件放在路径src/test/resources/testng.xml下,并在POM文件中更新,如下所示。

<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>

如果您不使用JUnit,可以将其从POM文件中删除。