0
votes

I am using Cucumber/Capybara to write some feature level tests.

Here is my feature definition

Feature: User Signin
  As a User
  I want to signin
  So i can use my app

  Background:
      Given user with "email" email and "password" password

  Scenario: Signing in with correct credentials
      When I go to sign in page
      And I fill in "user_email" with "email"
      And I fill in "user_password" with "password"
      And I click "Sign in" button
      Then I should go to the dashboard page

How do i define the step to check if it went to a specific page? Basically how do i define the following step?

Then(/^I should go to the dashboard page$/) do
end

Also is there a documentation for Cucumber/Capybara step definitions?

1

1 Answers

1
votes

There are several possibilities:

  1. Check page's path/url using current_path or current_url methods:

    Then(/^I should go to the dashboard page$/) do
      current_path.should == expected_path
      # or current_path.should == expected_url
    end
    
  2. Check contents of the page using one of RSpec matchers

    Then(/^I should go to the dashboard page$/) do
      page.should have_css('#id_that_is_present_only_at_dashboard_page')
    end
    

Also you may use page object pattern and do something like:

current_path.should == DashboardPage.path