mercredi 6 mai 2015

Capybara and Cucumber cannot find checkboxes even with unique ID

I have been encountering a problem when running cucumber to test the functionality of some of my checkboxes. The checkboxes are located on the edit profile page for users and allow users to check off their interests. However, every time I run cucumber it says that it is unable to find the checkbox. But this does not happen for all of the checkboxes on the page, only the checkboxes for the interests. Originally we thought that it was because the checkboxes did not have unique IDs, but now we have updated the checkboxes to have unique ids and they still cannot be found by capybara and cucumber.

The view code looks like this:

<% @interests.each do |interest| %>
  <div class="form-group">
    <%= label_tag 'interests', interest.name, class: 'col-sm-2 control-label'  %>
    <div class="col-sm-6">
      <%= check_box_tag 'interests[]', interest.id, resource.interest_ids.include?(interest.id), {class: 'form-control', id: "interest_#{interest.id}"} %>
    </div>
  </div>
<% end %>

The step definition is:

When /^(?:|I )check "([^"]*)"$/ do |field|
  check(field)
end

The feature look like this:

Feature: Edit Profile as a User

  As a BoardBank User
  So I can keep my info up to date
  I want to be able to edit my profile

Background:
    Given  I login as a User
    And I am on the home page

Scenario: Edit profile
    When I follow "Profile"
    And I follow "Edit Profile"
    And I fill in "user_firstname" with "User"
    And I fill in "user_lastname" with "Joe"
    And I fill in "user_address" with "123 userville"
    And I fill in "user_city" with "Userton"
    And I select "Alabama" from "user_state"
    And I fill in "user_zipcode" with "90210"
    And I fill in "user_phonenumber" with "555-555-5555"
    And I select "Bachelors" from "user_education"
    And I fill in "user_areaofstudy" with "Magic"
    And I check "interest_2"
    And I check "user_previous_experience"
    And I fill in "user_current_password" with "password"
    And I press "Update"
    Then I should see "Your account has been updated successfully."
    And I should be on the homepage

When I run cucumber this is what happens:

 And I check "interest_2"    #features/step_definitions/web_steps.rb:89
  Unable to find checkbox "interest_2" (Capybara::ElementNotFound)
  ./features/step_definitions/web_steps.rb:90:in `/^(?:|I )check "([^"]*)"$/'
  features/edit_profile.feature:23:in `And I check "interest_2"'

We think that it must be an issue with the view code and how the checkboxes are appearing on the page, but we could not find any solution to this issue when searching.




Aucun commentaire:

Enregistrer un commentaire