小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

火狐忽略下載彈框設(shè)置

 小豬窩969 2017-06-30

自學(xué)Selenium2 ( WebDriver ),理論和實(shí)踐的差距還是很大的,所以學(xué)習(xí)任何編程語言、工具,實(shí)踐是最好的老師。

進(jìn)入正題,這篇文章講述,在自動(dòng)化測試時(shí),對Firefox瀏覽器的profile設(shè)置、啟動(dòng)有所不同,需根據(jù)自己情況進(jìn)行相應(yīng)修改。


1 Firefox的profie設(shè)置

自動(dòng)化測試時(shí),有可能會(huì)遇到下載文件的情況,如下圖;目前Selenium2還無法處理這樣的對話框,但可通過對Firefox的profile預(yù)先進(jìn)行設(shè)置達(dá)到自動(dòng)下載的效果。


1.1 創(chuàng)建FirefoxProfile對象

FirefoxProfile profile = new FirefoxProfile();

1.2 設(shè)置下載路徑

// 設(shè)置是否詢問下載位置(可忽略);默認(rèn)true——不詢問,直接下載到指定路徑,具體設(shè)置見browser.folderList,false——詢問
profile.setPreference("browser.download.useDownloadDir",true);
// 指定下載位置
profile.setPreference("browser.download.downloadDir", "c:\\OutputFolder");
// 設(shè)置下載方式;0——下載到桌面,默認(rèn)1——下載到Firefox默認(rèn)位置,2——下載到指定位置
profile.setPreference("browser.download.folderList", 2);
// 當(dāng)一個(gè)下載開始時(shí),設(shè)置是否顯示下載管理器;默認(rèn)true——顯示,flase——不顯示
profile.setPreference("browser.download.manager.showWhenStarting",false);


2 設(shè)置無需確認(rèn)即可下載的文件格式

profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream, application/vnd.ms-excel, text/csv, application/zip,application/xml");

注意:

MIME類型是設(shè)置某種拓展名的文件用一種應(yīng)用程序打開的方式類型。

常見文件的MIME類型:

.txt text/plain 或 text/x-log
.pdf application/pdf
.csv text/csv
.xls application/vnd.ms-excel
.doc application/msword
.zip application/zip
.xml application/xml
.rar application/octet-stream
.exe application/octet-stream
.gif image/gif
.jpeg image/jpeg
.html text/html

有時(shí),需要的文件無法在搜索引擎上查詢到其對應(yīng)文件類型的MIME類型,可在瀏覽器中查看,如Firefox瀏覽器的工具欄 -> 選項(xiàng) -> 應(yīng)用程序。


3 啟動(dòng)Firefox時(shí)加載插件

WebDriver啟動(dòng)的是一個(gè)干凈的沒有任務(wù)、插件、cookies信息的Firefox瀏覽器(即使本機(jī)Firefox安裝某些插件),但在自動(dòng)化測試中可能需要插件(如Firebug)進(jìn)行調(diào)試。

注意:需要下載firebug.xpi,且最好使用非Firefox瀏覽器下載,不然提示直接安裝到Firefox;最好不要在Firebug官網(wǎng)中下載,因?yàn)樘崾灸阈枰褂肍irefox瀏覽器。

// 定義插件所在位置
File file = new File("E:\\Firefox\\files\\firebug-2.0.17.xpi");
// 創(chuàng)建一個(gè)FirefoxProfile對象profile
FirefoxProfile profile = new FirefoxProfile();
try{
// 將Firebug加載到profile對象中
profile.addExtension(file);
}catch (IOException e){
e.printStackTrace();
}
// 設(shè)置Firebug的當(dāng)前版本號(hào)
profile.setPreference("extensions.firebug.currentVersion","2.0.17");
// 激活Firebug
profile.setPreference("extensions.firebug.allPagesActivation","on");


4 啟動(dòng)Firefox瀏覽器

4.1 Firefox安裝在默認(rèn)路徑下

直接創(chuàng)建一個(gè)FirefoxDriver對象。

WebDriver driver = new FirefoxDriver();

4.2 Firefox未安裝在默認(rèn)路徑下

需要指定Firefox的可執(zhí)行程序firefox.exe的路徑,再創(chuàng)建FirefoxDriver對象。

System.setProperty("webdriver.firefox.bin", "E:\\Firefox\\firefox.exe");
WebDriver driver = new FirefoxDriver();


結(jié)合起來,就是如下代碼:

File file = new File("E:\\Firefox\\files\\firebug-2.0.17.xpi");
FirefoxProfile profile = new FirefoxProfile();
try{
	profile.addExtension(file);
} catch (IOException e){
	e.printStackTrace();
}
profile.setPreference("extensions.firebug.currentVersion","2.0.17");
profile.setPreference("extensions.firebug.allPagesActivation","on");
profile.setPreference("browser.download.downloadDir","C:\\Output");
profile.setPreference("browser.download.folderList",2);
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream, application/vnd.ms-excel, text/csv, application/zip,application/xml");
System.setPreperty("webdriver.firefox.bin","E:\\Firefox\\firefox.exe");
WebDriver driver = new FirefoxDriver();


    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多