Getting Started with Ruby, Cucumber, and Capybara on Windows

August 20, 2011

The Ruby version of Cucumber isn’t just for Rails developers. If you have a .NET or Java web or service app, Ruby can be a great language for testing. With libraries like Capybara for driving web apps and JSON, RestClient, SOAP, and others for interacting with service apps, you’ll find testing in Ruby requires much less code than in C# or Java.

It can be hard to find instructions for setting up Ruby and Cucumber on Windows, though, so I’ve compiled these to help my clients get started, and I thought they might be useful to others. I’ve tested this on a clean Windows 7 VM, and everything works. Your mileage may vary, but let me know if you have any issues.

  1. You’re going to be working in a command window quite a bit with Cucumber. You may want to customize your command window to make it more pleasant to use. I like the following settings (right click on the top left corner of the command window and choose Properties to set these):
    Font: Consolas, 20pt
    Screen Buffer: 120×3000
    Window Size: 120×60

    On a smaller screen, you’ll of course want a smaller window size and screen buffer. If you’re on an earlier version of Windows, you won’t be able to choose Consolas for the font, but Lucida Console is still better than the default.

    I also like to set a PROMPT environment variable to $P$_$+$G (right click on My Computer and choose Properties, then Advanced, then Environment Variables).

  2. Download and install Ruby. For Windows, http://rubyinstaller.org/ is the best option. Install the latest release of version 1.9.2. Make sure you check the option to “Add Ruby executables to your PATH.”
  3. Also install the Ruby Development Kit from the same place, which will allow Ruby to build native extensions for libraries. Instructions are available here: https://github.com/oneclick/rubyinstaller/wiki/Development-Kit.
  4. Confirm that the installation worked by opening a command window and running ruby -v. You should see a description of the Ruby version installed. If you see an error, something went wrong with the installation.
  5. Make sure you have RubyGems installed by running gem -v on a command line. RubyGems is the package manager for Ruby and should come with the standard Ruby installation.
  6. Run gem install cucumber to download and install Cucumber. Run cucumber --help to confirm that it worked.
  7. Cucumber complains that you need ANSICON to get console colors because Windows doesn’t understand ANSI color escape sequences. Download ANSICON from http://adoxa.3eeweb.com/ansicon/. Extract it somewhere (I put it in c:utils). In your command window, cd to either the x86 or x64 directory where you extracted ANSICON, depending on your OS, and run ansicon -i. Exit that command window and open a new one. Now, when you run cucumber --help, you should no longer see the message in the output about needing ANSICON.
  8. Run gem install capybara to download and install the Capybara web automation library.
  9. Run gem install rspec to download and install a nice library for readable assertions (among other things).
  10. You’ll want Firefox with the Firebug plugin to do UI-related tests. If you haven’t already, install those.
  11. You can edit Cucumber tests and automation code in Notepad, Visual Studio, or any other text editor. But I like having an editor that knows about Cucumber and provides Cucumber-oriented features, so I use JetBrains RubyMine to work with my Cucumber tests. There’s a free 30 day trial available.
  12. To make sure Cucumber and Capybara are working nicely together, download and extract this Ruby, Cucumber, and Capybara Starter Project somewhere on your machine. Open a command window at the root of the folder (if you run dir or ls there, you should see a “features” folder). Run cucumber, and you should see all the tests run and pass.

Update 4/15/2013 — Blog comments aren’t a good place to answer detailed technical questions, so I’ve closed commenting on this post. I encourage you to use the Cucumber and Capybara Google Groups if you run into problems.

Vimal November 14, 2011 at 12:11 am

Hi,

This is a great posting and very explanatory. However the purpose i was reading through it from the subject is not explained here. I was looking for something to know, how can i test my windows application with cucumber and Ruby.

Maybe as i am new to, i might not have understood most., but is it possible to explain it in detail. On can we test Windows based application using Ruby and cucumber.

Thanks,
Vimal

Richard Lawrence November 14, 2011 at 8:28 am

