Tuesday 27 June 2023

RSpec and comments in HTML

I needed to get at the html comment embedded in a page (don't ask why, it was part of the task I was given)

HTML comments were in the form:

<!-- Message: this is an embedded comment -->

Using the usual RSpec 

expect(page).to have_text('Message') doesn't work, as html comments are non-visible.

A way of getting around this is to use

expect(page.native.inner_html).to include('<!-- Message: this is an embedded comment -->')

does work.


This is a note for the next time I hit the problem.