I am testing a feature on a staging server that requires a basic authentication in order to access the site. I got it running by using the following:
Capybara.app_host = "http://user:password@this.isanexample.com"
At one point in the scenario I access a page that uses https instead of http and requires me to put in user and password again in order to continue. It would be easy if I just used visit again, but I actually want to click on a link...
How can I get past this? I have googled like crazy, but couldn't really find a solution that works.
I found this: http://theadmin.org/articles/test-http-basic-authentication-in-rails/, but I have no idea how to implement it. I am quite new to all of this, so I might miss the obvious.
Can someone point me in the right direction?
Here is my code:
env.rb
require 'capybara/cucumber'
Capybara.app_host = "https://user:password@this.isanexample.com"
Capybara.default_driver = :selenium
Capybara.default_wait_time = 5
Capybara.ignore_hidden_elements = true
Capybara.current_session.driver.browser.manage.window.resize_to(1024, 1000)
checkout_steps.rb (abridged)
Given /^I am on the main page$/ do
visit('/')
end
When /^I navigate to the page with the available boxes$/ do
page.find(:xpath, "//a[contains(@href,'how-it-works')]").click
page.find(:xpath, "//a[contains(@class,'join')]").click
end
When /^I choose a monthly subscription$/ do
page.find(:xpath, "//span[contains(@class,'title') and .[contains(., 'Unbefristetes Abo')]]").click
page.find_button("Jetzt Bestellen").click
end