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

标签 eclipse maven selenium junit selenium-webdriver

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

我创建了一个简单的 java 项目,其中 JUNIT 测试用例添加了适当的依赖项。 它与作为 JUNIT 测试用例运行完美配合,但它不能作为 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()
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 测试用例中运行,为什么不使用 maven。它说测试:0 运行:0 跳过:0

为什么它无法识别测试,我仍然不确定为什么?有人可以帮忙吗?

最佳答案

您说您的测试类名称以 Tests 结尾。根据 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

关于eclipse - Selenium Webdriver JUNIT Maven Eclipse 运行测试用例失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13297325/

相关文章:

java - Eclipse 使用正则表达式查找/替换整行

java - 如何自动使用m2e在eclipse中配置checkstyle?

java - 有没有更简单的方法来更改 Eclipse 中的构建路径?

c# - Selenium - 关闭带有确认警报的窗口。 C#

javascript - 我如何使用 Nightwatch.js 从 ol 元素中的 li 项目中获取文本?

java - Firefox 驱动程序无法单击单选按钮

编程ic时编译器错误

maven - 带有 jacoco 的声纳仅显示 testng 的覆盖范围,而不显示 powermock 的覆盖范围

git - 使用 Maven 发布插件时出现 "Git fatal: ref HEAD is not a symbolic ref"

Maven Central 究竟是哪个存储库?