# I am looking for RoR Webrat Selenium Install Recipe

**URL:** <https://www.ruby-forum.com/t/i-am-looking-for-ror-webrat-selenium-install-recipe/178625>\
**Category:** Rails\
**Created:** [November 8, 2009, 7:13am UTC](https://www.ruby-forum.com/t/i-am-looking-for-ror-webrat-selenium-install-recipe/178625 "2009-11-08T07:13:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![audreylee88](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ecae2f/32.png) [@audreylee88](https://www.ruby-forum.com/u/audreylee88)\
**Post date:** [November 8, 2009, 7:13am UTC](https://www.ruby-forum.com/t/i-am-looking-for-ror-webrat-selenium-install-recipe/178625/1 "2009-11-08T07:13:53Z")

</div>

Hi there,

I’m trying to follow the ch 22 of the RSpec book.  
[copy is (B11.0 printing, October 28, 2009)]

I want to use selenium and cucumber.

Ordinary webrat seems to be working well.

Here is info about my RoR:

Sat Nov 07 21:53 /pt/tt11 maco$  
Sat Nov 07 21:53 /pt/tt11 maco$  
Sat Nov 07 21:53 /pt/tt11 maco$  
Sat Nov 07 21:53 /pt/tt11 maco$ script/about  
About your application’s environment  
Ruby version 1.8.7 (i686-darwin9.6.2)  
RubyGems version 1.3.5  
Rack version 1.0  
Rails version 2.3.4  
Active Record version 2.3.4  
Active Resource version 2.3.4  
Action Mailer version 2.3.4  
Active Support version 2.3.4  
Edge Rails revision b87ab750d1ca166cc2abece3ebf88a8e8d7b7e9f  
Application root /pr/tt11  
Environment test  
Database adapter sqlite3  
Database schema version 20091106204750  
Sat Nov 07 21:53 /pt/tt11 maco$  
Sat Nov 07 21:53 /pt/tt11 maco$  
Sat Nov 07 21:53 /pt/tt11 maco$  
Sat Nov 07 21:53 /pt/tt11 maco$

I installed these 2 gems and unpacked them in vendor gems:

drwxr-xr-x 7 maco staff 238 Nov 7 21:04 Selenium-1.1.14/  
drwxr-xr-x 7 maco staff 238 Nov 7 21:05 selenium-client-1.2.17/

Here are the corresponding config.gem lines in config/environment.rb:

config.gem ‘selenium-client’, :lib =\> false, :version =\> ‘1.2.17’  
config.gem ‘Selenium’, :lib =\> false, :version =\> ‘1.1.14’

I edited this file:

features/support/env.rb

So it matches this file supplied by the RSpec book:

[http://media.pragprog.com/titles/achbd/code/simulated\_browser/03/features/support/env.rb](http://media.pragprog.com/titles/achbd/code/simulated_browser/03/features/support/env.rb)

The book-file has a bug which I commented out:

# config.selenium\_wait\_timeout = 10

When I run cucumber I see this:

Sat Nov 07 21:39 /pt/tt11 maco$  
Sat Nov 07 21:39 /pt/tt11 maco$  
Sat Nov 07 21:39 /pt/tt11 maco$  
Sat Nov 07 21:39 /pt/tt11 maco$  
Sat Nov 07 21:39 /pt/tt11 maco$  
Sat Nov 07 21:39 /pt/tt11 maco$ script/cucumber features/  
welcome\_page.feature  
Feature: Welcome Page

So that I can feel welcome  
As a general user  
I want to see a welcome page with 2 columns

Scenario: Show the welcome page to a general user #  
features/welcome\_page.feature:7  
Given the server is up #  
features/step\_definitions/welcome\_page\_steps.rb:3  
And I am not logged in #  
features/step\_definitions/welcome\_page\_steps.rb:7  
==\> Waiting for Selenium RC server on port 4444… Ready!  
==\> Waiting for rails application server on port 3001… Ready!  
When I go to the homepage #  
features/step\_definitions/webrat\_steps.rb:10  
execution expired (Timeout::Error)  
/pt/r1/lib/ruby/1.8/timeout.rb:60:in `rbuf_fill' /pt/r1/lib/ruby/1.8/timeout.rb:62:in `timeout’  
/pt/r1/lib/ruby/1.8/timeout.rb:93:in `timeout' /pt/r1/lib/ruby/1.8/net/protocol.rb:134:in `rbuf\_fill’  
/pt/r1/lib/ruby/1.8/net/protocol.rb:116:in `readuntil' /pt/r1/lib/ruby/1.8/net/protocol.rb:126:in `readline’  
/pt/r1/lib/ruby/1.8/net/http.rb:2020:in `read_status_line' /pt/r1/lib/ruby/1.8/net/http.rb:2009:in `read\_new’  
/pt/r1/lib/ruby/1.8/net/http.rb:1050:in `request' /pt/r1/lib/ruby/1.8/net/http.rb:1037:in `request’  
/pt/r1/lib/ruby/1.8/net/http.rb:543:in `start' /pt/r1/lib/ruby/1.8/net/http.rb:1035:in `request’  
/pt/r1/lib/ruby/1.8/net/http.rb:845:in `post' (eval):2:in `/^I go to (.+)$/’  
features/welcome\_page.feature:11:in `When I go to the homepage’  
Then I should see a page with 2 columns #  
features/step\_definitions/welcome\_page\_steps.rb:15  
And the LHS column should be relatively narrow #  
features/step\_definitions/welcome\_page\_steps.rb:20  
And the RHS column should be much more prominent #  
features/step\_definitions/welcome\_page\_steps.rb:25  
And the LHS column should have the links: login, register #  
features/step\_definitions/welcome\_page\_steps.rb:30  
And the RHS should only contain the word Welcome #  
features/step\_definitions/welcome\_page\_steps.rb:36

1 scenario (1 failed)  
8 steps (1 failed, 5 skipped, 2 passed)  
5m4.081s  
21:45:05.220 ERROR - Exception running '0 'command on session null  
java.lang.NullPointerException: sessionId should not be null; has this  
session been started yet?  
at org.openqa.selenium.server.FrameGroupCommandQueueSet.getQueueSet  
(FrameGroupCommandQueueSet.java:212)  
at org.openqa.selenium.server.commands.SeleniumCoreCommand.execute  
(SeleniumCoreCommand.java:34)  
at org.openqa.selenium.server.SeleniumDriverResourceHandler.doCommand  
(SeleniumDriverResourceHandler.java:516)  
at  
org.openqa.selenium.server.SeleniumDriverResourceHandler.handleCommandRequest  
(SeleniumDriverResourceHandler.java:368)  
at org.openqa.selenium.server.SeleniumDriverResourceHandler.handle  
(SeleniumDriverResourceHandler.java:129)  
at org.mortbay.http.HttpContext.handle(HttpContext.java:1530)  
at org.mortbay.http.HttpContext.handle(HttpContext.java:1482)  
at org.mortbay.http.HttpServer.service(HttpServer.java:909)  
at org.mortbay.http.HttpConnection.service(HttpConnection.java:816)  
at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:  
982)  
at org.mortbay.http.HttpConnection.handle(HttpConnection.java:833)  
at org.mortbay.http.SocketListener.handleConnection  
(SocketListener.java:244)  
at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:357)  
at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:534)  
Sat Nov 07 21:45 /pt/tt11 maco$  
Sat Nov 07 21:45 /pt/tt11 maco$  
Sat Nov 07 21:45 /pt/tt11 maco$  
Sat Nov 07 21:45 /pt/tt11 maco$  
Sat Nov 07 21:45 /pt/tt11 maco$

I inspected the process listing:

Sat Nov 07 21:39 /pt/tt11 maco$  
Sat Nov 07 21:39 /pt/tt11 maco$  
Sat Nov 07 21:39 /pt/tt11 maco$  
Sat Nov 07 21:39 /pt/tt11 maco$  
Sat Nov 07 21:39 /pt/tt11 maco$  
Sat Nov 07 21:39 /pt/tt11 maco$ psorg java

maco 1351 0.0 1.0 343076 21312 s000 S 9:40PM  
0:00.63 /usr/bin/java -jar /Users/maco/pt/customers3/thubten/tt11/  
vendor/gems/webrat-0.4.4/vendor/selenium-server.jar -port 4444 -  
timeout 0  
maco 1381 0.0 0.0 599820 464 p0 S+ 9:46PM 0:00.00  
grep -i java  
Sat Nov 07 21:46 /pt/tt11 maco$  
Sat Nov 07 21:46 /pt/tt11 maco$  
Sat Nov 07 21:46 /pt/tt11 maco$  
Sat Nov 07 21:46 /pt/tt11 maco$  
Sat Nov 07 21:46 /pt/tt11 maco$

It looks like Selenium-RC is getting started.

But I sense that Selenium-RC is broken or my call to script/cucumber  
cannot connect to Selenium-RC.

Is there a recipe for getting cucumber and selenium to work together.

It worries me that the RSpec book is not specific about gem versions.

I’d like to see a recipe which has a very specific list of ingredients  
I need in order to operate cucumber with Selenium.

Can anyone offer a clue?

Thanks.

---

<div class="post-metadata">

**Author:** ![audreylee88](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ecae2f/32.png) [@audreylee88](https://www.ruby-forum.com/u/audreylee88)\
**Post date:** [November 9, 2009, 3:54am UTC](https://www.ruby-forum.com/t/i-am-looking-for-ror-webrat-selenium-install-recipe/178625/2 "2009-11-09T03:54:06Z")

</div>

ok,

I made some progess debugging this.

## I downloaded software from here:

[http://release.seleniumhq.org/selenium-remote-control/1.0.1/selenium-remote-control-1.0.1-dist.zip](http://release.seleniumhq.org/selenium-remote-control/1.0.1/selenium-remote-control-1.0.1-dist.zip)

I verified that Selenium Remote Control works on my Mac using this  
tutorial:

- [Best Online Casino in Australia | Top Licensed Casinos for Gamblers](http://www.jroller.com/selenium/#steps)

Above tutorial tells me I can start selenium-remote-control with a  
simple shell command:

- /usr/bin/java -jar selenium-server-1.0.1/selenium-server.jar -  
multiwindow

Then I exported a test-case (in ruby format) using Selenium IDE:

require “rubygems”  
require “selenium”  
require “test/unit”

class SelTestCase20091108 \< Test::Unit::TestCase  
def setup  
@verification\_errors = []  
if $selenium  
@selenium = $selenium  
else  
@selenium = Selenium::SeleniumDriver.new(“localhost”, 4444,  
“\*chrome”, “[http://www.google.com/](http://www.google.com/)”, 10000);  
@selenium.start  
end  
@selenium.set\_context(“SelTestCase20091108”)  
end

def teardown  
@selenium.stop unless $selenium  
assert\_equal [], @verification\_errors  
end

def test\_sel\_test\_case2009\_1108  
@selenium.open “/”  
@selenium.type “q”, “selenium remote control”  
@selenium.click “btnG”  
sleep 66  
end  
end

I was able to run above test-case with no problem:

- ruby sel\_test\_case2009\_1108.rb

At that point it dawned on me that the Selenium-server started by my  
Cucumber was broken.

And I recognized that the Selenium-server I had started by hand was  
ok.

So, I started the Selenium-server by hand using this shell command:

- /usr/bin/java -jar selenium-server-1.0.1/selenium-server.jar -  
multiwindow

Then, in another terminal I ran this:

script/cucumber features/welcome\_page.feature

Cucumber complained that port 4444 was taken but that is a good thing  
because broken-Selenium-server could not start.

After 7 seconds, 2 firefox windows came to life and Cucumber walked  
through some steps.

Some of the matchers malfunctioned but I feel like I am making some  
progress.

Recap:

- Cucumber wants to start a broken Selenium-server
- I prevent that by starting a selenium-server-1.0.1 by hand before  
I run Cucumber

---

<div class="post-metadata">

**Author:** ![audreylee88](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ecae2f/32.png) [@audreylee88](https://www.ruby-forum.com/u/audreylee88)\
**Post date:** [November 9, 2009, 4:44pm UTC](https://www.ruby-forum.com/t/i-am-looking-for-ror-webrat-selenium-install-recipe/178625/3 "2009-11-09T16:44:27Z")

</div>

Audrey,  
I would suggest, a few things…

1. Updating webrat, selenium-client to the most recent versions and  
cucumber to at least 0.4.2. Don’t forget to run script/generate  
cucumber after you update the cucumber gem.
2. Also you do not need the selenium gem as selenium server comes  
prepackaged with webrat, in its vendor folder.
3. After you’re up and running using those gems its a good idea to  
separate your features or scenarios into two different profiles, plain  
and enhanced for your rails and selenium modes respectively. A good how  
to for this is on Aslak Hellesoy’s cucumber github wiki page for  
selenium.  
[http://wiki.github.com/aslakhellesoy/cucumber/setting-up-selenium](http://wiki.github.com/aslakhellesoy/cucumber/setting-up-selenium) .  
Please note the update at the top of the page.

I’ve found that not all versions of webrat work with all versions of  
cucumber but the most recent of both gems work well for me. Btw, I’m  
running:  
Selenium-client 1.2.17  
Cucumber 0.4.2  
Webrat 0.5.3  
Dbcleaner 0.2.3  
Rails 2.3.2  
Ruby 1.8.6 pl 287

If all else fails I would try the webrat list: removed\_email\_address@domain.invalid.

-Dave  
Sent via BlackBerry by AT&T

---

<div class="post-metadata">

**Author:** ![audreylee88](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ecae2f/32.png) [@audreylee88](https://www.ruby-forum.com/u/audreylee88)\
**Post date:** [November 9, 2009, 7:58am UTC](https://www.ruby-forum.com/t/i-am-looking-for-ror-webrat-selenium-install-recipe/178625/4 "2009-11-09T07:58:09Z")

</div>

For what it’s worth, I follow the recipe in the Beta version of The  
RSpec Book available from [http://www.pragprog.com/](http://www.pragprog.com/) as well as watching  
the cucumber railscasts at [railscasts.com](http://railscasts.com). These are great sources of  
info for configuring and using this stack.

I’m running (ubuntu 9.04):

Ruby version 1.8.7 (i686-linux)  
RubyGems version 1.3.5  
Rack version 1.0  
Rails version 2.3.4  
Active Record version 2.3.4  
Active Resource version 2.3.4  
Action Mailer version 2.3.4  
Active Support version 2.3.4  
Application root /srv/www/lcre  
Environment development  
Database adapter mysql

[  
[‘rspec’, false, ‘\>=1.2.9’],  
[‘rspec-rails’, false, ‘\>=1.2.9’],  
[‘thoughtbot-factory\_girl’, ‘factory\_girl’, ‘\>=1.2.2’],  
[‘cucumber’, false, ‘\>=0.4.3’],  
[‘pickle’, false, ‘\>=0.1.22’],  
[‘webrat’, false, ‘\>=0.5.3’],  
[‘Selenium’, false, ‘\>=1.1.14’],  
[‘selenium-client’, false, ‘\>=1.2.17’],  
[‘rcov’, false, ‘\>=0.9.6’],  
[‘mongrel’, false, ‘\>=1.1.5’],  
[‘launchy’, false, ‘\>=0.3.3’],  
].each do | gem, lib, version |  
unless File.directory?(File.join(Rails.root, ‘vendor/plugins/#  
{gem}’))  
config.gem gem, :lib =\> lib, :version =\> version  
end  
end

with all of the gems actually being at the version specified (as  
opposed to something higher).

env.rb (it’s a bit of a hack right now as I’m playing around trying to  
debug a problem in which Webrat can’t find its ‘within’ method when  
running in selenium mode):

require ‘rubygems’

# Sets up the Rails environment for Cucumber

ENV[“RAILS\_ENV”] ||= “test”  
require File.expand\_path(File.dirname( **FILE** ) + ‘/…/…/config/  
environment’)  
require ‘cucumber/rails/world’

# If you set this to true, each scenario will run in a database

transaction.

# You can still turn off transactions on a per-scenario basis, simply

tagging

# a feature or scenario with the @no-txn tag.

# 

# If you set this to false, transactions will be off for all

scenarios,

# regardless of whether you use @no-txn or not.

# 

# Beware that turning transactions off will leave data in your

database

# after each scenario, which can lead to hard-to-debug failures in

# subsequent scenarios. If you do this, we recommend you create a

Before

# block that will explicitly put your database in a known state.

Cucumber::Rails::World.use\_transactional\_fixtures = false

# since not using transactional fixtures, need to clean out the db

ourselves  
require ‘database\_cleaner’  
require ‘database\_cleaner/cucumber’  
DatabaseCleaner.strategy = :truncation

# If you set this to false, any error raised from within your app will

bubble

# up to your step definition and out to cucumber unless you catch it

somewhere

# on the way. You can make Rails rescue errors and render error pages

on a

# per-scenario basis by tagging a scenario or feature with the @allow-

rescue tag.

# 

# If you set this to true, Rails will rescue all errors and render

error

# pages, more or less in the same way your application would behave in

the

# default production environment. It’s not recommended to do this for

all

# of your scenarios, as this makes it hard to discover errors in your

application.  
ActionController::Base.allow\_rescue = false

require ‘cucumber’

# Comment out the next line if you don’t want Cucumber Unicode support

require ‘cucumber/formatter/unicode’  
require ‘cucumber/webrat/element\_locator’ # Lets you do table.diff!  
(element\_at(‘#my\_table\_or\_dl\_or\_ul\_or\_ol’).to\_table)  
require ‘cucumber/rails/rspec’

#==================================================  
use\_selenium = false

require ‘selenium’ if use\_selenium  
require ‘webrat’  
require ‘webrat/selenium’ if use\_selenium

Webrat.configure do |config|  
config.open\_error\_files = false # Set to true if you want error  
pages to pop up in the browser  
if (!use\_selenium)  
config.mode = :rails  
else  
config.mode = :selenium  
config.selenium\_browser\_startup\_timeout = 10  
config.selenium\_browser\_key = “\*firefox”  
config.application\_framework = :rails  
end

config.application\_environment = :test  
end

if use\_selenium  
class ActiveSupport::TestCase  
setup do |session|  
session.host! “localhost:3001”  
end  
end  
end

#====================================================  
require ‘factory\_girl’  
require File.expand\_path(File.dirname( **FILE** ) + ‘…/…/…/spec/  
factories’)

require ‘pickle/world’

Pickle.configure do |config|  
config.adapters = [:factory\_girl]  
config.map ‘I’, ‘myself’, ‘me’, ‘my’, :to =\> ‘user: “me”’  
end
