acceptance testing
capybara
capybara is the next generation testing library for web apps acceptance testing.
It took me 3 days to migrate 128 scenarios (806 steps) from webrat to capybara. Here are the problems I have encountered and how I solved them:
have_tag matcher
API: Rack::Test unofficial support for http vebs
ssl_requirement plugin
capybara does not play well with ssl_requirement (Rails plugin written by DHH)
webrat had no problem with it so I suspect it is a capybara bug
SslRequirement.module_eval do
def ensure_proper_protocol
true
end
end
case sensitive texts
symbol for ids in fill_in
session_id changes when subdomain changes
solution:
Before do
WirecardGateway.stub_xml_response_with 'wirecard_cc_success_response.xml'
host! "wwww.betterplace.local"
end
Testing presence of images
Then /^I should see the image "([^\"]*)"$/ do |file_name|
page.should have_xpath("//*/img[contains(@src, '#{file_name}')]")
end
def should_have_exclamation_mark(selector, colour, scale)
with_scope(selector) do
src = exclamation_mark_src(colour, scale)
page.should have_xpath(".//img[contains(@src, '#{src}')]")
end
end
webrat
Use tag#id with have_tag matcher
Then /^I should not see the payment option "([^\"]*)"$/ do |payment_option|
response.should_not have_tag("input##{payment_option}")
end
Using Firebug with WebDriver in Capybara/Cucumber
Posted by Mike Gehard on Tuesday September 21, 2010 at 07:58AM
Ever wanted to be able to debug an HTML page using the power of Firebug while running Cucumber/Capybara features/steps?
Follow these simple steps and you can get it to work:
1) Create a new "WebDriver" Firefox profile using the instructions found here
2) Fire up Firefox using the newly created profile and install/configure Firebug the way you want it. See instructions above.
3) Run your Cucumber/Capybara steps and pause the feature using a sleep() statement long enough for you to poke around in the page with Firebug.
**Note this has been proven to work on OS X, your mileage on other OS's may be limited.