2013-08-27 118 views
0

我正在使用黃瓜/水豚寫一些功能水平測試。黃瓜步定義

這裏是我的特徵定義

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 

如何定義的步驟,以檢查它是否去一個特定的頁面?基本上我怎麼定義下面的步驟?

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

另外,是否有Cucumber/Capybara步驟定義的文檔?

回答

1

有幾種可能性:

  1. 檢查網頁的路徑/使用current_pathcurrent_url方法網址:

    Then(/^I should go to the dashboard page$/) do 
        current_path.should == expected_path 
        # or current_path.should == expected_url 
    end 
    
  2. 頁的檢查內容使用的一個RSpec matchers

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

你也可以使用頁面對象模式,並做類似:

current_path.should == DashboardPage.path