Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to make Capybara do tests live in a browser?

Tags:

rspec

capybara

I'd like to debug some of my tests and see what's actually happening. An easy way to do that would be to watch them play out in front of me. Is it possible to force Capybara to use an actual browser instance to run the tests visibly in front of you?

like image 801
Peter Nixey Avatar asked Dec 22 '15 12:12

Peter Nixey


People also ask

What is Capybara DSL?

Capybara is a Ruby library (also referred to as a gem) that is used with an underlying web-based driver. It consists of a user-friendly DSL (Domain Specific Language) which describe actions that are executed by the underlying web driver.

What is Capybara framework?

Capybara is a test automation framework commonly used for testing web applications in Ruby. Capybara simulates scenarios for user stories and automates web application testing for behavior-driven software development.

What are capybara tests?

Capybara is an acceptance test framework for web applications. It's a common choice for end-to-end, acceptance, or integration testing in Rails applications. It allows developers to simulate a user on a web page and make assertions based on the content and environment of the page.


1 Answers

Of course it is possible! You can use selenium driver.

Add selenium-webdriver to your Gemfile. Then, in your spec_helper.rb you'll have to set

Capybara.javascript_driver = :selenium

When you'll launch your tests, a new Firefox window will open!

If you want Chrome to be opened, set the driver to :selenium_chrome

Remember to set :js => true in your test:

describe 'some test', :js => true do
 it "something" do
  .
  .
  .
 end
end

You can also learn more about drivers here

like image 157
thefabbulus Avatar answered Sep 19 '22 15:09

thefabbulus