HTTP basic auth for Capybara

I got it to work using page.driver.basic_authorize(name, password) instead Update: At the moment, after a Capybara upgrade, I’m using this pile of workarounds: if page.driver.respond_to?(:basic_auth) page.driver.basic_auth(name, password) elsif page.driver.respond_to?(:basic_authorize) page.driver.basic_authorize(name, password) elsif page.driver.respond_to?(:browser) && page.driver.browser.respond_to?(:basic_authorize) page.driver.browser.basic_authorize(name, password) else raise “I don’t know how to log in!” end

Change default Capybara browser window size

A proper way to do it for all js tests is to add following inside spec_helper.rb RSpec.configure block config.before(:each, js: true) do Capybara.page.driver.browser.manage.window.maximize end to maximize the window. Change to resize_to(x,y) to set any window size. EDIT: If you happen to be using Poltergeist the correct way to do it is config.before(:each, js: true) do … Read more

How to use Capybara in pure Ruby (without Rails)?

Here’s something that seems to work for me: require ‘rubygems’ require ‘capybara’ require ‘capybara/dsl’ Capybara.run_server = false Capybara.current_driver = :selenium Capybara.app_host=”http://www.google.com” module MyCapybaraTest class Test include Capybara::DSL def test_google visit(“https://stackoverflow.com/”) end end end t = MyCapybaraTest::Test.new t.test_google

Capybara matcher for presence of button or link

Updated answer (should matcher is deprecated in RSpec 3.0+): expect(page).to have_selector(:link_or_button, ‘Click me’) Before: page.should have_selector(:link_or_button, ‘Click me’) Followed from click_link_or_button which is defined here: https://github.com/jnicklas/capybara/blob/master/lib/capybara/node/actions.rb#L12 def click_link_or_button(locator) find(:link_or_button, locator).click end alias_method :click_on, :click_link_or_button It calls a selector :link_or_button. This selector is defined here: https://github.com/jnicklas/capybara/blob/master/lib/capybara/selector.rb#L143 Capybara.add_selector(:link_or_button) do label “link or button” xpath { |locator| XPath::HTML.link_or_button(locator) … Read more

Is there a way to send key presses to Webkit using Capybara?

I’ve been trying to implement Marc’s answer without any success, but I found some help from a similar question: capybara: fill in form field value with terminating enter key. And apparently there was a pull request from capybara that seems to address this issue. What worked for me was: before { fill_in “some_field_id”, with: “\t” … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)