/* The class created is 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 {
Method One
System.setproperty ("Webdriver.firefox.bin", "D:\\ruanjian\\firefox\\azml\\firefox.exe");
Method Two
Desiredcapabilities Capability=desiredcapabilities.firefox ();
Capability.setcapability ("Firefox_binary", "D:\\ruanjian\\firefox\\azml\\firefox.exe");
Driver = new Firefoxdriver (capability);
Method Three
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 Example 2: Open Baidu, enter Hello World