0

我有一个简单的功能:

Feature: User can see the welcome page
Scenario: User can see the worker page
    Given I am on the welcome page  
    Then I should see the Worker button
    When I click on the  Worker button
    Then I should be on the Worker page

Scenario: User can see the requester page 
    Given I am on the welcome page  
    Then I should see the Requester button 
    When I click on the Requester button 
    Then I should be on the Requester page 

奇怪的是我可以通过 Then 我应该看到 Worker 按钮但不能通过点击测试。

这是我的步骤定义

Then /^I should see the (.+) button$/ do |button_name|
  page.has_button? button_name
end

When /^I click on the (.*) button$/ do |button_name|
  #page.has_button? button_name
  click_on button_name
end

这是我的欢迎页面

  div.row
    %div.span6
      = button_to 'Worker', workers_path, :class => "btn btn-large btn-primary"
    %div.span6                   
      = button_to 'Requester', requesters_path, :class => "btn btn-large btn-primary"

是has_button吗?Cabybara 或 Cucumber 的方法?

4

2 回答 2

1

无论页面上的内容如何,​​您的 Then 步骤都将始终通过,因为has_button?返回 true 或 false,这两者都不会导致您的 Cucumber 步骤失败。为此,您的步骤必须引发异常,最好通过以下方式实现:

page.should have_button button_name
于 2012-05-01T14:05:20.007 回答
0

有按钮?是Capybara提供的一种方法。它记录在这里

而不是click_on button_name 尝试click_button button_name

于 2012-05-01T11:36:57.863 回答