Cucumber/Capybara VS Selenium

Cucumber/Capybara vs Selenium?

This question is borderline asking for an opinion. Your question actually reads to me, "What tool is right for me?" I say this because you don't give a reason for why you chose Cucumber and Capybara. I believe to answer that tester's question, you need to answer a couple more questions first:

1.) What stage in the process are you going to be writing these tests?

Cucumber may not be the right choice for unit tests, depending on the language you're using. But it can be used for any level of testing, from unit to integration to end-user.

2.) Who is going to maintaining your tests? You? Other developers? Testers? Business Analysts? Project Managers?

Automated tests must be maintained, and knowing who will be doing that can help you decide on a tool - as some will be too technical for certain users.

3.) Who is going to be defining new tests?

Cucumber is meant to be used collaboratively between development, QA and business owners. It is the perfect tool for leveraging everyone's knowledge into the automated testing process. It requires the development of an ubiquitous language to be effect however. You can read up on that on James Shore's Art of Agile page.

Once you've answered these questions, you're ready to address the tester's question.

However, there are a couple of points to keep in mind when comparing recording tools (such as Selenium IDE, HP Quick Test Pro, IBM Rational Functional Tester) vs. development tools (nUnit, jUnit, RSpec, Selenium webdriver, Capybara) is that they are targeted towards different audiences. They also have different plusses and minuses.

Recording tools are easy for anyone to use, but the scripts they create are fragile. They break easily and require more maintenance. They are great for one-off automated testing, where you need to get it done quickly and have non-technical manpower.

Development tools have a larger learning curve and require programming (or at the least scripting) experience. The scripts are generally more robust, but require more technical knowledge to maintain. They are a good solution when you want repeatability and plan to use tests for a long time.

I strongly suggest you read The Cucumber Book. It will really help you decide if Cucumber is the right choice for you.

Comparison of capybara-webkit vs selenium-webdriver

You're confusing a few things here. Capybara is a testing framework/DSL, for Ruby, which can be used with any of the test runner frameworks (RSpec, Minitest, etc). It can use a number a of different drivers to communicate with the web app being tested.

The default driver is rack_test which doesn't support any JS and cannot connect to any addresses outside the app under test.

A second driver option is selenium-webdriver which can control multiple different real browsers firefox/chrome/safari/etc. for testing, and can connect to any valid URL. The downside of using selenium-webdriver as the driver is that it opens a real browser and is therefore usually slower with a larger memory footprint.

Another driver option is capybara-webkit which is headless and can also connect to any valid URL. It is generally faster than using selenium however as it is built on an old version of QtWebkit it doesn't support newer web standards (ES2015, etc) so at a minimum you need to make sure all JS is transpiled to ES5 maximum.

There is nothing to stop you using different drivers for different tests to get the benefits of speed for most tests and then use a real browser for tests that need things like WebRTC, etc. The Capybara README details how to do that when using different test runners (RSpec, Minitest, etc)

Trouble using cucumber/capybara/selenium with different browsers

Well, I got some help from a coworker and now the tests are running in firefox, and hopefully soon on ie. Here is how he changed the env.rb file

require 'cucumber/rails'
Capybara.default_selector = :css
cb = ENV['CURRENT_BROWSER']
testbrowser = cb ? cb.downcase.to_sym : :firefox
puts "-------------- current browser: #{testbrowser}........."
Capybara.register_driver :selenium do |app|
if RbConfig::CONFIG['host_os'][/linux/] && testbrowser.to_s.eql?("CHROME".downcase)
Capybara::Selenium::Driver.new(app, {:browser => :remote, :url => "http://127.0.0.1:9515"})
else
if testbrowser.eql?(:chrome)
Capybara::Selenium::Driver.new(app, :browser => :chrome, :switches => %w[--test-type])
elsif testbrowser.eql?(:safari)
Capybara::Selenium::Driver.new(app, :browser => :safari, :switches => %w[--test-type])
elsif testbrowser.eql?(:internetexplorer)
Capybara::Selenium::Driver.new(app, :browser => :internetexplorer, :switches => %w[--test-type])
else
Capybara::Selenium::Driver.new(app, :browser => testbrowser)
end
end
end

ActionController::Base.allow_rescue = false

begin
DatabaseCleaner.strategy = :transaction
rescue NameError
raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
end

Cucumber::Rails::Database.javascript_strategy = :truncation

Then when I run a feature from the command line I use

bundle exec cucumber CURRENT_BROWSER=chrome feature/myFeature.feature

for Chrome, or

bundle exec cucumber feature/myFeature.feature

for Firefox (default). The opera driver still didn't want to work for me, and only 1% of people use it so I'm not worried, and Safari driver doesn't support modal interaction so if your test involves a validation window or interacting with a deliberate failure say on login, safari won't work. I kept the Safari option in case they update the Safari driver, or if I have a very simple test I'd like to be able to run. I will update after I have seen if it works properly on IE.

How to use headless chrome with capybara and selenium

1) Make sure you don't have another registered driver, I made this mistake myself and had an iphone driver, which was using the args in the old way, that's why I was getting the warning.

2) Make sure you have Chrome version 57+ on Linux, 59+ on macOS or 60+ on Windows;

3) Add/update the gem selenium-webdriver;

4) Add the following driver to your spec_helper.rb or rails_helper.rb:

Capybara.register_driver :chrome do |app|
Capybara::Selenium::Driver.new app, browser: :chrome,
options: Selenium::WebDriver::Chrome::Options.new(args: %w[headless disable-gpu])
end

Capybara.javascript_driver = :chrome


Related Topics



Leave a reply



Submit