chadb768
chadb768

Reputation: 473

What does this line of Cucumber and Capybara code do?

I'm brand new to Cucumber and Capybara and I'm having trouble understanding what this one line of code in my homework does. "rating" is a movie rating (G, PG-13, etc.) that is searched for in a table of movies in this context:

assert page.has_xpath?('//td', :text => "#{rating}")

Could someone explain what every part of this line does?

Upvotes: 0

Views: 99

Answers (2)

kross
kross

Reputation: 3752

If any element named td has the contents of the given rating, it succeeds.

Upvotes: 0

mechanicalfish
mechanicalfish

Reputation: 12826

It checks whether the page contains an element matching the XPath //td, that has a text node "#{rating}". If it doesn't, it fails the test.

The XPath //td matches every td element regardless of its location in the document (because of the double slash).

Here are links to the documentation:

assert

has_xpath?

Upvotes: 3

Related Questions