打开Chrome浏览器时,Capybara无法加载或添加扩展程序
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了打开Chrome浏览器时,Capybara无法加载或添加扩展程序相关的知识,希望对你有一定的参考价值。
我正在尝试使用扩展程序/附加“mod标头”自动打开Chrome浏览器,以便我可以使用http标头,用户代理等发送网址。
问题是我的脚本(下面给出的代码片段)打开Chrome浏览器没有扩展/附加“mod标头”,不知道我做错了什么?请帮忙
env.rb:
require 'rspec'
require 'cucumber'
require 'capybara'
require 'selenium-webdriver'
require 'capybara/cucumber'
require 'base64'
Capybara.app_host = "http://google.com"
settings = YAML.load_file(File.expand_path(File.dirname(__FILE__))+ "/../../config/settings.yml")
puts settings.inspect
puts settings["browser"]
case settings["browser"]
when "CHROME"
chrome_extensions = []
my_capabilities = Hash.new
# chrome_extension_path = '/Users/Duncan/Desktop/Browser_Testing/extension_1_2_4.crx'
# puts '#{chrome_extension_path}'
begin
File.open('/Users/Duncan/Desktop/Browser_Testing/extension_1_2_4.crx', "rb") do |file|
chrome_extensions << Base64.encode64(file.read.chomp)
puts 'over it is...'
end
rescue Exception => e
raise "ERROR: Couldn't File.read or Base64.encode64 a Chrome extension: #{e.message}"
end
# Append the extensions to your capabilities hash
my_capabilities.merge!({'chrome.extensions' => chrome_extensions})
caps = Selenium::WebDriver::Remote::Capabilities.chrome(my_capabilities)
Capybara.register_driver :selenium_chrome do |app|
#Capybara::Selenium::Driver.new(app, :browser => :chrome, :switches => ["--load-extension=/Users/chinmayajb/Desktop/MPM_Testing/extension_1_2_4.crx"])
Capybara::Selenium::Driver.new(app, :browser => :chrome, :desired_capabilities => caps)
end
Capybara.default_driver = :selenium_chrome
end
答案
这应该适用于在Chrome浏览器上使用Ruby Capybara加载扩展程序:
caps = Selenium::WebDriver::Remote::Capabilities.chrome({'chromeOptions'
=>
{'extensions' => Base64.strict_encode64(
File.open('C:WorkspaceRemoteSystemsTempFilesextension.crx','rb').read
)]}})
Capybara.register_driver :selenium_chrome do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome,
:desired_capabilities => caps)
end
Capybara.default_driver = :selenium_chrome
以上是关于打开Chrome浏览器时,Capybara无法加载或添加扩展程序的主要内容,如果未能解决你的问题,请参考以下文章
ruby 持续集成,parallel_tests,黄瓜,无头,capybara-webkit,chrome。对于mac和linux。有条件的@show chrome浏览器(:
ruby 持续集成,parallel_tests,黄瓜,无头,capybara-webkit,chrome。对于mac和linux。有条件的@show chrome浏览器(:
capybara webkit 无法加载 mailto url
Selenium加载Chrome/Firefox浏览器配置文件