0
我正在使用Selenium,TestNG和Maven進行自動化測試。當我執行:cmd中的mvn集成測試時,maven不會運行我的測試。我是Maven中的新成員,我閱讀了一些示例,但沒有爲我的問題找到任何解決方案。mvn集成測試不會運行我的測試
這裏是我的pom.xml:
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<classifier>jdk15</classifier>
<version>5.11</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>2.31.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>selenium-maven-plugin</artifactId>
<executions>
<execution>
<phase>pre-integration-test</phase>
<goals>
<goal>start-server</goal>
</goals>
<configuration>
<background>true</background>
</configuration>
</execution>
<execution>
<id>stop-selenium</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop-server</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<include>**/MainPage*.java </include>
</configuration>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
這裏是我的MainPage類:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import static org.testng.Assert.*;
public class MainPage
{
static WebDriver driver;
@BeforeClass
public void setUp() {
driver = new FirefoxDriver();
}
@Test
public void OpenRegistrationPage(){
//GIVEN
openPage();
//WHEN
clickOnRegistration();
//THEN
checkIfIsDirected();
}
private void checkIfIsDirected() {
String elementTitle = driver.findElement(By.xpath("//td[@id='center- col']/div/div/table/tbody/tr/td/div")).getText();
assertEquals(elementTitle, "Rejestracja");
}
private void clickOnRegistration() {
WebElement registrationLink = driver.findElement(By.cssSelector("span.icon-rejestracja"));
registrationLink.click();
}
private void openPage() {
driver.get("https://www.x-kom.pl");
}
@AfterClass
public static void tearDown() {
driver.close();
}
}
在此先感謝! :)
謝謝!我已經將測試更改爲單元測試(使用maven-surefire-plugin),並將我的類的名稱更改爲:MainPageTest.java並且它工作正常。 – Nat
你沒有單元測試你有集成測試,所以你應該連同我提出的建議。 – khmarbaise