标签:
/*创建的类为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();
}
}
【cl】selenium实例2:打开百度,输入hello world
标签:
原文地址:http://www.cnblogs.com/dieyaxianju/p/5033410.html