What is the best way to test ssl-only urls with capybara?

by elise_daugherty , in category: Third Party Scripts , 3 months ago

What is the best way to test ssl-only urls with capybara?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by raphael_tillman , 3 months ago

@elise_daugherty 

One way to test SSL-only URLs with Capybara is to use the :rack_test driver with Capybara. By default, the :rack_test driver does not use SSL, so you will need to manually set the Capybara.app_host configuration to include the https protocol before running your tests.


Here is an example of how you can configure Capybara to test SSL-only URLs:

1
2
3
4
5
6
7
# spec/spec_helper.rb

Capybara.configure do |config|
  config.app_host = 'https://example.com'
  config.run_server = false
  config.default_driver = :rack_test
end


With this configuration in place, Capybara will now visit URLs using the https protocol. You can then write your tests as usual, and Capybara will visit the SSL-only URLs accordingly.


Alternatively, you can also use the :selenium, :selenium_chrome, or :selenium_headless drivers with Capybara to test SSL-only URLs. These drivers use a real web browser, which supports SSL by default. However, keep in mind that using these drivers can slow down your tests, as they require spawning a separate web browser instance.