【问题标题】:Cucumber step definition黄瓜步骤定义
【发布时间】:2013-08-28 05:37:16
【问题描述】:

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

【问题讨论】:

    标签: ruby-on-rails cucumber capybara bdd


    【解决方案1】:

    有几种可能:

    1. 使用current_pathcurrent_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 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-10
      • 2020-07-12
      • 1970-01-01
      • 1970-01-01
      • 2022-01-15
      • 1970-01-01
      相关资源
      最近更新 更多