While doing integration testing with RSpec, I found that I can test image posting with the code below.
expect(page).to have_selector("img[src$='test_image.png']")
(I'm testing an image posted with the name test_image.png
.)
However, I didn't understand the meaning of `` $ incorporated, so I'll record what I looked up.
You can specify a selector that includes a specific wording by writing as follows.
Prefix match ・ ・ ・ E [foo ^ = "bar"] </ b> E element whose foo attribute value starts with bar
End match ・ ・ ・ E [foo $ = "bar"] </ b> E element whose foo attribute value ends with bar
Partial match ・ ・ ・ E [foo * = "bar"] </ b> E element with bar in the value of the foo attribute
If you decompose the code written at the beginning based on this, it means that you are testing whether there is a ʻimg element
whose value of the src attribute ends with test_image.png
. ..
http://www.htmq.com/selector/attrvaluee.shtml
Recommended Posts