follow me icons

Setting up/Installing Cucumber Automation

Steps by Steps guide to Setup/Install Cucumber automation test using Selenium webdriver in Ruby


This is a guide on how to create a project to setup/install a cucumber automation test using Selenium Webdriver in Ruby. I will assume that the OS platform is in Windows. I will cover how to setup the project in Ubuntu in a different blog.

Please note that there are many ways to do this. This is just the way I setup a new project. I use Capybara in my automation project.

The first part is to setup ruby and ruby gems into your local machine.

1. Download ruby
2. Download RubyMine
3. Open command line prompt in windows and type "set http_proxy=proxy-name:8080"
- You only need to do this step if you need to use proxy to access the net. We will need it so that we can download the ruby gems
4. Gem install cucumber
5. Gem install rake -v 0.8.7
6. Gem install rspec -v 1.2.8
7. Gem install capybara
8. Gem install gizmo -v 0.1.1
9. Gem install term-ansicolor

The second part is to create a new project:

You might want to read more about Cucumber, Steps definitions, and Page Models before continuing on the steps.

1. Open ruby mine and create a new project
2. Create the following directories
"features/regression"
"features/step_definitions"
"features/support/pages"
"features/support/patches"

The following steps are to initialize cucumber

3. Create a new file called "env.rb" under "features/support"

require 'uri'
require 'net/http'

#CAPYBARA
require 'capybara/cucumber'
require 'capybara/session'
require 'features/support/patches/capybara'
Capybara.default_driver = :selenium
Capybara.run_server = false
Capybara.default_selector = :css
Capybara.default_wait_time = 20

#gizmo!!
require 'gizmo'
World(Gizmo::Helpers)

Gizmo.configure do |config|
  config.mixin_dir = File.dirname(__FILE__) + '/../pages'
end

4. Create a new file called "capybara.rb" under "features/support/patches"
if Object.const_defined? :Capybara
    module Capybara
        alias :response :page
    end
end

5. Create a new file called "cucumber.yml" at the top level directory

default: -r features/support/ -r features/step_definitions

Writing the Cucumber Scenarios file

6. Create a new file called "search.feature" under "features/regression"
Feature: A simple google search

Scenario: A simple google search scenario
  Given I am on the main google search
  And I search for "site:qastuffs.blogspot.com"
  
  When I click on the search button
  And I click on the first result
  Then I should land on the qastuffs blog

Writing the Steps Definitions

7. Create a new file called "search_steps.rb" under "features/steps_definitions"
Given /^I am on the main google search$/ do
  visit "http://www.google.com"
end

Given /^I search for "([^\"]*)"$/ do |query|
  on_page_with :google do |page|
    page.fill_in_search query
  end
end

Then /^I click on the search button$/ do
  on_page_with :google do |page|
    page.click_submit_button
  end
end

Then /^I click on the first result$/ do
  on_page_with :google do |page|
    page.click_first_result
    page.should have_css(page.qastuffs_main_css)
  end
end

Then /^I should land on the qastuffs blog$/ do
  on_page_with :qastuffs do |page|
    page.valid?.should == true
  end
end

Writing the Page Definitions

8. Create a new file called "page_with_google.rb" under "features/support/pages"
module PageWithGoogle
  include Gizmo::PageMixin

  def valid?
    if title =~ /.*Google.*/
      return true
    else
      return false
    end
  end

  def title
    find(:xpath, "//title").text
  end

  def fill_in_search query
    fill_in 'q', :with=> query
  end

  def click_submit_button
    click_button "Google Search"
  end

  def qastuffs_main_css
    ".description"
  end

  def click_first_result
    find(:xpath, ".//*[@id='rso']/li[1]/h3/a").click
  end
  
end
9. Create a new file called "page_with_qastuffs.rb" under "features/support/pages"
module PageWithQastuffs
  include Gizmo::PageMixin

  def valid?
    title.should =~ /.*QA Blog.*/
  end

  def title
    find(:xpath, "//title").text
  end
   
end

How to run the Cucumber Test

10. Open command line prompt
11. Go to the project
12. Type "cucumber features\regression\search.feature"

The above command will run the test for search.feature.