@Vimal – This post is about testing a web application from Windows using Ruby. I’m not sure what Windows application drivers are available in Ruby, though a quick search turned up win32-autogui. You might try that in place of Capybara.

Serguei Cambour November 21, 2011 at 3:50 am

I got a Timeout error:
[code]
Feature: Demo
Make sure Cucumber and Capybara are wired up properly

Scenario: Search Google # featuresdemo.feature:4
When I search Google for "cucumber" # features/step_definitions/demo_steps.rb:1
Timeout::Error (Timeout::Error)
C:/Ruby192/lib/ruby/1.9.1/net/protocol.rb:140:in `rescue in rbuf_fill'
C:/Ruby192/lib/ruby/1.9.1/net/protocol.rb:134:in `rbuf_fill'
C:/Ruby192/lib/ruby/1.9.1/net/protocol.rb:116:in `readuntil'
C:/Ruby192/lib/ruby/1.9.1/net/protocol.rb:126:in `readline'
C:/Ruby192/lib/ruby/1.9.1/net/http.rb:2219:in `read_status_line'
C:/Ruby192/lib/ruby/1.9.1/net/http.rb:2208:in `read_new'
C:/Ruby192/lib/ruby/1.9.1/net/http.rb:1191:in `transport_request'
C:/Ruby192/lib/ruby/1.9.1/net/http.rb:1177:in `request'
C:/Ruby192/lib/ruby/1.9.1/net/http.rb:1170:in `block in request'
C:/Ruby192/lib/ruby/1.9.1/net/http.rb:627:in `start'
C:/Ruby192/lib/ruby/1.9.1/net/http.rb:1168:in `request'
./features/step_definitions/demo_steps.rb:2:in `/^I search Google for "(.*)"$/'
featuresdemo.feature:5:in `When I search Google for "cucumber"'
Then there should be a result for "cukes.info/" # features/step_definitions/demo_steps.rb:7

Failing Scenarios:
cucumber featuresdemo.feature:4 # Scenario: Search Google

1 scenario (1 failed)
2 steps (1 failed, 1 skipped)
1m19.597s
[/code]
on Windows XP, SP3, behind a proxy,
RubyGems Environment:
– RUBYGEMS VERSION: 1.7.2
– RUBY VERSION: 1.9.2 (2011-07-09 patchlevel 290) [i386-mingw32]
– INSTALLATION DIRECTORY: C:/Ruby192/lib/ruby/gems/1.9.1
– RUBY EXECUTABLE: C:/Ruby192/bin/ruby.exe
– EXECUTABLE DIRECTORY: C:/Ruby192/bin
– RUBYGEMS PLATFORMS:
– ruby
– x86-mingw32
– GEM PATHS:
– C:/Ruby192/lib/ruby/gems/1.9.1
– U:/.gem/ruby/1.9.1
– GEM CONFIGURATION:
– :update_sources => true
– :verbose => true
– :benchmark => false
– :backtrace => false
– :bulk_threshold => 1000
– REMOTE SOURCES:
http://rubygems.org/
- cucumber version : 1.7.2

Richard Lawrence November 21, 2011 at 8:35 am

@Serguei – Your timeout seems be related to your proxy. I haven’t tried Capybara with a proxy. It’s using Net::Http under the covers (as you can see from the stack trace). I’d suggest searching for “ruby net http proxy” or something similar to see what you can turn up. Or, post your question to the Capybara Google group.

Vikram February 7, 2012 at 12:51 am

I downloaded ansicon from Github, but there is no executable in it. CMD does not recognizes the ansicon command.

Richard Lawrence February 7, 2012 at 6:53 am

@Vikram – Github only has the source code for ansicon. Looks like the download link for ansicon in my post had broken for some reason. I’ve updated it to the new one: http://adoxa.3eeweb.com/ansicon/. You should find an executable in that package.

Serguei Cambour February 7, 2012 at 6:57 am

You should download a zip file ‘ansi150.zip’ from: https://github.com/adoxa/ansicon/downloads. Unzip it somewhere and you will get a folder that contains x64, x86 folders and some C files. Inside of ‘x86′ folder you will find a ‘ansicon.exe’ file to be executed. You can later create a shortcut on your desktop pointing to it.

Vikram February 7, 2012 at 11:58 pm

Richard, thanks a bunch for the new link!

Deola March 19, 2012 at 6:30 pm

Mr Richard Lawrence , you have save me from countless hours of trying to get cucumber working on my system ,i am very grateful to you for putting up this tutorial

Allison March 28, 2012 at 5:23 am

When I attempted to run the command “gem install cucumber”, I obtained the below error:
Error: Error installing cucumber:
ERROR: Failed to build gem native extension.
C:/Ruby187/bin/ruby.exe extconf.rb creating Makefile
make
‘make’ is not recognized as an internal or external command, operable program or batch file.

I am using Windows7.

Richard Lawrence March 28, 2012 at 7:27 am

@Allison – Did you install the DevKit mentioned in step 3? Your error looks like the tools to compile a C extension are missing.

Allison March 29, 2012 at 5:19 am

Thank you Richard for your prompt response. I did omit extracting the files in the DevKit. I have now successfully installed cucumber.

Moy July 6, 2012 at 4:42 am

absolutely flawless instruction .. Thank you

Irvin July 27, 2012 at 9:53 am

Very easy to follow and clear instructions. You’re page has saved me numerous hours of searching for details on Ruby and Cucumber set up for Windows.

Many thanks.

Oliver August 27, 2012 at 10:07 am

I’m getting a 404 error on the link: Ruby, Cucumber, and Capybara Starter Project.
It would be great to look at the project

Richard Lawrence August 27, 2012 at 1:44 pm

@Oliver – Not sure why that file was missing, but I’ve uploaded it again, and it seems to work now. Thanks for letting me know.

ram August 31, 2012 at 3:02 pm

Any suggestions for a free IDE for Ruby + Cucumber than JetBrains RubyMine

Richard Lawrence September 1, 2012 at 5:27 pm

I don’t know of a good free alternative to RubyMine. There’s a Cucumber plugin for Vim if you like that.

ram September 4, 2012 at 11:02 am

I am trying to explore: Aptana Studio/ NetBeans IDE with some plugins, hope it will work out, if not I will take a look at this one: http://qastrategies.blogspot.com/2012/06/bdd-framework-to-run-groovy-scripts.html

Harv Gill October 11, 2012 at 4:51 pm

I use “Sublime Text 2″ it’s not free, but it’s free to try for an unlimited amount of time. It’s also not as sophisticated as Aptana Studio or RubyMine, but I like it a lot because it still has auto complete for functions/variablenames, etc…

LongRed November 5, 2012 at 1:34 pm

There’ s a syntax highlighting for notepad++ around.

Heider October 24, 2012 at 3:18 pm

I have the following error: Ruby on Rails – error when running cucumber: You have already activated activesupport 3.2.8, but your Gemfile requires activesupport 3.1.0.

any one can help

Richard Lawrence October 24, 2012 at 7:06 pm

@Heider – I’d recommend posting to the cukes Google group or a Rails community. You’ll get better help there.

Karol October 26, 2012 at 5:44 am

Nice tutorial but can you explain what all those files in side the ruby-capybara do ?
like inside the .idea folder and so on. how to they link to other components, which files are necessary for the project to run. How do you actually build a project form scratch.

Thanks

Richard Lawrence October 26, 2012 at 7:41 am

@Karol – The ruby-capybara Google group would be a good place to ask your questions.

Neeraj Srivastava November 8, 2012 at 6:08 am

This is my first time I am trying this tool for my web-based application… Looking for more support on this..

Richard Lawrence November 8, 2012 at 6:59 am

@Neeraj – Check out the cukes and ruby-capybara Google groups for places to get answers as you learn the tools.

TJ_M December 5, 2012 at 9:04 am

Brilliant! many thanks…

I’m a newbie who has run into some capybara-webkit issues who truly appreciates the help in proving I can establish some functionality in my windows7 environment.

I ran your cucumber test. The 1 scenario and the 2 steps all passed. Firefox window launched, ran the test, and then shut down as quickly.

One (two) question(s): Is the following error message expected? Or does it suggest I still have a configuration issue?
!!! error running onStopped callback: TypeError: callback is not a function
*** LOG addons.xpi: shutdown

Richard Lawrence December 5, 2012 at 10:34 am

The capybara Google group would be your best place to get an answer.

trevor December 30, 2012 at 8:55 pm

Richard -

THANK YOU!!! You didn’t miss a step. I cannot tell you how frustrated I get by the amazing amount of omissions people tend to have in this kind of instruction. Yours were flawless.

I do have one question though. I get 1 scenario (i passed) then, 2 steps (2 passed) but then…
!!! error running onStopped callback: TypeError: callback is not a function…

do you get this error?

Richard Lawrence December 31, 2012 at 8:23 am

@trevor – This looks like an issue between Selenium and Firefox. The capybara Google group would be your best place to get a specific answer on what to do about it.

Deepak Uppal January 24, 2013 at 4:52 am

Thanks a lot for this Richard. I got the project set up nicely and the tests run fine. But I am also getting the same error mentioned by trevor i.e.

“!!! error running onStopped callback: TypeError: callback is not a function…”

I get this after the execution is finished.

Yamini Patel March 11, 2013 at 9:47 am

I am getting following message: Not sure what I am doing wrong. Everything installed fine.

C:\Ruby187\bin>cucumber
Feature: Demo
Make sure Cucumber and Capybara are wired up properly

Scenario: Search Google # features\demo.feature:4
When I search Google for “cucumber” # features\demo.feature:5
Then there should be a result for “cukes.info/” # features\demo.feature:6

1 scenario (1 undefined)
2 steps (2 undefined)
0m0.025s

You can implement step definitions for undefined steps with these snippets:

When(/^I search Google for “(.*?)”$/) do |arg1|
pending # express the regexp above with the code you wish you had
end

Then(/^there should be a result for “(.*?)”$/) do |arg1|
pending # express the regexp above with the code you wish you had
end

If you want snippets in a different programming language,
just make sure a file with the appropriate file extension
exists where cucumber looks for step definitions.

Richard Lawrence March 11, 2013 at 11:47 am

@Yamini – That’s Cucumber not being able to find the Ruby step definitions. They should be under features/step_definitions from your working directory. Are they?

sudha April 8, 2013 at 8:52 am

HI

I am new using ruby and cucumber. I installed ruby and all the gem files etc. however, I do not know how to use cucumber. Can you please guide me. I appreciate your help. Thanks.

sudha April 10, 2013 at 6:13 am

HI

Thanks for your response. I have all these under features/step definitions in my C: \ directory. However, when I type in to the command prompt it comes back as project folder not found. Can you please help me. thanks.

Ben April 9, 2013 at 1:03 pm

Great help. Thanks much! FYI – I was getting a “stack level too deep (SystemStackError)” at gherkin_builder.rb:100, but when I switched from Ruby 2.0.0 to 1.9.3 the problem went away.

sudha April 15, 2013 at 7:10 am

HI

I created a features directory and ran cucumber and I am getting0scenarios, 0 steps and 0m0.000…After this what do I need to enter in the command to create or adding a scenario. I am new to cucumber. I am learning. I have not used command. Please help me with the commands that I can enter in order to set up a scenario to get fail and pass results. I appreciate your help.
If I type features/adding.feature: I am getting an error saying feature is not recognized as an internal or external command operable program or batch file error.

Richard Lawrence April 15, 2013 at 7:16 am

@sudha – Try using the starter project in step 12 above, which will give you all the pieces you need. You might also check out the Cucumber website, which has links to tutorials and other documentation.

Previous post:

Next post: