您的位置:軟件測(cè)試 > 開(kāi)源軟件測(cè)試 > 開(kāi)源單元測(cè)試工具 > TestNG
在Eclipse中使用Maven配置WebDriver+Testng(2)
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2014/3/10 10:57:56 ] 推薦標(biāo)簽:Testng Maven

  建立一個(gè)簡(jiǎn)單的測(cè)試項(xiàng)目
package net.Maventest;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class WebDriverDemoTest{
private WebDriver driver;
private String baseUrl;
@BeforeClass
public void setUp() throws Exception {
System.setProperty("webdriver.firefox.bin", "D:\Program Files (x86)\Mozilla Firefox\firefox.exe");
driver = new FirefoxDriver();
baseUrl = "http://www.baidu.com/";
}
@Test
public void testSearch() throws Exception {
driver.get(baseUrl);
Thread.sleep(1000);
WebElement input = driver.findElement(By.id("kw1"));
input.sendKeys("天氣預(yù)報(bào)");
Thread.sleep(1000);
WebElement search = driver.findElement(By.id("su1"));
search.click();
Thread.sleep(1000);
Assert.assertTrue(driver.getTitle().contains("天氣預(yù)報(bào)"),"Title is incorrect.");
System.out.println(driver.getTitle());
//      (new WebDriverWait(driver,10)).until(new ExpectedCondition<Boolean>(){
//          public Boolean apply(WebDriver d){
//                 return d.getTitle().startsWith("天氣預(yù)報(bào)");
//          }
//      });
}
@AfterClass
public void tearDown() throws Exception {
driver.quit();
}
}

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