Note that if you need to run the test against multiple URL/environments, you can setup a YAML configuration file. Instruction on how to do it can be found here

54 comments:

  1. I am trying to run this example on my win 7 box it shows error
    Given I am on the main google search # step_defination/google.rb:1
    undefined method `visit' for # (NoMethodError)
    ./step_defination/google.rb:2:in `/^I am on the main google search$/'
    google.feature:4:in `Given I am on the main google search'

    Please suggest something for that.

    All gems are installed those you mentioned above of this example.

    Thanks
    M

    ReplyDelete
  2. Hi Muhammad,

    It seems that the script does not recognize the "visit" method and most probably is because some of the gems (capybara or selenium webdriver) could be missing or the script could not find the gems correctly.

    Please try to download the code from this github
    https://github.com/giozom/Cucumber-Test-Framework-for-Newbies and see if you still have the same problem.

    You might also want to change ./step_defination into ./step_definition. If you use RubyMine, this will allow RubyMine to be able to detect your steps definition enabling it to give you easy access to step definition from the feature files.

    BA

    ReplyDelete
  3. Hi Bananta,

    Thanks much for your reply. I have installed the gem from scratch now Visit method is working but the same error on locate method now.Locate method is also part of capybara.Please suggest.

    ReplyDelete
  4. Hi Muhammad,

    Could you try changing "locate" to "find". I think locate method has been deprecated from Capybara 0.4.0.

    What version of Capybara are you using? The example above was created using Capybara 0.3.9. Please see this blog to upgrade to Capybara 0.4.0. http://qastuffs.blogspot.com/2010/11/upgrading-to-capybara-040.html.

    Could you also give me the error message as well?

    ReplyDelete
  5. Hi Bananta,
    I have sorted the above issues and thanks for your help.
    I am getting problem when I want to execute my this feature file behind the proxy.Proxy doesn't allow the web driver to execute my test.Any suggestion please.

    thanks
    M

    ReplyDelete
  6. Hi Muhammad,

    You can use this blog to help you sort out the proxy issue. http://qastuffs.blogspot.com/2010/09/bypassing-proxy-setting-using-webdriver.html

    ReplyDelete
  7. You use this method for title

    def title
    @document.xpath("//title").inner_text
    end


    How we will handle if we want to validate the buttons on web page.

    ReplyDelete
  8. The above method is just to check the homepage title. What do you mean to validate the button?

    The way I validate the button is usually to just click the button itself. If the next response after clicking the button is correct then the button is validated.

    To click the button you can simply use the following method:

    find(:css, ".the_button_css").click

    ReplyDelete
  9. Hi Bananta,

    I want to check the button is available on my main page.My html tag is like that on my main page.
    I have addedd extra s in class and on span so it doesnot accept class attribute your blog page
    Search and in start a is a tag like

    a idd="CMDnnn" classs="button search submit-on-click" href="#">Ssearch /a

    Please suggest somewhat

    ReplyDelete
  10. Hi Muhammand,

    In that case you can try using the has_css methods to validate the button in the def valid? method. This will validate the button whenever the page is laoded.

    def valid?
    has_css?("#CMDnnn").should == true
    end

    Below is the list of available methods that Capybara has (taken from https://github.com/jnicklas/capybara)

    "
    Querying

    Capybara has a rich set of options for querying the page for the existence of certain elements, and working with and manipulating those elements (see Capybara::Node::Matchers).

    page.has_selector?('table tr')
    page.has_selector?(:xpath, '//table/tr')
    page.has_no_selector?(:content)

    page.has_xpath?('//table/tr')
    page.has_css?('table tr.foo')
    page.has_content?('foo')

    You can use these with RSpec’s magic matchers:

    page.should have_selector('table tr')
    page.should have_selector(:xpath, '//table/tr')
    page.should have_no_selector(:content)

    page.should have_xpath('//table/tr')
    page.should have_css('table tr.foo')
    page.should have_content('foo')
    page.should have_no_content('foo')

    Note that page.should have_no_xpath is preferred over page.should_not have_xpath. Read the section on asynchronous JavaScript for an explanation. "

    ReplyDelete
  11. Thanks Ban!

    Quick question.
    Can we count number of characters in a specific field?

    like
    fill_in 'fieldID', :with => 'aaaabbbbbbccc1$#2222'

    Now I want to count how many character i have entered.

    Suggest somewot plz.

    Thanks

    ReplyDelete
  12. Hi

    We can count the character using following command its not mentioned in capybara Rdoc but it works

    page.find_field('searchString').value.size.should==230

    Thanks
    M

    ReplyDelete
  13. Hi Bananta,

    When I run the cucumber features\regression\search.feature command I get an error:
    no such file to load -- features/support/patches/capybara

    Everything appears to be setup correctly, any thoughts?

    ReplyDelete
  14. Did you put the capybara.rb in the correct directory? /features/support/patches/capybara?

    In which directory did you run the cucumber?

    If you still get the error, I would need more information on the error such as your directory structure, etc.

    ReplyDelete
  15. I downloaded your file from github and installed the specified versions of the gems you list in this post. I created a new rails app and copied the contents of the download into the application. I had to modify on line in the env.rb file to correct one error. This is the edited line:
    require File.dirname(__FILE__) + '/lib/configuration';

    This is the only change I've made. My folder structure is exactly like you have it on github. After setting my test_env and running cucumber features ( or the full command listed in my previous post ) I get an error:

    no such file to load -- features/support/patches/capybara (LoadError)
    :29:in `require'
    :29:in `require'
    C:/Ruby192/lib/ruby/gems/1.9.1/gems/polyglot-0.3.1/lib/polyglot.rb:64:in `requir
    e'
    C:/Ruby192/groups/features/support/env.rb:11:in `'
    :29:in `require'
    :29:in `require'
    C:/Ruby192/lib/ruby/gems/1.9.1/gems/polyglot-0.3.1/lib/polyglot.rb:64:in `requir
    e'
    C:/Ruby192/lib/ruby/gems/1.9.1/gems/cucumber-0.6.4/lib/cucumber/rb_support/rb_la
    nguage.rb:124:in `load_code_file'
    C:/Ruby192/lib/ruby/gems/1.9.1/gems/cucumber-0.6.4/lib/cucumber/step_mother.rb:8
    5:in `load_code_file'
    C:/Ruby192/lib/ruby/gems/1.9.1/gems/cucumber-0.6.4/lib/cucumber/step_mother.rb:7
    7:in `block in load_code_files'
    C:/Ruby192/lib/ruby/gems/1.9.1/gems/cucumber-0.6.4/lib/cucumber/step_mother.rb:7
    6:in `each'
    C:/Ruby192/lib/ruby/gems/1.9.1/gems/cucumber-0.6.4/lib/cucumber/step_mother.rb:7
    6:in `load_code_files'
    C:/Ruby192/lib/ruby/gems/1.9.1/gems/cucumber-0.6.4/lib/cucumber/cli/main.rb:48:i
    n `execute!'
    C:/Ruby192/lib/ruby/gems/1.9.1/gems/cucumber-0.6.4/lib/cucumber/cli/main.rb:20:i
    n `execute'
    C:/Ruby192/lib/ruby/gems/1.9.1/gems/cucumber-0.6.4/bin/cucumber:8:in `'
    C:/Ruby192/bin/cucumber:19:in `load'
    C:/Ruby192/bin/cucumber:19:in `'

    ReplyDelete
  16. I've resolved that issue by editing another line in the env.rb file. Edited line is :
    require File.dirname(__FILE__) + '/patches/capybara'

    However, when I run the features the result is that non of the steps are defined.

    ReplyDelete
  17. And I resolved this issue by changing the folder steps_definitions to step_definitions. Works like a charm. Thanks for this post and for putting this up on github.

    ReplyDelete
  18. Glad to know that you resolve the problem. The reason why you need to defined the folder as step_definitions is because the cucumber.yml file is looking for that directory.

    default: -r features/support/ -r features/step_definitions

    ReplyDelete
  19. Right, but you guys might want to change in on github.

    ReplyDelete
  20. Thanks. I will let the owner of that github to change it then.

    ReplyDelete
  21. Hello! I am newby. Actually I am so newbie that you can't imaging... I didn't no programming at all((. Just begin with ruby. So please heeelp!!!) Could you give me a list of materials I must to read to understand how does it work.. Every line in your example-framework. For the moment when I run "cucumber features\regression\search.feature" error no such file to load -- spec/expectations (LoadError) appears. Is it ok? What should I do to make browser execute the case?

    ReplyDelete
  22. One more question. How can I modify your framework to run a test in several browsers in turn? Thanks a lot your examples very informative and super useful!

    ReplyDelete
  23. You can just open up several terminals and run cucumber at the same time.

    ReplyDelete
  24. And what should I do to keep browser open after test?

    ReplyDelete
  25. You can use Ruby-debug to keep the browser open after the test.

    http://qastuffs.blogspot.com/2010/10/debug-your-web-test-with-ruby-debug.html

    Or alternatively if you want a quick way to keep your browser open, you can just use the ruby sleep method to pause the test temporarily. e.g sleep 10000.

    ReplyDelete
  26. Hi,

    I also followed step by step the process mentioned here but while installing i took the latest version of all the gems, please find below their details:
    Ruby 1.9.3
    Cucumber 1.1.4
    rake 0.9.2.2
    rspec 2.7.0
    Install DevKit config.yml
    capybara 1.1.2
    gizmo 0.1.1
    win-32 process 0.6.5
    win-32 console 1.3.0-x86
    rails 3.2.0
    cucumber-rails 1.2.1

    After installing ruby mine i additionally installed rails-3.2.0 and cucumber-rails-1.2.1

    After placing all the files when i tried to execute the search on google it showed me the following error:
    cannot load such file -- spec/expectations (LoadError)

    Also, when I installed cucumber-rails and tried to run 'ruby script/generate cucumber' it didn't worked.

    ReplyDelete
  27. Hi, I had problems installing capybara as the version of ffi it was pulling down has problems compiling in windows (1.0.11). I follewed details found here: http://stackoverflow.com/questions/7852566/error-error-installing-ffi-error-failed-to-build-gem-native-extension
    and installed ffi 1.0.9 before running the capybara install. It then installed fine.

    ReplyDelete
  28. Hi,
    Thanks for your post on this. I've run into a problem I cannot solve... when I run the feature it returns an error as follows:
    Using the default profile...
    cannot load such file -- features/support/patches/capybara (LoadError)
    C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    C:/Workspaces/Lua Development Tools/Tournament WebApp/features/support/env.rb:8:in `'
    C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.1.9/lib/cucumber/rb_support/rb_language.rb:129:in `load'
    C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.1.9/lib/cucumber/rb_support/rb_language.rb:129:in `load_code_file'
    C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.1.9/lib/cucumber/runtime/support_code.rb:171:in `load_file'
    C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.1.9/lib/cucumber/runtime/support_code.rb:83:in `block in load_files!'
    C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.1.9/lib/cucumber/runtime/support_code.rb:82:in `each'
    C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.1.9/lib/cucumber/runtime/support_code.rb:82:in `load_files!'
    C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.1.9/lib/cucumber/runtime.rb:175:in `load_step_definitions'
    C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.1.9/lib/cucumber/runtime.rb:40:in `run!'
    C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.1.9/lib/cucumber/cli/main.rb:43:in `execute!'
    C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.1.9/lib/cucumber/cli/main.rb:20:in `execute'
    C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.1.9/bin/cucumber:14:in `'
    C:/Ruby193/bin/cucumber:19:in `load'
    C:/Ruby193/bin/cucumber:19:in `'

    I don't know where to go from here. Could you help?
    Thanks.

    ReplyDelete
    Replies
    1. Hi Mark,

      How do you run cucumber from your command line?

      Also you need to use ruby 1.8.7 instead of 1.9
      http://rubyforge.org/frs/download.php/72085/rubyinstaller-1.8.7-p302.exe

      Delete
  29. Hi, yes I was running from my command line. Since downgrading my Ruby install the test started working. I did also need to make a change to the step_definition folder... to call it "step_definitions". You mention both with and without the "s" above and I didn't pick up on the change at first.
    Thanks.

    ReplyDelete
    Replies
    1. Yes you need to have step_definitions otherwise cucumber won't be able to pick up the steps. I have corrected the error. Thanks!

      Delete
  30. Hey Guys,

    I am also experiencing the same as Mark Jones's post. I am running Ruby 1.8.7 without rails as not needed. I am running this on a vm machine.

    vagrant@hamza-exploring-test:~/cucumber/features$ cucumber
    no such file to load -- features/support/patches/capybara (LoadError)
    :29:in `require'
    :29:in `require'
    /home/vagrant/cucumber/features/support/env.rb:41:in `'
    /var/lib/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/rb_support/rb_language.rb:129:in `load'
    /var/lib/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/rb_support/rb_language.rb:129:in `load_code_file'
    /var/lib/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/runtime/support_code.rb:171:in `load_file'
    /var/lib/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/runtime/support_code.rb:83:in `block in load_files!'
    /var/lib/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/runtime/support_code.rb:82:in `each'
    /var/lib/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/runtime/support_code.rb:82:in `load_files!'
    /var/lib/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/runtime.rb:175:in `load_step_definitions'
    /var/lib/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/runtime.rb:40:in `run!'
    /var/lib/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/cli/main.rb:43:in `execute!'
    /var/lib/gems/1.9.1/gems/cucumber-1.2.1/lib/cucumber/cli/main.rb:20:in `execute'
    /var/lib/gems/1.9.1/gems/cucumber-1.2.1/bin/cucumber:14:in `'
    /var/lib/gems/1.9.1/bin/cucumber:19:in `load'
    /var/lib/gems/1.9.1/bin/cucumber:19:in `'

    ReplyDelete
    Replies
    1. Hi Hamza,

      Could you try running the cucumber from the cucumber folder instead of cucumber/feature.

      So you would run it like this:

      vagrant@hamza-exploring-test:~/cucumber$ cucumber features

      Delete
  31. Hi,

    After following above steps I get the following output, please advise what I need to do to get test running, and what to expect to see. Thanks.

    Output

    C:\Users\Rahul\RubymineProjects\Test1>cucumber features\regression\search.featur
    e
    *** WARNING: You must use ANSICON 1.31 or higher (http://adoxa.110mb.com/ansicon
    ) to get coloured output on Windows
    Using the default profile...
    undefined method `page' for module `Capybara' (NameError)
    ./features/support/patches/capybara.rb:3
    C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original
    _require'
    C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
    C:/Users/Rahul/RubymineProjects/Test1/features/support/env.rb:7
    C:/Ruby187/lib/ruby/gems/1.8/gems/cucumber-1.2.1/bin/../lib/cucumber/rb_support/
    rb_language.rb:129:in `load'
    C:/Ruby187/lib/ruby/gems/1.8/gems/cucumber-1.2.1/bin/../lib/cucumber/rb_support/
    rb_language.rb:129:in `load_code_file'
    C:/Ruby187/lib/ruby/gems/1.8/gems/cucumber-1.2.1/bin/../lib/cucumber/runtime/sup
    port_code.rb:171:in `load_file'
    C:/Ruby187/lib/ruby/gems/1.8/gems/cucumber-1.2.1/bin/../lib/cucumber/runtime/sup
    port_code.rb:83:in `load_files!'
    C:/Ruby187/lib/ruby/gems/1.8/gems/cucumber-1.2.1/bin/../lib/cucumber/runtime/sup
    port_code.rb:82:in `each'
    C:/Ruby187/lib/ruby/gems/1.8/gems/cucumber-1.2.1/bin/../lib/cucumber/runtime/sup
    port_code.rb:82:in `load_files!'
    C:/Ruby187/lib/ruby/gems/1.8/gems/cucumber-1.2.1/bin/../lib/cucumber/runtime.rb:
    175:in `load_step_definitions'
    C:/Ruby187/lib/ruby/gems/1.8/gems/cucumber-1.2.1/bin/../lib/cucumber/runtime.rb:
    40:in `run!'
    C:/Ruby187/lib/ruby/gems/1.8/gems/cucumber-1.2.1/bin/../lib/cucumber/cli/main.rb
    :43:in `execute!'
    C:/Ruby187/lib/ruby/gems/1.8/gems/cucumber-1.2.1/bin/../lib/cucumber/cli/main.rb
    :20:in `execute'
    C:/Ruby187/lib/ruby/gems/1.8/gems/cucumber-1.2.1/bin/cucumber:14
    C:/Ruby187/bin/cucumber:19:in `load'
    C:/Ruby187/bin/cucumber:19

    ReplyDelete
    Replies
    1. 1. You can install ansicon to get the coloured output by following this blog
      http://qastuffs.blogspot.com.au/2011/02/how-to-install-ansicon-for-cucumber-to.html

      2. for the error undefined method `page' for module `Capybara' (NameError) did you follow the steps to create the pages? It seems that the error is just because your env.rb is not defined properly. can you show what you get when you do "gem list"

      Delete
    2. I am getting same error with undefined method 'page' for module 'Capybara' (NameError). Am I supposed to look for a particular ge in the gem list? MY env.rb looks like this:
      require 'uri'
      require 'net/http'

      #CAPYBARA
      require 'capybara/cucumber'
      require 'capybara/session'
      require 'capybara/rails'
      #require 'features/support/patches/capybara'
      #require File.dirname(__FILE__) + '/lib/configuration';
      require File.dirname(__FILE__) + '/patches/capybara';
      Capybara.default_driver = :selenium
      Capybara.run_server = false
      Capybara.default_selector = :css
      Capybara.default_wait_time = 20

      #gizmo!!
      require 'gizmo'
      World(Gizmo::Helpers)

      Gizmo.configure do |config|
      config.mixin_dir = File.dirname(__FILE__) + '/../pages'
      end

      any help is really apprciated ...

      Delete
  32. This comment has been removed by the author.

    ReplyDelete
  33. Below is gem list output

    *** LOCAL GEMS ***

    activesupport (2.3.14)
    addressable (2.3.2)
    builder (3.0.0)
    capybara (1.1.2)
    childprocess (0.3.5)
    cucumber (1.2.1)
    cukable (0.1.3)
    diff-lcs (1.1.3)
    ffi (1.1.5)
    gherkin (2.11.1 x86-mingw32)
    gizmo (0.1.1)
    json (1.7.4)
    libwebsocket (0.1.5)
    mime-types (1.19)
    multi_json (1.3.6)
    nokogiri (1.5.5 x86-mingw32)
    rack (1.4.1)
    rack-test (0.6.1)
    rake (0.8.7)
    rspec (1.2.8)
    rubyslim-unofficial (0.0.2)
    rubyzip (0.9.9)
    selenium-webdriver (2.25.0)
    term-ansicolor (1.0.7)
    tilt (1.3.3)
    xpath (0.1.4)

    ReplyDelete
  34. Afternoon Guys.

    am having same problem installing error occurs

    trying to run a quick test which passes test .com.google.search

    on rubymine ballon appears missing gems to run the test above can you help guys

    ERROR: While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions into the /usr/bin directory.

    ReplyDelete
    Replies
    1. you can ignore the rubymine ballon problem as you are running the test using the command line and not through rubymine.

      As for the problem, you need to install it with with sudo gem install as you don't have the write permission.

      Delete
  35. Afternoon Guys.

    am having same problem installing error occurs

    trying to run a quick test which passes test .com.google.search

    on rubymine ballon appears missing gems to run the test above can you help guys

    ERROR: While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions into the /usr/bin directory.

    ReplyDelete
  36. I followed theabove steps i got load error.Then i changed my ruby version from 1.9.3 to 1.8.7.Now when i ran "cucumber features\regression\search.feature" i got cucumber is not recognised as external or internal command". when i tried to install cucumber again i am getting "ERROR: Error installing cucumber:
    The 'json' native gem requires installed build tools.

    Please update your PATH to include build tools or download the DevKit
    from 'http://rubyinstaller.org/downloads' and follow the instructions
    at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit'

    please suggest what i need to do.

    ReplyDelete
    Replies
    1. Try installing ruby dev kit http://qastuffs.blogspot.com.au/2010/10/how-to-install-ruby-debug-gems-on.html or install http://railsinstaller.org/ to download and install the ruby development kit.

      Delete
    2. I installed dev kit.the issue is resolved.but after running cucumber features\regression\search.feature i am now getting"Scenario: A simple google search scenario # search.feature:3
      Given I am on the main google search # search.feature:4
      And I search for "site:qastuffs.blogspot.com" # search.feature:5
      And I click on the search button # search.feature:6
      And I click on the first result # search.feature:7
      Then I should land on the qastuffs blog # search.feature:8

      1 scenario (1 undefined)
      5 steps (5 undefined)
      0m0.047s

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

      Given /^I am on the main google search$/ do
      pending # express the regexp above with the code you wish you had
      end

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

      Given /^I click on the search button$/ do
      pending # express the regexp above with the code you wish you had
      end

      Given /^I click on the first result$/ do
      pending # express the regexp above with the code you wish you had
      end

      Then /^I should land on the qastuffs blog$/ do
      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"

      My step_definitions floder name is also correct.not sure why it is showing indefined steps.please suggest.

      Delete
    3. In which directory you run the cucumber? You need to run it on the directory above the ./feature/step_definitions

      Delete
    4. Now i am getting the below error

      undefined method `page' for module `Capybara' (NameError)
      ./features/support/patches/capybara.rb:3
      D:/software/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
      D:/software/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
      D:/software/features/sudhir selenium/features/support/env.rb:7
      D:/software/Ruby187/lib/ruby/gems/1.8/gems/cucumber-1.2.1/bin/../lib/cucumber/rb_support/rb_language.rb:129:in `load'
      D:/software/Ruby187/lib/ruby/gems/1.8/gems/cucumber-1.2.1/bin/../lib/cucumber/rb_support/rb_language.rb:129:in `load_code_file'
      D:/software/Ruby187/lib/ruby/gems/1.8/gems/cucumber-1.2.1/bin/../lib/cucumber/runtime/support_code.rb:171:in `load_file'
      D:/software/Ruby187/lib/ruby/gems/1.8/gems/cucumber-1.2.1/bin/../lib/cucumber/runtime/support_code.rb:83:in `load_files!'
      D:/software/Ruby187/lib/ruby/gems/1.8/gems/cucumber-1.2.1/bin/../lib/cucumber/runtime/support_code.rb:82:in `each'
      D:/software/Ruby187/lib/ruby/gems/1.8/gems/cucumber-1.2.1/bin/../lib/cucumber/runtime/support_code.rb:82:in `load_files!'
      D:/software/Ruby187/lib/ruby/gems/1.8/gems/cucumber-1.2.1/bin/../lib/cucumber/runtime.rb:175:in `load_step_definitions'
      D:/software/Ruby187/lib/ruby/gems/1.8/gems/cucumber-1.2.1/bin/../lib/cucumber/runtime.rb:40:in `run!'
      D:/software/Ruby187/lib/ruby/gems/1.8/gems/cucumber-1.2.1/bin/../lib/cucumber/cli/main.rb:43:in `execute!'
      D:/software/Ruby187/lib/ruby/gems/1.8/gems/cucumber-1.2.1/bin/../lib/cucumber/cli/main.rb:20:in `execute'
      D:/software/Ruby187/lib/ruby/gems/1.8/gems/cucumber-1.2.1/bin/cucumber:14
      D:/software/Ruby187/bin/cucumber:23:in `load'
      D:/software/Ruby187/bin/cucumber:23

      Below is the gem list.

      *** LOCAL GEMS ***

      activesupport (2.3.14)
      addressable (2.3.2)
      builder (3.1.4)
      capybara (2.0.1)
      childprocess (0.3.6)
      cucumber (1.2.1)
      diff-lcs (1.1.3)
      ffi (1.2.0 x86-mingw32)
      gherkin (2.11.5 x86-mingw32)
      gizmo (0.1.1)
      json (1.7.5)
      libwebsocket (0.1.7.1)
      mime-types (1.19)
      multi_json (1.4.0)
      nokogiri (1.5.5 x86-mingw32)
      rack (1.4.1)
      rack-test (0.6.2)
      rake (0.8.7)
      rdiscount (1.6.8)
      rspec (1.2.8)
      rubyzip (0.9.9)
      selenium-webdriver (2.27.1)
      term-ansicolor (1.0.7)
      tilt (1.3.3)
      websocket (1.0.4)
      xpath (1.0.0)

      Please suggest.

      Delete
  37. i am getting"


    Scenario: A simple google search scenario # regression\search.feature:3
    Given I am on the main google search # regression\search.feature:4
    And I search for "site:qastuffs.blogspot.com" # regression\search.feature:5
    And I click on the search button # regression\search.feature:6
    And I click on the first result # regression\search.feature:7
    Then I should land on the qastuffs blog # regression\search.feature:8

    1 scenario (1 undefined)
    5 steps (5 undefined)
    0m0.022s

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

    Given /^I am on the main google search$/ do
    pending # express the regexp above with the code you wish you had
    end

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

    Given /^I click on the search button$/ do
    pending # express the regexp above with the code you wish you had
    end

    Given /^I click on the first result$/ do
    pending # express the regexp above with the code you wish you had
    end

    Then /^I should land on the qastuffs blog$/ do
    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.

    seems its not getting steps definitions.please suggest

    ReplyDelete
  38. Hi Sudhir,
    Have you resolved the Nameerror problem? if so how?

    undefined method `page' for module `Capybara' (NameError)
    ./features/support/patches/capybara.rb:3

    ReplyDelete
  39. Great Tutorial on cucumber. Will try it now

    ReplyDelete
  40. To install ruby you can use the windows installer. just search railsinstaller

    ReplyDelete
  41. Hi, first thank you for posting this. I am a manual tester but would like to up my skills and become an automated tester. I too am having trouble with:

    undefined method `page' for module `Capybara' (NameError)

    I am using RubyMine
    Copied & Pasted your code (modifying require 'features/support/patches/capybara' to require File.dirname(__FILE__) + '/patches/capybara')

    Gems install include:

    source 'https://rubygems.org'
    gem 'shotgun'
    gem 'nokogiri', '1.6.0'
    gem 'rake'
    gem 'launchy'
    gem 'gherkin'
    gem 'cucumber'
    gem 'capybara'
    gem 'rspec'
    gem 'selenium'
    gem 'selenium-webdriver'
    gem 'gizmo'
    gem 'term-ansicolor'

    Here is my env file:
    #require 'rspec/expectations'
    require 'uri'
    require 'net/http'

    #CAPYBARA
    require 'capybara/cucumber'
    require 'capybara/session'

    require File.dirname(__FILE__) + '/patches/capybara'
    Capybara.default_driver = :selenium
    Capybara.run_server = false
    Capybara.default_selector = :css
    Capybara.default_wait_time = 20

    #gizmo
    require 'gizmo'
    World(Gizmo::Helpers)

    Gizmo.configure do |config|
    config.mixin_dir = File.dirname(__FILE__) + '/../pages'
    end

    ReplyDelete
  42. After triggering, I got console output as:


    Scenario: A simple google search scenario # regression\search.feature:3
    Given I am on the main google search # regression\search.feature:4
    And I search for "site:qastuffs.blogspot.com" # regression\search.feature:5
    And I click on the search button # regression\search.feature:6
    And I click on the first result # regression\search.feature:7
    Then I should land on the qastuffs blog # regression\search.feature:8

    1 scenario (1 undefined)
    5 steps (5 undefined)
    0m0.022s

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

    Given /^I am on the main google search$/ do
    pending # express the regexp above with the code you wish you had
    end

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

    Given /^I click on the search button$/ do
    pending # express the regexp above with the code you wish you had
    end

    Given /^I click on the first result$/ do
    pending # express the regexp above with the code you wish you had
    end

    Then /^I should land on the qastuffs blog$/ do
    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.

    Please help as I want to let it work correctly.................
    Also it would be helpful if you have some answers for questions like:
    1.What type of application testing is most suited with capybara+ruby?
    2.Why Capybara?
    3.How to use capybara?
    4.how we can use capybara for web app test automation?
    5.how capybara best from selenium web driver.


    Please reply...................

    ReplyDelete
  43. on_page_with :google do |page|

    What does "on_page_with" here?

    ReplyDelete