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?

有帮助吗?

解决方案

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

其他提示

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')
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top