免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

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

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

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


1 Firefox的profie設(shè)置

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


1.1 創(chuàng)建FirefoxProfile對象

FirefoxProfile profile = new FirefoxProfile();

1.2 設(shè)置下載路徑

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


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

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

注意:

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

常見文件的MIME類型:

.txttext/plain 或 text/x-log
.pdfapplication/pdf
.csvtext/csv
.xlsapplication/vnd.ms-excel
.docapplication/msword
.zipapplication/zip
.xmlapplication/xml
.rarapplication/octet-stream
.exeapplication/octet-stream
.gifimage/gif
.jpegimage/jpeg
.htmltext/html

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


3 啟動Firefox時加載插件

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

注意:需要下載firebug.xpi,且最好使用非Firefox瀏覽器下載,不然提示直接安裝到Firefox;最好不要在Firebug官網(wǎng)中下載,因為提示你需要使用Firefox瀏覽器。

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


4 啟動Firefox瀏覽器

4.1 Firefox安裝在默認路徑下

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

WebDriver driver = new FirefoxDriver();

4.2 Firefox未安裝在默認路徑下

需要指定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();


本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Selenium2(WebDriver)總結(jié)(一)
webdriver 啟動firefox driver時,加載firebug的擴展
Selenium2(WebDriver)總結(jié)(二)——firebug插件參數(shù)設(shè)置(補充)
webdriver入門
Selenium-webdriver系列教程(12)————如何在啟動firefox時加載擴展
Selenium WebDriver 之 PageObjects 模式 by Example
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服