Monday, February 16, 2015

Make Capybara and Selenium open a google page.

Here simple step by step to make bare minimum Capybara and Selenium to open a google page


1. Make a dirctory
      mkdir capy_open_google

2. Get into the directory and create following sub directories
       cd capy_open_google
   mkdir features
   mkdir features/support
   mkdir features/step_definitions

3. Create 'Gemfile' with following content (Check Note 1)
source "http://rubygems.org"
gem "cucumber"
gem "capybara"
gem "selenium-webdriver"
gem "rspec"

4. Create 'features/support/env.rb' file with following content

require 'capybara'
require 'capybara/dsl'
require 'capybara/cucumber'
require 'capybara/rspec'
require 'selenium/webdriver'
Capybara.default_driver = :selenium
Capybara.app = "Cuke alone"
Capybara.run_server = false

5. Create 'features/step_definitions/web_steps.rb' file with following content
     Given /^(?:|I am )on the "([^"]*)" page$/ do |url|
       visit(url)
     end

6. Create 'features/search.feature' file with following content

Feature: Sample demo
Scenario: Open google
  Given I am on the "www.google.com" page

7. In shell, execute 'bundle install'

8. then, 'bundle exec cucumber features/search.feature'

Note 1: 
 At the time of the blog post, Firefox 35.0.1 throws some driver error. It is suggested to use FF25 in Ubuntu 14.04. More info in https://code.google.com/p/selenium/issues/detail?id=6988

Note 2:
 This post is created in response to https://groups.google.com/forum/#!topic/ruby-capybara/-yZYB8i7aPs

I would suggest to check: 






No comments:

Post a Comment