您的位置:軟件測試 > 開源軟件測試 > 開源單元測試工具 > TestNG
在Eclipse中使用Maven配置WebDriver+Testng(1)
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時間:[ 2014/3/6 9:59:53 ] 推薦標(biāo)簽:Testng Eclipse Maven

  4. 打開cmd命令窗口,切換到my_testng_test文件夾,敲入命令:mvn eclipse:eclipse 回車出現(xiàn)Build Success信息,則創(chuàng)建Webdriver項目成功。
  5. 在eclipse中導(dǎo)入所建文件夾

  6. 在my_testng_test項目下新建Source Folder - src, 新建package - org.openqa.selenium.example并在package “org.openqa.selenium.example”下新建
Class (修改使用Selenium官網(wǎng)上的例子)
<span style="font-family:SimSun;font-size:12px;">package org.openqa.selenium.example;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
public class Selenium2Example  {
public static void main(String[] args) {
System.setProperty("webdriver.firefox.bin", "D:\Program Files (x86)\Mozilla Firefox\firefox.exe");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.baidu.com");
WebElement element = driver.findElement(By.name("wd"));
element.sendKeys("Cheese!");
element.submit();
System.out.println("Page title is: " + driver.getTitle());
(new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
return d.getTitle().toLowerCase().startsWith("cheese!");
}
});
System.out.println("Page title is: " + driver.getTitle());
driver.quit();
}
}
</span>
  運行即可。

上一頁12下一頁
軟件測試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd