I’m writing Cucumber features and step definitions for an app and I’d like to assert if there is some particular text on the page. As an example, I would like to find the visible text "section"
.
Currently I’m using something like:
...getSource().then(function(source){
source.should.contain(expectedText);
});
This doesn’t work when a section
element is present on the page.
Ideally I would also like to restrict the scope of this search to within a particular selector like .random-container
, although this is less important.
Capybara’s way of handling this is awesome, so anything that feels similar would be ideal:
within '.random-container' do
should have_content 'section'
end
What is the best way to assert visible text, while reducing possible collisions?
DISCLAIMER: I come from a Rails background.