Created
March 24, 2011 18:53
-
-
Save mcornell/885618 to your computer and use it in GitHub Desktop.
Running Cucumber with celerity and watir-webdriver. No need for Selenium Server for headless
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Just returns the appropriate browser class to instantiate | |
case RUBY_PLATFORM | |
when /java/ | |
if ENV['BROWSER'] =~ /true/ | |
require "watir-webdriver" | |
Browser = Watir::Browser | |
WEBDRIVER = true | |
puts "Running in a Browser" | |
if ENV['CHROMEWATIR'] | |
BROWSER_TYPE = :chrome | |
puts "Using Chrome" | |
elsif ENV['FIREWATIR'] | |
BROWSER_TYPE = :firefox | |
puts "Using Firefox" | |
if ENV['FIREWATIRPATH'] | |
# Custom Firefox Path, handy if you don't install in default locations | |
# or if you want to test with multiple Firefoxes | |
Selenium::WebDriver::Firefox.path = ENV['FIREWATIRPATH'] | |
puts "at #{ENV['FIREWATIRPATH']}" | |
end | |
else # ENV['WATIR'] | |
BROWSER_TYPE = :ie | |
puts "Using IE" | |
end | |
else | |
require 'celerity' | |
Browser = Celerity::Browser | |
Celerity.index_offset = 0 | |
WEBDRIVER = false | |
puts "Running Headless" | |
end | |
else | |
raise "This platform is not supported (#{PLATFORM})" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source "http://rubygems.org" | |
gem "cucumber", "0.10.0" | |
gem "gherkin", "2.3.3" | |
gem "watir-webdriver", "0.2.0" | |
gem "rake" | |
gem "rspec" | |
platforms :jruby do | |
gem "celerity", "0.8.7" | |
gem "syntax" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Before do | |
case RUBY_PLATFORM | |
when /java/ | |
if WEBDRIVER | |
@browser = Browser.new BROWSER_TYPE | |
else | |
@browser = Browser.new | |
@browser.webclient.setUseInsecureSSL(true) | |
end | |
else | |
raise "This platform is not supported (#{PLATFORM})" | |
end | |
@base_url = RegionBaseURL | |
end | |
After do | |
@browser.close | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'rake/clean' | |
require 'cucumber' | |
require 'cucumber/rake/task' | |
task :browser => ['features:setupenv', 'features:isbrowser', 'features:browser'] do | |
end | |
task :headless => ['features:setupenv', 'features:headless'] do | |
end | |
def setup_environment | |
ENV['TEST_SERVER'] ||= 'devl' | |
puts "running on the #{ENV['TEST_SERVER']} environment..." | |
end | |
namespace :features do | |
task :setupenv do | |
setup_environment | |
end | |
task :isbrowser do | |
ENV['BROWSER'] ||= 'true' | |
end | |
Cucumber::Rake::Task.new(:browser, 'Run Cucumber Features using a Browser') do |t| | |
t.profile = ENV['CI'] ? 'browser_ci' : 'browser' | |
end | |
Cucumber::Rake::Task.new(:headless, 'Run Cucumber Features using a Headless Browser') do |t| | |
t.profile = ENV['CI'] ? 'ci' : 'default' | |
end | |
end | |
task :default => :headless |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
set TEST_SERVER= | |
set FIREWATIR=true | |
set CHROMEWATIR= | |
set WATIR= | |
@REM set FIREWATIRPATH=C:\path\to\your\other\version\of\firefox.exe | |
if "" == "%1%" goto NO_SERVER | |
set TEST_SERVER=%1 | |
shift | |
echo testing on %TEST_SERVER% environment | |
:NO_SERVER | |
echo jruby -S rake --trace browser | |
jruby -S rake --trace browser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
set TEST_SERVER= | |
set FIREWATIR= | |
set CHROMEWATIR= | |
set WATIR= | |
if "" == "%1%" goto NO_SERVER | |
set TEST_SERVER=%1 | |
shift | |
echo testing on %TEST_SERVER% environment | |
:NO_SERVER | |
echo jruby -S rake --trace headless | |
jruby -S rake --trace headless |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
set TEST_SERVER= | |
set FIREWATIR= | |
set CHROMEWATIR= | |
set WATIR=true | |
if "" == "%1%" goto NO_SERVER | |
set TEST_SERVER=%1 | |
shift | |
echo testing on %TEST_SERVER% environment | |
:NO_SERVER | |
echo jruby -S rake --trace browser | |
jruby -S rake --trace browser |
Yes it is...fortunately, I'm not actually using it since WATIR is the else. Regardless, should be fixed.
This
@browser.webclient.setUseInsecureSSL(true)
could just be
@browser = Browser.new :secure_ssl => false
See this is what you get when you take folks with Java skills and try to get them to program in Ruby. Thanks for the tip!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is that a typo in your .bat files? Shouldn't the WAITR variable be WATIR?