我正在使用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] ------------------------------------------------------------------------
答案 0 :(得分:0)
David Williams - 我觉得您使用的Test Suite文件不正确。您需要一个包含@Before和@After的Test Suite文件。然后创建一个不同的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();
}
}
然后,当您运行Test Suite文件时,它会运行测试。