Domanda

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?

È stato utile?

Soluzione

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')

Altri suggerimenti

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')
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top