public class WebDriverTest {
private String url = "http://www.baidu.com/";
WebDriver driver = new FirefoxDriver();
public void openUrl(){
driver.get(url);
}
public void login(){
driver.findElement(By.linkText("登录")).click();
}
public void quit(){
driver.quit();
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriverTest driverTest = new WebDriverTest();
driverTest.openUrl();
driverTest.login();
driverTest.quit();
}
}
JUnit测试代码:
package WebDriverPackage;
import static org.junit.Assert.*;
import org.junit.Test;
public class WebDriverTestTest {
WebDriverTest driverTest = new WebDriverTest();
@Test
public void testOpenUrl() {
driverTest.openUrl();
}
@Test
public void testLogin() {
driverTest.login();