我是新來的測試世界。我使用硒IDE來記錄測試。另外,我將測試用例導出爲JUnit4測試用例。我的出口看起來像:運行硒IDE出口測試用例
package com.example.tests;
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class Test {
private WebDriver driver;
private String baseUrl;
private StringBuffer verificationErrors = new StringBuffer();
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "http://192.168.8.207/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void test() throws Exception {
driver.get(baseUrl + "/");
driver.findElement(By.name("user")).clear();
driver.findElement(By.name("user")).sendKeys("admin");
driver.findElement(By.name("password")).clear();
driver.findElement(By.name("password")).sendKeys("infineta123");
driver.findElement(By.id("btnLogin-button")).click();
}
@After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
}
如何執行此測試用例?在那之後,我該如何自動執行幾個這樣的測試用例呢?