0

I'm trying to do functional-testing in rails with cucumber and capybara, to test bootstrap-star-rating, but i don't know how do that. I'd like to describe this step 'When I select 1 star to rate'

In view

<%= form_tag("/medics/rating", method: "post") do %> 
                    <input id="input-2a" class="rating" name="grade" data-min="0" data-max="5" data-step="1" data-stars=5 
                        data-glyphicon="false">
                     <%= hidden_field_tag :medic_id, @medic.id %>
                    <%= submit_tag 'Avaliar' , class: 'btn btn-lg btn-success' %>
                <%end%>
            </div>
        </div>
    </div>

So, how i write this test?

When(/^I select 1 star to rate$/) do

end

1 Answers1

0

I know this is an old question, but I recently had the same problem and found the solution here. In short, use a JavaScript driver such as poltergeist/selenium (I'm using Selenium) and provide the value to the input using page.evaluate_script.

I'm not using Cucumber, however, here's what worked for me with minitest and capybara/minitest/rails:

script = "document.getElementById('review_rating').value = '3'"

click_link 'add a review'
fill_in 'review[take_away]', with: 'Review takeaway'
fill_in 'review[body]', with: 'Review body'
page.evaluate_script(script)

click_button 'Review!'

Since this is 100% Capybara syntax, the fact that I'm using minitest and you're using Cucumber shouldn't make any difference.

Community
  • 1
  • 1
wendybeth
  • 424
  • 4
  • 17