Frage

Here's what I'm performing in my tests:

find('#instructors').find('.caption').find('h2').should have_content(full_name)

Is there a way to refactor it to just one find instead of three?

War es hilfreich?

Lösung

When you chain find methods, you are saying to find node A and within that find node B and within that find node C. As you are using CSS-selectors for each find, this is equivalent to using the CSS-selectors to search for descendants. Descendant searches are performed by simply adding a space between selectors.

The three find methods can be combined into a single find as:

find('#instructors .caption h2').should have_content('full_name')

Andere Tipps

As you are looking for something rather than interacting with it, you can use a matcher e.g.

 has_css('#instructors .caption h2', text: 'full_name')
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top