0

我正在使用 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 步骤定义的文档吗?

4

1 回答 1

1

有几种可能性:

  1. current_path使用orcurrent_url方法检查页面的路径/url :

    Then(/^I should go to the dashboard page$/) do
      current_path.should == expected_path
      # or current_path.should == expected_url
    end
    
  2. 使用RSpec 匹配器之一检查页面内容

    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
于 2013-08-27T21:37:16.013 回答