Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to test Java application with Capybara?

I like the overall idea of Capybara, but i can't run it against the Java application for some reason.

Is that possible at all?

like image 824
0100110010101 Avatar asked Jul 02 '10 09:07

0100110010101


People also ask

Which testing framework can be used with Capybara?

Some major testing framework which can be used with Capybara is : Cucumber is a Ruby-based test tool for BDD. RSpec is a behaviour-driven development (BDD) framework, inspired by JBehave. Minitest: is a testing suite for Ruby.

What is capybara used for?

Capybara is a web-based automation framework used for creating functional tests that simulate how users would interact with your application. Capybara is a library/gem useful for an underlying web-based driver.

What is a capybara library?

Capybara is a library/gem useful for an underlying web-based driver. Moreover, it offers a user-friendly DSL (Domain Specific Language) which is useful to describe actions that execute by the underlying web driver.


1 Answers

Yes, it is possible and we are doing it. Just use the selenium-webdriver gem with firefox or Chromium to remotely test the running application.

You can't test it from the Java test environment as you don't have the Rack infrastructure, but you can create a separate ruby testsuite and run rake when your java app is running on your development machine (or even autostart the application from the Rakefile)

This is how cucumber's env.rb looks like:

#
# features/support/env.rb
#
$: << File.join(File.dirname(__FILE__), "..", "..", "lib")

browser = :chrome #:htmlunit #:chrome #:firefox

host = ENV['TESTHOST'] || 'http://localhost:8080'
# may be non url was given
if not host.include?("//")
  host = "https://#{host}"
end

ENV['LANG'] = "en_US.UTF-8"

require 'rubygems'
require 'capybara'
require 'capybara/cucumber'
require 'selenium-webdriver'

require 'culerity' if browser == :htmlunit

case browser
when :htmlunit
  Capybara.default_driver = :culerity
  Capybara.use_default_driver
else
  Capybara.default_driver = :selenium
  Capybara.app_host = host
end

Capybara.run_server = false
if Capybara.default_driver == :selenium
  Capybara::Driver::Selenium.browser = browser
  driver = Selenium::WebDriver.for browser
end
like image 150
duncan Avatar answered Nov 15 '22 06:11

duncan