I have been trying to use Capybara to match actual image file name with expected file name.
I have images that are stored in app/assets/images
, e.g. image01.png
.
The file name of these images are stored in the image_file_name
field of one or more tables.
They are being rendered using <%= @object.image_file_name %>
in one of more html.erb
file. However, the actual file name rendered has a series of alphanumeric characters at the right hand side, e.g. assets/image01-d4f7d162a9ecb8877e69bc96a8ca03bd7531c8faf7be7c65ba60c14e7c6fe530.png'
.
I've tried the following expectations and they work:
expect(page).to have_css("img[src*='image01-d4f7d162a9ecb8877e69bc96a8ca03bd7531c8faf7be7c65ba60c14e7c6fe530.png']")
expect(page).to have_css("img[src*='image01']")
May I know is there a way to validate that the image file name starts with image01
and ends with .png
regardless of what are in between? If that couldn't be achieved with hav_css
, how about have_selector
or have_xpath
?