gpt4 book ai didi

java - Selenium 测试未按预期运行

转载 作者:太空宇宙 更新时间:2023-11-04 15:17:17 26 4
gpt4 key购买 nike

我正在使用 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] ------------------------------------------------------------------------

最佳答案

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();
}

}

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

关于java - Selenium 测试未按预期运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20766327/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com