您的位置:軟件測(cè)試 > 開源軟件測(cè)試 > 開源功能測(cè)試工具 > Selenium
Selenium2.0功能測(cè)試之Close browser
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2013/10/14 16:31:00 ] 推薦標(biāo)簽:

  關(guān)閉瀏覽器是每條Case執(zhí)行完成或者測(cè)試進(jìn)行結(jié)束必要的操作,Selenium提供了兩種關(guān)閉瀏覽器的方法:
  driver.close() ; 作用為關(guān)閉當(dāng)前的瀏覽器窗口。
  driver.quit(); 作用為不僅關(guān)閉了當(dāng)前的瀏覽器窗口還徹底的退出WedDriver,釋放了Driver與Server之間的鏈接。一句話總結(jié)是:quit是更加徹底的close,quit會(huì)更好的釋放資源。所以quit方法比較適合我這種強(qiáng)迫癥患者,那么到底用哪種方式關(guān)閉瀏覽器以你自己的病癥而異了。

 

package org.coderinfo.demo;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class CloseBrowser {
public static void main(String[] args) {
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com.hk");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
//      driver.close();  僅關(guān)閉當(dāng)前瀏覽器窗口
driver.quit();  //徹底退出WebDriver
}
}
相關(guān)鏈接:
軟件測(cè)試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請(qǐng)使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd