DEV Community

n350071๐Ÿ‡ฏ๐Ÿ‡ต
n350071๐Ÿ‡ฏ๐Ÿ‡ต

Posted on

Narrow down scope with `within` in Capybara Rails testing

๐Ÿ”— Parent Note

๐Ÿค” By using find method

expect(find('div.greet > h1').text).to eq 'Hello'
expect(find('div.greet > p.message').text).to eq "world"

๐Ÿ‘ By using within method

within('div.greet') do
  expect(find('h1').text).to eq 'Hello'
  expect(find('p.message').text).to eq "world"
end

๐Ÿ“š Method: Capybara::Session#within โ€” Documentation for jnicklas/capybara (master)

Top comments (0)