【问题标题】:Selenium Tests Not Running as ExpectedSelenium 测试未按预期运行
【发布时间】:2013-12-24 20:14:30
【问题描述】:

我正在使用 maven 和 junit 编写一个基本的 java selenium 测试。它看起来像这样:

@Before
public void setUp() throws Exception {
    DesiredCapabilities capabilities = DesiredCapabilities.firefox();
    capabilities.setCapability("version", "17");
    capabilities.setCapability("platform", Platform.MAC);
    this.driver = new RemoteWebDriver(
            new URL("http://" + authentication.getUsername() + ":" + authentication.getAccessKey() + "@ondemand.saucelabs.com:80/wd/hub"),
            capabilities);
    driver.get("https://pledgeling.com");
}

@After
public void tearDown() throws Exception {
    driver.quit();
}

@Test
public void testEmailSubmission() throws Exception {
    driver.findElement(By.id("emailAddress")).sendKeys("david@pledgeling.com");
    driver.findElement(By.className("btn-primary")).click();
    Assert.assertEquals(1,1);
}

但是,当我使用 mvn test 运行测试时,似乎没有运行任何测试。我该如何解决?当没有同名的类时,为什么会显示“TestSuite”?

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running TestSuite
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@61dd1c39
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.697 sec

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.597s
[INFO] Finished at: Tue Dec 24 12:06:41 PST 2013
[INFO] Final Memory: 16M/310M
[INFO] ------------------------------------------------------------------------

【问题讨论】:

  • 你把这个测试的源文件放在你项目的什么地方了?
  • 根据输出TestNG用于测试,而不是JUnit。还列出您的 pom.xml 文件 - 这将使调查更容易。
  • 可能属性之前、之后和测试来自 Junit 但不是 TestNG,如果我没记错的话,你必须添加 TestNG 属性而不是 Junit

标签: java maven selenium


【解决方案1】:

David Williams - 在我看来,您使用的测试套件文件不正确。您需要一个包含@Before 和@After 的测试套件文件。然后创建一个不同的 Java 类并将其添加到您的

/*----------------------------------------------------------------------
 * Filename: PlaygroundTestSuite.java
 *
 *
 *
 * How to add a new test class to the suite...
 *   1. Add an import statement for the new test class.
 *   2. Add an entry to the array of test classes.
 *
 */

package *.selenium.test_suites;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;

import *.*.*.TestNameBlah;

// Specify a runner class.
@RunWith(Suite.class)
//@formatter:off
// Specify an array of test classes.
@Suite.SuiteClasses({
    //Classes to run go here
    TestNameBlah.class,
    }

)
//@formatter:on
public class PlaygroundTestSuite extends BaseSeleniumTest {

    @BeforeClass
    public static void suiteStart() throws Exception {
        setup();
    }

    @AfterClass
    public static void suiteEnd() throws Exception {
        logout();
        tearDown();
    }

}

然后,当您运行测试套件文件时,它会运行测试。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-28
    • 2018-01-08
    • 1970-01-01
    相关资源
    最近更新 更多