Capybara: is it possible to get an attribute value from a css string?
Probably too late. But I also had the same problem and found the solution. It might help someone else. page.find(‘div#drawer a’)[:href]
Probably too late. But I also had the same problem and found the solution. It might help someone else. page.find(‘div#drawer a’)[:href]
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
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
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
You may want to try: When(/^I go back$/) do page.evaluate_script(‘window.history.back()’) end This will require running the senario in a javascript capable driver (selenium/celerity/akephalos)
The standard way of doing this in Capybara is find(‘button.filter-case-studies’).click In relatively recent versions of Capybara you should also be able to do click_on(class: ‘filter-case-studies’)
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
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
As an aside. This line page.status_code.should = ‘404’ Should be page.status_code.should == 404 This worked for me with capybara-webkit.
Just ran into this issue myself. So the reason for this is there has been a somewhat undocumented change in Capybara. Capybara now makes the assumption that anything using it needs to be in the spec/features folder and it will make the proper assumptions. Anything left in the spec/requests folder will no longer work. Though … Read more