/*创建的类为junit class*/
package Selenium_lassen;
import static org.junit.Assert.*;
import java.io.File;
import org.junit.After;
import org.junit.Before;import org.junit.Test;import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebElement;import org.openqa.selenium.firefox.FirefoxBinary;import org.openqa.selenium.firefox.FirefoxDriver;import org.openqa.selenium.remote.DesiredCapabilities;
public class Case2 {
WebDriver driver;
@Before public void setUp() throws Exception { //方法一 // System.setProperty("webdriver.firefox.bin", "D:\\ruanjian\\Firefox\\azml\\firefox.exe"); //方法二 // DesiredCapabilities capability=DesiredCapabilities.firefox(); // capability.setCapability("firefox_binary","D:\\ruanjian\\Firefox\\azml\\firefox.exe"); //driver = new FirefoxDriver(capability); //方法三 File pathToFirefoxBinary = new File("D:\\ruanjian\\Firefox\\azml\\firefox.exe"); FirefoxBinary firefoxbin = new FirefoxBinary(pathToFirefoxBinary); driver = new FirefoxDriver(firefoxbin,null); }@Test public void test() throws Exception{ driver.get("http://www.google.com.hk"); WebElement element = driver.findElement(By.name("q")); element.sendKeys("hello Selenium!"); element.submit(); }
@After
public void tearDown() throws Exception { System.out.println("Page title is:"+driver.getTitle()); driver.quit(); }}