Back To Normal

Subscribe To Our E-Mail Newsletter

Friday, June 20, 2014

How to setup capybara with cucumber in 5 mins?


Couch ModePrint It


  •  create test directory  (mkdir  test)
  •  \curl -L https://get.rvm.io | bash -s stable —ruby 
  •  gem install cucumber
  •  gem install capybara
  •  mkdir features\support
  •  mkdir features\step_definitions

Capybara settings 

Create env.rb file under support folder with following content

require 'capybara/cucumber'
Capybara.default_driver = :selenium


Cucumber scenarios

 Create test.feature file under features folder 

Feature: Find the automationhints blog

  Scenario: Search for the blog
    Given I am on the Google homepage
    Then I will search for "automationhints.blogspot"
    Then I should see "Vijay Ragavan"


Step definitions for cucumber steps

Create my_steps.rb file under step_definitions directory.

Given(/^I am on the Google homepage$/) do
  visit 'http://www.google.co.in'
end

Then(/^I will search for "([^"]*)"$/) do |arg|
 fill_in 'gbqfq', :with => arg + "\n"

end

Then(/^I should see "([^"]*)"$/) do |text|
  page.should have_content(text)
end



RUN


Navigate to test folder in console and type command as "cucumber". it will run all scenarios which is part of feature files.





Click Here For Smileys :D
:D
:)
:[
;)
:D
:O
(6)
(A)
:'(
:|
:o)
8)
(K)
(M)

No comments:

560 Free Online Courses

Top 200 universities launched 500 free online courses.  Please find the list here .