适合火狐与谷歌浏览器,可在各自的浏览器应用商店下载。
这是一款可以录制浏览器操作的工具,并且可以用 Export 导出成 webDriver 的各种语言的代码,例如以下是录制在百度搜索 java 关键词动作生成的脚本
package com.example.tests;
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class UntitledTestCase {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
@Before
public void setUp() throws Exception {driver = new FirefoxDriver();
baseUrl = "https://www.google.com/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void testUntitledTestCase() throws Exception {driver.get("https://www.baidu.com/");
driver.findElement(By.id("kw")).click();
driver.findElement(By.id("kw")).clear();
driver.findElement(By.id("kw")).sendKeys("java");
driver.findElement(By.id("form")).submit();}
@After
public void tearDown() throws Exception {driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {fail(verificationErrorString);
}
}
private boolean isElementPresent(By by) {try {driver.findElement(by);
return true;
} catch (NoSuchElementException e) {return false;}
}
private boolean isAlertPresent() {try {driver.switchTo().alert();
return true;
} catch (NoAlertPresentException e) {return false;}
}
private String closeAlertAndGetItsText() {try {Alert alert = driver.switchTo().alert();
String alertText = alert.getText();
if (acceptNextAlert) {alert.accept();
} else {alert.dismiss();
}
return alertText;
} finally {acceptNextAlert = true;}
}
}