你要哪个客户端版本的脚本? Junit3 / Junit4 / WebDriver?
其实你用Firefox的Selenium IDE插件录制脚本, 然后转化成需要的java脚本即可.
import java.util.ArrayList;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import junit.framework.TestCase;
/**
* @author RobinGou
*
*/
public class webTestOpenLink extends TestCase {
WebDriver driver = null;
WebElement element = null;
public void testwebTestOpenLink()
{
final String sUrl = "http://www.baidu.com/";
String btnSearch = "su";
String inputBox = "kw";
String pageTittle = "百度一下,你就知道";
System.setProperty("webdriver.ie.driver","D:\\eclipse_cn\\selenium\\IEDriverServer.exe");
DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
driver = new InternetExplorerDriver(ieCapabilities);
driver.get(sUrl);
// try {
// Thread.sleep(1000);
// } catch (InterruptedException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
List list = new ArrayList();
list.size();
element = driver.findElement(By.id(inputBox));
element.sendKeys("selenium-webdriver");
element = driver.findElement(By.id(btnSearch));
element.click();
assertTrue("未成功进入待测试页面!",driver.getTitle().equals(pageTittle));
}
/* (non-Javadoc)
* @see junit.framework.TestCase#setUp()
*/
protected void setUp() throws Exception {
super.setUp();
}
/* (non-Javadoc)
* @see junit.framework.TestCase#tearDown()
*/
protected void tearDown() throws Exception {
driver.close();
super.tearDown();
}
}