How to check that a form field is prefilled correctly using capybara

capybaraformsrspec

I have a field with a proper label that I can fill in with capybara without a problem:

fill_in 'Your name', with: 'John'

I'd like to check the value it has before filling it in and can't figure it out.

If I add after the fill_in the following line:

find_field('Your name').should have_content('John')

That test fails, although the filling just before worked as I've verified by saving the page.

What am I missing?

Best Answer

Another pretty solution would be:

page.should have_field('Your name', with: 'John')

or

expect(page).to have_field('Your name', with: 'John')

respectively.

Also see the reference.

Note: for disabled inputs, you'll need to add the option disabled: true.

Related Topic