- capybara: Acceptance test framework for web applications
- poltergeist: A PhantomJS driver for Capybara (enables also javascript testing)
- easy to integrate with CI.
PhantomJSruns well as command line program. - easy to write tests.
CSSlike selectors for querying DOM elements and checking for values
rspec spec/
or
rspec spec/directory_you_want_to_test
page.driver.render 'screenshots/fuji-checkout.png'Just put binding.pry wherever inside your test. When execution stops at your break point you can inspect values just by typing variable names and pressing enter. To exit break point just write exit and execution will continue.
When testing javascript heavy (or weird implemented - PSD2HTML) pages you sometimes need to wait for a javascript event to complete. This will help you out:
page.document.should have_selector('div.chk-checked')
Browser will wait until it has an element with that selector.
visit '/path/on/your/host'
click_button 'Buy'
click_link 'Home'
find('.bg-wrapper-inner h3').should have_content('Content')
current_url.should == "#{Capybara.app_host}/checkout"
page.has_selector? '#xxx'
within('div.login') do
fill_in '_username', :with => '[email protected]'
fill_in '_password', :with => 'password'
click_button 'Login'
end