Questions tagged [capybara]

Capybara is a web application testing framework for Rack applications, such as Rails, Sinatra and Merb.

Capybara aims to simplify the process of integration testing Rack applications, such as Rails, Sinatra or Merb. Capybara simulates how a real user would interact with a web application. It is agnostic about the driver running your tests and currently comes bundled with rack-test, Culerity, Celerity and Selenium support built in.

A complete reference is available at rubydoc.info.
A great capybara cheat sheet is available here.

5916 questions
86
votes
10 answers

How to test a confirm dialog with Cucumber?

I am using Ruby on Rails with Cucumber and Capybara. How would I go about testing a simple confirm command ("Are you sure?")? Also, where could I find further documentation on this issue?
Yuval Karmi
  • 26,277
  • 39
  • 124
  • 175
84
votes
12 answers

setting request headers in selenium

I'm attempting to set the request header 'Referer' to spoof a request coming from another site. We need the ability test that a specific referrer is used, which returns a specific form to the user, otherwise an alternative form is given. I can do…
tamouse
  • 2,169
  • 1
  • 19
  • 26
83
votes
8 answers

How to make Capybara check for visibility after some JS has run?

After loading a page I have code that runs and hides and shows various items based on data returned by an xhr. My integration test looks something like this: it "should not show the blah" do page.find('#blah').visible?.should be_true end When…
Kevin Davis
  • 2,698
  • 1
  • 22
  • 27
83
votes
14 answers

Error installing gem capybara-webkit

I am new to ruby, but while trying to install capybara to run test on my system I get the following error. Im running OSX my_app$ gem install capybara-webkit Building native extensions. This could take a while... ERROR: Error installing…
eiu165
  • 6,101
  • 10
  • 41
  • 59
83
votes
15 answers

With Capybara, how do I switch to the new window for links with "_blank" targets?

Perhaps this isn't actually the issue I'm experiencing, but it seems that when I "click_link" a link with target="_blank", the session keeps the focus on the current window. So I either want to be able to switch to the new window, or to ignore the…
GlyphGryph
  • 4,714
  • 4
  • 32
  • 43
83
votes
10 answers

How do I get the HTML in an element using Capybara?

I’m writing a cucumber test where I want to get the HTML in an element. For example: within 'table' do # this works find('//tr[2]//td[7]').text.should == "these are the comments" # I want something like this (there is no "html" method) …
Jon Kruger
  • 4,009
  • 4
  • 33
  • 46
81
votes
8 answers

How do I confirm a javascript popup with Capybara?

I've tried several examples found online, but with no luck. I am looking to confirm the confirm message of a delete link. The last attempt was the code below, but that resulted in an Capybara::NotSupportedByDriverError error. def confirm_dialog …
Eric M.
  • 5,399
  • 6
  • 41
  • 67
76
votes
12 answers

Unable to obtain stable firefox connection in 60 seconds (127.0.0.1:7055)

While testing scenario by cucumber i'm getting the following error when running rspec tests unable to obtain stable firefox connection in 60 seconds (127.0.0.1:7055) (Selenium::WebDriver::Error::WebDriverError) Using ruby (1.9.2)…
72
votes
8 answers

Capybara: How to test the title of a page?

In a Rails 3 application using Steak, Capybara and RSpec how do I test the page's title?
Nerian
  • 15,901
  • 13
  • 66
  • 96
71
votes
7 answers

How do I simulate hitting enter in an input field with Capybara and ChromeDriver?

I have the following helper method to input a string into an input field and press the enter key, but it seems the enter key is never pressed. I see the string entered into the input field, but the events that take place upon hitting enter never…
Eric M.
  • 5,399
  • 6
  • 41
  • 67
70
votes
10 answers

Capybara: Select an option by value not text

For the HTML I have the following Capybara Ruby code: select…
Paul
  • 1,188
  • 1
  • 11
  • 21
69
votes
7 answers

Get select value of dropdown for capybara testing

I have to write tests for a web site. I am trying to get the selected value of a dropdown box. So far i can get the contents of the dropdown by doing find_field('restrictions__rating_movies').text returns - Don't Allow…
Brandon
  • 1,425
  • 2
  • 16
  • 19
67
votes
6 answers

How to stub ApplicationController method in request spec

I am needing to stub the response of a current_user method in an Rspec/capybara request spec. The method is defined in ApplicationController and is using helper_method. The method should simply return a user id. Within the test, I'd like this method…
Matt Fordham
  • 3,147
  • 10
  • 34
  • 51
65
votes
4 answers

How to fill hidden field with Capybara?

I've already found that when I want to set value to text field, text area or password field, I can use id, name or label as something in fill_in something, :with => some_value. However such approach fails when I try to set value to
skalee
  • 12,331
  • 6
  • 55
  • 57
61
votes
4 answers

How do poltergeist/PhantomJS and capybara-webkit differ?

What are the differences between PhantomJS and capybara-webkit? What are the advantages of capybara-webkit over PhantomJS? Which of the two is the most efficient tool? Others ...
Prashanth Sams
  • 19,677
  • 20
  • 102
  • 125