我无法使用Capybara和Selenium与Safari技术预览(STP)建立会话。 Capybara甚至不打开浏览器窗口。
我升级到Ruby 2.3.0 Capybara 2.14.2 Selenium 3.4.0
我从https://developer.apple.com/safari/download/下载并安装了STP
我正在尝试使用以下代码:
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(
app,
browser: :safari
)
end
Capybara.default_driver = :selenium
如何初始化Capybara以使用已实施W3C自动化标准的STP safaridriver?
答案 0 :(得分:2)
为了实现这一点,我使用了以下代码:
#This is what we use to test the Safari release channel.
#You will have to install Safari Technology Preview (STP) from Apple.
#see standard properties here: https://www.w3.org/TR/webdriver/#capabilities
#STP requires a capabilities object
#you could use any of the properties from the link above.
#I just used a accept_insecure_certs for the heck of it
desired_caps = Selenium::WebDriver::Remote::Capabilities.safari(
{
accept_insecure_certs: true
}
)
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(
app,
browser: :safari,
driver_path: '/Applications/Safari Technology Preview.app/Contents/MacOS/safaridriver',
desired_capabilities: desired_caps
)
end
Capybara.default_driver = :selenium
答案 1 :(得分:0)
现在有了一种无需指定路径(您可能不知道)的方法。 Selenium驱动程序支持告诉驱动程序您需要技术预览。但是,这似乎与其他选项有些不同。
调用Selenium::WebDriver::Safari.technology_preview!
会打开此后创建的所有Safari驱动程序的功能。
Capybara.register_driver :safari_tech_preview do |app|
Selenium::WebDriver::Safari.technology_preview!
capabilities = Selenium::WebDriver::Remote::Capabilities.safari
Capybara::Selenium::Driver.new(app, browser: :safari, desired_capabilities: capabilities)
end
确保首先在技术预览浏览器中启用了远程自动化。