簡體   English   中英

使用selenium2library設置自動下載首選項配置文件

[英]Set auto download preference profile using selenium2library

環境:robotframework-selenium2library

我正在selenium2library中尋找一種通過在FirefoxProfile中設置首選項來自動下載文件的方法,因為這是我可以找到的解決方案。 但是,似乎我無法使用在selenium webdriver中列出的方式將首選項配置文件導入selenium2library中的瀏覽器。

使用Selenium Webdriver:
fp = webdriver.FirefoxProfile()
fp.set_preference("browser.download.folderList",2) fp.set_preference("browser.download.manager.showWhenStarting",False) fp.set_preference("browser.download.dir",getcwd()) fp.set_preference("browser.helperApps.neverAsk.saveToDisk","application/msword, application/csv, application/ris, text/csv, image/png, application/pdf, text/html, text/plain, application/zip, application/x-zip, application/x-zip-compressed, application/download, application/octet-stream")
browser = webdriver.Firefox(firefox_profile=fp)

我可以在selenium2library中找到open_browser(),但是它只吃一個目錄,而不是像selenium webdriver這樣使用首選項配置文件的靈活性。

Selenium2Library:
open_browser(self, url, browser='firefox', alias=None,remote_url=False, desired_capabilities=None,ff_profile_dir=None)

如果我可以像robotframework-selenium2library中的Selenium Webdriver一樣進行操作,誰能給我一些啟發?

我在Github上發現了一個關於此的封閉問題https://github.com/rtomac/robotframework-selenium2library/issues/18

但是,似乎使用配置文件目錄而不是靈活地設置Firefox配置文件的首選項。

謝謝!!

我可以在selenium2library中找到open_browser(),但它只占用一個目錄

不。它也有偏好。 長話是這樣的:

我不太確定您實際上如何使用robotframework-selenium2library。 我會說, 通常的用法是運行導入selenium2library的robotframework測試用例(即簡單的UTF-8文本文件)。 可能的解決方案如下所示(不用說,所有變量都應在*** Variables ***定義):

*** Settings ***
Library           Selenium2Library
Library           Collections

*** Variables ***

*** Test Cases ***
MyTestCase
    ${preferences} =    Create Dictionary   browser.download.folderList  2  browser.download.manager.showWhenStarting  False   # and so on ....
    Open Browser    <yourURL>    desired_capabilities=${preferences}

但是,您的問題表明您打算直接使用selenium2library提供的python函數(例如您在問題中提到的open_browser )。 在這種情況下,您需要做的就是使用適當設置的參數desired_capabilities來調用該函數。

請注意該參數的文檔(完整的代碼可在此處找到):

如果為remote指定一個值,則還可以指定'desired_capabilities',它是key1:val1,key2:val2格式的字符串,將用於為遠程服務器指定desired_capabilities。 這對於執行諸如為Internet Explorer指定代理服務器或在使用saucelabs.com時指定瀏覽器和操作系統之類的操作很有用。 “ desired_capabilities”也可以是字典(使用“ Create Dictionary”創建),以允許進行更復雜的配置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM