How to setup Capybara with Safari Technology Preview in Ruby

白昼怎懂夜的黑 提交于 2019-12-24 01:54:58

问题


I can't establish a session with Safari Technology Preview (STP) using Capybara and Selenium. Capybara won't even open a browser window.

I've upgraded to Ruby 2.3.0 Capybara 2.14.2 Selenium 3.4.0
I downloaded and installed STP from https://developer.apple.com/safari/download/
I am trying to use the following code:

Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(
  app,
  browser: :safari 
)
end
Capybara.default_driver = :selenium

How do I initialize Capybara to use the STP safaridriver that has implemented the W3C standards for automation?


回答1:


To get this to work I used the following code:

    #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


来源:https://stackoverflow.com/questions/44663481/how-to-setup-capybara-with-safari-technology-preview-in-ruby

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!