您的位置:軟件測(cè)試 > 開(kāi)源軟件測(cè)試 > 開(kāi)源功能測(cè)試工具 > Selenium
自動(dòng)化測(cè)試工具 Selenium WebDriver 入門(mén)
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2014/1/9 9:30:07 ] 推薦標(biāo)簽:Selenium WebDriver 測(cè)試工具

【4. 測(cè)試 IE】
想逃避 IE 嗎?? 作為前端開(kāi)發(fā),IE 你是必須要面對(duì)的,沖吧!
其實(shí)你會(huì)發(fā)現(xiàn), Selenium 主要也是針對(duì) FireFox 和 IE 來(lái)制作的,所以把 FireFox 的代碼修改為 IE 的,那是相當(dāng)?shù)娜菀祝恍枰?jiǎn)單地兩步:
1)把 ExampleForFireFox.java 另存為 ExampleForIE.java
2)把 WebDriver driver = new FirefoxDriver(); 修改為 WebDriver driver = new InternetExplorerDriver();
3)一般大家的 IE都是默認(rèn)路徑吧,所以也不用設(shè)置 property 了

01 packagelesson1;
02 
03 importorg.openqa.selenium.By;
04 importorg.openqa.selenium.WebDriver;
05 importorg.openqa.selenium.WebElement;
06 importorg.openqa.selenium.ie.InternetExplorerDriver;
07 importorg.openqa.selenium.support.ui.ExpectedCondition;
08 importorg.openqa.selenium.support.ui.WebDriverWait;
09 
10 publicclassExampleForIE {
11     publicstaticvoidmain(String[] args) {
12         // 如果你的 FireFox 沒(méi)有安裝在默認(rèn)目錄,那么必須在程序中設(shè)置
13         // System.setProperty("webdriver.firefox.bin", "D:\Program Files\Mozilla Firefox\firefox.exe");
14         // 創(chuàng)建一個(gè) FireFox 的瀏覽器實(shí)例
15         WebDriver driver =newInternetExplorerDriver();
16 
17         // 讓瀏覽器訪問(wèn) Baidu
18         driver.get("http://www.baidu.com");
19         // 用下面代碼也可以實(shí)現(xiàn)
20         // driver.navigate().to("http://www.baidu.com");
21 
22         // 獲取 網(wǎng)頁(yè)的 title
23         System.out.println("1 Page title is: "+ driver.getTitle());
24 
25         // 通過(guò) id 找到 input 的 DOM
26         WebElement element = driver.findElement(By.id("kw"));
27 
28         // 輸入關(guān)鍵字
29         element.sendKeys("zTree");
30 
31         // 提交 input 所在的 form
32         element.submit();
33 
34         // 通過(guò)判斷 title 內(nèi)容等待搜索頁(yè)面加載完畢,間隔10秒
35         (newWebDriverWait(driver,10)).until(newExpectedCondition<Boolean>() {
36             publicBoolean apply(WebDriver d) {
37                 returnd.getTitle().toLowerCase().endsWith("ztree");
38             }
39         });
40 
41         // 顯示搜索結(jié)果頁(yè)面的 title
42         System.out.println("2 Page title is: "+ driver.getTitle());
43 
44         // 關(guān)閉瀏覽器
45         driver.quit();
46     }
47 }

運(yùn)行一下,是不是 so easy?

入門(mén)工作完成,現(xiàn)在完全可以利用 java 代碼,讓 Selenium 自動(dòng)執(zhí)行我們?cè)O(shè)置好的測(cè)試用例了,不過(guò).....這僅僅是個(gè)開(kāi)始。

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