第一步 解压apache-ant-1.7.1-bin.zip到某个盘符,这里以C盘做为例。
第二步 将bin所在目录设置为path环境变量的值之一:C:\apache-ant-1.7.1\bin
第三步 设置环境变量ANT_HOME为:C:\apache-ant-1.7.1
第四步 打开Dos窗口,输入ant -version检查是否正确,如果正确如下图
C:\Documents and Settings\Administrator>ant -version
Apache Ant version 1.7.1 compiled on June 27 2008
复制代码
- <parameter name="firefox_dir"
- value="D:/Program Files/Mozilla Firefox/Mozilla Firefox/firefox.exe" />
@Test
@Parameters( { "webSite" })
public void setUp_InternetExplorerDriver(String webSite) throws Exception {
//.\\lib\\IEDriverServer.exe 是lib目录下的驱动
System.setProperty("webdriver.ie.driver", ".\\lib\\IEDriverServer.exe");
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
true);
driver = new InternetExplorerDriver(capabilities);
baseUrl = webSite;
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
script(driver);
}
@Test
@Parameters( { "firefox_dir", "webSite" })
public void setUp_FirefoxDriver(String firefox_dir, String webSite)
throws Exception {
//firefox_dir 为本机 firefox安装目录
System.setProperty("webdriver.firefox.bin", firefox_dir);
driver = new FirefoxDriver();
baseUrl = webSite;
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
script(driver);
}
@Test
@Parameters( { "webSite" })
public void setUp_ChromeDriver(String webSite) throws Exception {
//.\\lib\\IEDriverServer.exe 是lib目录下的驱动
System.setProperty("webdriver.chrome.driver", "./lib/chromedriver.exe");
driver = new ChromeDriver();
baseUrl = webSite;
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
script(driver);
}
private void script(WebDriver driver) throws Exception {
try {
logger.log("开始");
driver.get(baseUrl);
driver.findElement(By.id("kw")).clear();
driver.findElement(By.id("kw")).sendKeys("selenium");
driver.findElement(By.id("kw")).submit();
driver.findElement(By.linkText("下一页>")).click();
driver.findElement(By.linkText("下一页>")).click();
driver.findElement(By.linkText("下一页>")).click();
assertEquals("selenium", driver.findElement(By.id("kw"))
.getAttribute("value"));
logger.log("结束");
} catch (Exception e) {
throw e;
} finally {
tearDown();
}
}
<suite name="WebDriver兼容性测试" thread-count="4" parallel="tests">
<parameter name="firefox_dir"
value="D:/Program Files/Mozilla Firefox/Mozilla Firefox/firefox.exe" />
<parameter name="webSite" value="http://www.baidu.com" />
private static final SelLogger logger = SelLogger.getLogger(脚本名.class);
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) | Powered by Discuz! X3.2 |