黄瓜步骤定义

时间:2013-08-27 20:38:40

标签: ruby-on-rails cucumber capybara bdd

我正在使用Cucumber / Capybara编写一些功能级别的测试。

这是我的功能定义

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 个答案:

答案 0 :(得分: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
    
  3. 您也可以使用页面对象模式并执行以下操作:

    current_path.should == DashboardPage.path