我的第一个目录如下:
+- 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的方法
当我运行我的测试&#34; Run As&#34; &#34; TestNG测试&#34;没关系。
我使用右键单击项目并选择Maven&gt;更新项目......
添加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 :(得分: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>
作为旁注,当您不使用它时,您也在POM中声明junit
,因此最好删除该依赖项。此外,您当前的testng
依赖项应该是范围test
而不是compile
,如下所示:
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.10</version>
<scope>test</scope>
</dependency>
答案 1 :(得分:0)
首先检查项目的输出文件夹应该是/ target / test-classes。 并且您的POM应该具有以下输入源:
<testSourceDirectory>src</testSourceDirectory>
<outputDirectory>target/test-classes</outputDirectory>
答案 2 :(得分: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>