2016-02-09 46 views
1

我的第一目錄的樣子:的webdriver - 頁面對象模型和Maven找不到類

+- pom.xml 
+- src/ 
    +- test/ 
     +- java/ 
     +- dms.config/ 
      +- config.java 
     +- dms.util/ 
      +- generatedata.java 
     +- dms.pages/ 
      +- LoginPage.java 
     +- dms.testcase/ 
      +- LoginTest.java 

testng.xml樣子:

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> 
<suite name="Suite" parallel="none"> 
    <test name="Test"> 
    <classes> 
     <class name="dms.testcase.LoginTest"/> 
    </classes> 
    </test> <!-- Test --> 
</suite> <!-- Suite --> 

我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/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>pl.rsoftstudio</groupId> 
    <artifactId>dms</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>jar</packaging> 

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

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

<repositories> 
    <repository> 
    <id>central</id> 
    <name>bintray</name> 
    <url>http://jcenter.bintray.com</url> 
    </repository> 
</repositories> 


    <dependencies> 
    <dependency> 
    <groupId>junit</groupId> 
    <artifactId>junit</artifactId> 
    <version>4.12</version> 
</dependency> 
<dependency> 
    <groupId>org.seleniumhq.selenium</groupId> 
    <artifactId>selenium-java</artifactId> 
    <version>2.48.2</version> 
</dependency> 
<dependency> 
    <groupId>org.testng</groupId> 
    <artifactId>testng</artifactId> 
    <version>6.9.10</version> 
</dependency> 
    </dependencies> 
    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <configuration> 
        <source>1.6</source> 
        <target>1.6</target> 
       </configuration> 
      </plugin> 

      <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-resources-plugin</artifactId> 
      <version>2.6</version> 
      <configuration> 

       <encoding>UTF-8</encoding> 

      </configuration> 
      </plugin>  
     </plugins> 
    </build> 

</project> 

當我嘗試通過Maven運行我的測試我有:

[TestNGClassFinder]警告:無法鏈接,並確定類的方法dms.testcase.LoginTest

當我運行我的測試「運行方式」,「TestNG的測試」是確定。

我用右鍵單擊該項目,選擇的Maven>更新項目...

添加LoginTest.class:

package dms.testcase; 

import org.testng.Assert; 
import org.testng.annotations.Test; 
import org.openqa.selenium.By; 
import org.openqa.selenium.WebElement; 
import org.openqa.selenium.support.ui.Select; 

import dms.config.Main; 
import dms.pages.kancelaria.LoginPage; 

public class LoginTest extends Main { 

    LoginPage lp = new LoginPage(); 

    @Test 
    public void login() throws Exception { 
      lp.login(); 
      lp.password(); 
      lp.buttonOK(); 
    } 
} 

回答

0

首先檢查你的項目輸出文件夾應該是/目標/測試 - 班。 和你的POM應該有源條目按如下:

<testSourceDirectory>src</testSourceDirectory> 
    <outputDirectory>target/test-classes</outputDirectory> 
+0

加油,停止猜測和說無意義。 ' SRC'?真?它是'src/test/java',默認和OP使用它。 – Tunaki

+0

這是我如何使用maven運行我的測試 –

1

沒有配置的maven-surefire-plugin使用您的具體TestNG的套件文件。從the docs,你需要在你的POM以下配置:

<plugin> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <version>2.19.1</version> 
    <configuration> 
    <suiteXmlFiles> 
     <suiteXmlFile>testng.xml</suiteXmlFile> 
    </suiteXmlFiles> 
    </configuration> 
</plugin> 

作爲一個側面說明,你也宣告junit在你的POM,當你不使用它,所以它會是最好的刪除該依賴關係。此外,當前的testng的依賴應該是範圍test而不是compile,像這樣:

<dependency> 
    <groupId>org.testng</groupId> 
    <artifactId>testng</artifactId> 
    <version>6.9.10</version> 
    <scope>test</scope> 
</dependency> 
0

我的問題是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>pl.rsoftstudio</groupId> 
    <artifactId>dms</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>jar</packaging> 

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

    <build> 
    <pluginManagement> 
     <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>2.19.1</version> 
     </plugin> 
     </plugins> 
    </pluginManagement> 
    </build> 

    <dependencies> 

    <dependency> 
     <groupId>org.seleniumhq.selenium</groupId> 
     <artifactId>selenium-java</artifactId> 
     <version>2.48.2</version> 
    </dependency> 

    <dependency> 
     <groupId>br.eti.kinoshita</groupId> 
     <artifactId>testlink-java-api</artifactId> 
     <version>1.9.8-1</version> 
    </dependency> 

    <dependency> 
     <groupId>xml-apis</groupId> 
     <artifactId>xml-apis</artifactId> 
     <version>1.4.01</version> 
    </dependency> 

    <dependency> 
     <groupId>org.testng</groupId> 
     <artifactId>testng</artifactId> 
     <version>6.9.8</version> 
     <scope>test</scope> 
    </dependency> 

    </dependencies> 

</project> 
相關問題