2017-10-13 78 views
0

我有一個TestNG的劇本在我的Maven項目,但是當我執行mvn test該腳本不執行不執行TestNG的文件中的Maven

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

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

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

    <dependencies> 
     <dependency> 
      <groupId>org.seleniumhq.selenium</groupId> 
      <artifactId>selenium-java</artifactId> 
      <version>3.5.3</version> 
     </dependency> 
     <dependency> 
      <groupId>org.testng</groupId> 
      <artifactId>testng</artifactId> 
      <version>6.11</version> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 
</project> 

這裏是我的腳本的測試包

package test; 

import java.util.concurrent.TimeUnit; 

import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.chrome.ChromeDriver; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import org.testng.annotations.AfterMethod; 
import org.testng.annotations.BeforeMethod; 
import org.testng.annotations.Test; 

public class Login { 

    public static WebDriver driver; 
    public String baseUrl; 

    @BeforeMethod 
    public void beforeMethod() throws Exception { 



     //System.setProperty("webdriver.chrome.driver", "chromedriver_win32\\chromedriver.exe"); 
     //driver = new ChromeDriver(); 

     System.setProperty("webdriver.gecko.driver", "geckodriver-v0.18.0-win64\\geckodriver.exe"); 
     driver = new FirefoxDriver(); 

     baseUrl = "https://www.google.lk/"; 
     driver.manage().window().maximize(); 
     driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 

    } 

    @Test 
    public void login() throws Exception { 
     driver.get(baseUrl); 
     driver.findElement(By.xpath("//input[@value='Google Search']")).click(); 
    } 

    @AfterMethod 
    public void afterMethod() { 
     driver.quit(); 
    } 

} 

我的文件夾結構

enter image description here

我的行家輸出

enter image description here

需要知道爲什麼會出現這種情況。這是工作正常,當我運行它與testNG

回答

1

POM不知道哪個文件運行。按照以下步驟使其工作。

創建testng.xml文件並在pom.xml之前添加以下代碼並嘗試運行。

<build> 
     <!-- Source directory configuration --> 
     <sourceDirectory>src</sourceDirectory> 
     <plugins> 
      <!-- Following plugin executes the testng tests --> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-surefire-plugin</artifactId> 
       <version>2.14.1</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> 
相關問題