简体   繁体   English

如何在远程 Firefox webdriver 上安装附加组件?

[英]How to install add-on on a remote Firefox webdriver?

install_addon is a method on the Firefox webdriver, but I'm running tests remotely. install_addon是 Firefox webdriver 上的一种方法,但我正在远程运行测试。 How can I install an add-on to a driver like the following:如何为驱动程序安装附加组件,如下所示:

driver = webdriver.Remote(
    command_executor=SELENIUM_URL,
    desired_capabilities=webdriver.DesiredCapabilities.FIREFOX
)

? ? It looks like creating a webdriver.FirefoxProfile() and using add_extension() should work, but it's currently broken .看起来创建一个webdriver.FirefoxProfile()并使用add_extension()应该可以工作,但它目前已损坏

The use case is testing the effect of Firefox add-on manifest.json's all_frames property.用例正在测试 Firefox 附加组件 manifest.json 的all_frames属性的效果。

Аfter a long search and visits on this topic from google i found solution经过长时间的搜索和从谷歌访问这个主题,我找到了解决方案

Install addon in you Firefox profile from browser, save it and set him into webdriver options.从浏览器在您的 Firefox 配置文件中安装插件,保存它并将其设置为 webdriver 选项。

Firefox profile creating Firefox 配置文件创建

  1. Open you firefox browser打开你的firefox浏览器
  2. Go to about:profiles转到about:profiles
  3. Create a New Profile创建新配置文件
  4. Launch browser with created profile使用创建的配置文件启动浏览器
  5. Install addons what you need安装你需要的插件

Export profile导出配置文件

  1. Open root directory of your firefox profile (see in in about:profile in Root Directory section)打开您的 firefox 配置文件的根目录(参见about:profile in Root Directory部分)
  2. Copy folder into you project将文件夹复制到您的项目中

Python Python

from selenium.webdriver import FirefoxOptions, FirefoxProfile, Remote

# init options object
options = FirefoxOptions()

# init profile object with path to you profile
profile = FirefoxProfile('{path_to_your_profile_folder}')

# set profile into options
options.profile = profile

# init you Remote browser with created options (commented arguments for example)
driver = Remote(
    options=options,
    # command_executor= ..., 
    # desired_capabilities=...
)


It`s works for me.它对我有用。 The disadvantage of this solution is the presence of a folder with a profile that needs to be stored somewhere此解决方案的缺点是存在一个文件夹,其中包含需要存储在某处的配置文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM