简体   繁体   English

黄瓜步骤定义

[英]Cucumber step definition

I am using Cucumber/Capybara to write some feature level tests. 我正在使用Cucumber / Capybara编写一些功能级别的测试。

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? 还有关于黄瓜/水豚步定义的文档吗?

There are several possibilities: 有几种可能性:

  1. Check page's path/url using current_path or current_url methods: 使用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. Check contents of the page using one of RSpec matchers 使用RSpec匹配器之一检查页面内容

     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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM