Click overlay marker in Google Maps with capybara-webkit
To test that there are n markers on the page: expect(find(‘.gmap_container’)[‘data-markers’].split(‘},{‘).count).to eq(n)
To test that there are n markers on the page: expect(find(‘.gmap_container’)[‘data-markers’].split(‘},{‘).count).to eq(n)
If jQuery is on the page you most likely have to use an evaluate function to enter the context of the page. CasperJS has this diagram http://docs.casperjs.org/en/latest/_images/evaluate-diagram.png http://phantomjs.org/api/webpage/method/evaluate.html The execution is sandboxed, the web page has no access to the phantom object and it can’t probe its own setting.
If you’re using WebMock in your specs, then add the following to your rails_helper.rb: WebMock.allow_net_connect!(net_http_connect_on_start: true) or WebMock.disable_net_connect!(net_http_connect_on_start: true) source: https://github.com/bblimke/webmock/blob/master/README.md#connecting-on-nethttpstart
expect(page).to have_content(“my-text”, count: 2) will do what you want in modern versions of Capybara, not sure if that will work in 2.1 but worth trying (2.1 is over 2 years old now) Update: In Capybara 3.19+ this can also now be written expect(page).to have_content(“my-text”).twice
In case anyone washed up this shore looking for how to do this with Poltergeist you just need to pass the full argument: page.save_screenshot(‘screen.png’, full: true) # If providing a custom file name. page.save_screenshot(full: true) # Capybara sets a name based on timestamp. page.save_and_open_screenshot(‘screen.png’, full: true) # Same as save_screenshot. page.save_and_open_screenshot(full: true) # Same as … Read more
This should do the trick for your Cucumber step definition: page.has_css?(“div.records li”, :count => 2) There’s also page.has_xpath? (but I don’t understand xpath) If you’re using Rspec you can phrase it the Rspec way with: page.should have_css(“div.records li”, :count => 2) I had to solve a very similar problem just yesterday; here’s the full step … Read more
The accepted answer suggests rack_session_access. It works by inserting middleware controllers to edit and update the session state, then has capybara visit that page and submit a form with the session data. Very ingenious! But unnecessary if you are using Warden (directly or through Devise). Warden has a hook on_next_request that gives access to the … Read more
Try this: url = URI.parse(current_url)
To find a link based on just its href using capybara you could do link = page.find(:css, ‘a[href=”actual link”]’) or if you’re looking to assert that the element exists page.assert_selector(:css, ‘a[href=”actual link”]’) or – if using RSpec expect(page).to have_selector(:css, ‘a[href=”actual link”]’) Since have link by default searches for substrings in the link text you can … Read more
You get the table like this: //span[@data-id=’table1′]/table Select the data-id attribute and get the child element of name table.