Selenium Webdriver JUNIT Maven Eclipse运行测试用例失败

时间:2012-11-08 20:31:45

标签: eclipse maven selenium junit selenium-webdriver

我正在尝试使用JUNIT 4.10和Selenium在Eclipse中使用Maven运行Web应用程序来运行测试用例。

我创建了一个简单的java项目,JUNIT测试用例添加了适当的依赖项。 它与Run as a JUNIT Test case完全正常,但它不能作为Maven测试,因此像mvn clean test这样的东西不起作用。

这是我的pom.xml摘录

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

<dependencies>
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.10</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>org.apache.poi</groupId>
  <artifactId>poi</artifactId>
  <version>3.8</version>
  <scope>compile</scope>
</dependency>
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>2.25.0</version>
    <type>jar</type>
    <scope>test</scope>
</dependency>

这里也是我写的JUnit Test案例,

@Test()
public void testTC101() throws InterruptedException{
    driver.get(ADMIN_BASE_URL_QA);
    driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);
    driver.findElement(By.xpath("//*[@id='top30Events']"));
    WebElement loanModFullEvent = driver.findElement(By.partialLinkText(QA_MOD_FULL_EVENT));
    loanModFullEvent.click();
    String clickedFullEventId = loanModFullEvent.findElement(By.xpath("..")).getAttribute("id").split("_")[1];
    List<WebElement> nearbyEvents = driver.findElements(By.id("nearby_events_" + clickedFullEventId));
    ListIterator<WebElement> wIterator = nearbyEvents.listIterator();
    WebElement element = null;
    String registerNowId = null;
    while(wIterator.hasNext()) {
        element = wIterator.next().findElement(By.linkText(QA_MOD_NONFULL_EVENT));
        element.click();
        registerNowId = element.getAttribute("onclick").replaceAll("\\D+", "");
    }
    registerNowId = "top30_" + registerNowId;
    driver.findElement(By.xpath("//*[@id='" + registerNowId + "']/div[3]/div/a")).click();              
    WebElement dropDownListBox = driver.findElement(By.xpath("//*[@id='list']"));
    Select clickThis = new Select(dropDownListBox);
    clickThis.selectByValue("mod");
    driver.findElement(By.xpath("//*[@id='situationdropdown']/div/div/div[1]/span/span/span/input")).click();
    RegistrationForm.fillFormAndSubmit();

}

代码只是为了这个想法,但问题是它在JUnit Test案例中运行为什么不使用maven。它说测试:0次运行:0次跳过:0次

为什么它没有认识到测试,我仍然不确定为什么?有人可以帮忙吗?

1 个答案:

答案 0 :(得分:2)

您说您的测试类名称以测试结束。根据surefire插件网站,这不是默认模式之一:http://maven.apache.org/plugins/maven-surefire-plugin/examples/inclusion-exclusion.html

**/Test*.java" - includes all of its subdirectories and all java filenames that start with "Test
**/*Test.java" - includes all of its subdirectories and all java filenames that end with "Test
**/*TestCase.java" - includes all of its subdirectories and all java filenames that end with "TestCase