I implemented the evaluation function using Raty, but I will leave it as an article because it took time to execute the integration test. If you know it, there is nothing wrong with it, but I hope it helps beginners.
I want to make the action of clicking the star mark of each item, so I will look at the elements using the verification tool.
rspec.rb
find("img").click
rspec.rb
find('#taste_star').find("img[alt='5']").click
Finally, I was able to clear the test with this code ◎ Let's look at each one.
I was personally blind because I usually specified a unique id for each element and could only pick up the element in one shot, but find can be used repeatedly. First, by picking up the id = "taste_star" specified in the parent element, you can narrow down the applicable range of the img tag that follows it.
Since there are still multiple img tags in the same parent element, use the alt attribute that is sorted individually. If you want to specify the attribute, you can enclose it in square brackets.
click Then click on the image and you're done!
By the way, you can use click_on to click a link or button, but in the case of an image, specify the alt attribute. In this case, the value of the alt attribute is not unique, so you will get an error.
While summarizing the article, I regret that I stumbled in a simple place again.
Introduction of jquery.raty rails Add star function using "Raty" in Rails Introduction to RSpec that can be used, Part 4 "Any browser operation is free! Reverse lookup Capybara dictionary"
Recommended Posts