N D
N D

Reputation: 737

How to setup Capybara with Safari Technology Preview in Ruby

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?

Upvotes: 4

Views: 1636

Answers (2)

tgf
tgf

Reputation: 3266

There is now a way to do this without specifying the path (which you may not know). The Selenium driver supports telling the driver that you want Technology Preview. However this seems to work a little differently than other options.

Calling Selenium::WebDriver::Safari.technology_preview! turns the feature on for any Safari Driver created after this.

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

Make sure you've enabled remote automation in the tech preview browser first.

Upvotes: 0

N D
N D

Reputation: 737

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 :safari_technology_preview 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 = :safari_technology_preview

Upvotes: 4

Related Questions