后续会带来testNG单元测试框架比junit框架更强大;
package cn.helloselenium; import org.openqa.selenium.*; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.By; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; public class junitwebdriver { public WebDriver driver; String baseUrl="http://www.sogou.com/"; @BeforeClass public static void setUpBeforeClass() throws Exception { } @AfterClass public static void tearDownAfterClass() throws Exception { } @Before public void setUp() throws Exception { System.setProperty("webdriver.gecko.driver", "C:\Program Files (x86)\Mozilla Firefox\geckodriver.exe"); driver=new FirefoxDriver(); } @After public void tearDown() throws Exception { //driver.quit(); } @Test public void test() { //fail("Not yet implemented"); driver.get(baseUrl+"/"); driver.findElement(By.id("query")).sendKeys("junit4单元测试"); driver.findElement(By.id("stb")).click(); } }