![](/img/trans.png)
[英]Selenium Webdriver : How to run testNG.xml file in Terminal (in MAC)?
[英]Unable to run testng.xml SELENIUM
我正在使用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);
}
}
在您的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文件中刪除。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.