Using Capybara with Test::Unit

Using Capybara with Test::Unit

Using Capybara with Test::Unit

Let’s understand Using Capybara with Test::Unit. If you are using Rails, add the following code in your test_helper.

rb file to make Capybara available in all test cases deriving from ActionDispatch::IntegrationTest:

class ActionDispatch::IntegrationTest

# Make the Capybara DSL available in all integration tests

include Capybara::DSL

end

  • If you are not using Rails, define a base class for your Capybara tests like so:

class CapybaraTestCase < Test::Unit::TestCase

include Capybara::DSL

def teardown

Capybara.reset_sessions!

Capybara.use_default_driver

end

end

Remember to call super in any subclasses that override teardown.

To switch the driver, set Capybara.current_driver. For instance,

class BlogTest < ActionDispatch::IntegrationTest

setup do

Capybara.current_driver = Capybara.javascript_driver # :selenium by default

end

test ‘shows blog posts’ do

# … this test is run with Selenium …

end

end

 

Make your resume stand out and become a Certified Capybara Testing Professional. Try free practice tests here!

A great career is just a certification away. So, practice and validate your skills to become Certified Capybara Testing Professional

Using Capybara with Cucumber
Using Capybara with MiniTest::Spec

Get industry recognized certification – Contact us

keyboard_arrow_up