thoughtbot / capybara-webkit

A Capybara driver for headless WebKit to test JavaScript web apps
https://thoughtbot.com/open-source
MIT License
1.97k stars 427 forks source link

Incorrect input data using Capybara-webkit #935

Closed Xosmond closed 8 years ago

Xosmond commented 8 years ago

Im using devise for authentication and when i login with no javascript, everything works well, but when i add capybara-webkit as javascript engine, i get an error saying that the login information is incorrect.

When i did "save_and_open_screenshot" i saw that the fields were filled before click on login button. code

describe "process", :type => :feature do
  let(:valid_attributes) { attributes_for(:user, rol: 'Administrador') }

  before :each do
    User.create(valid_attributes)
    visit '/users/sign_in'
    within(".form-inputs") do
      fill_in 'user[login]', :with => valid_attributes[:email]
      fill_in 'user[password]', :with => valid_attributes[:password]
    end
    click_button 'Ingresar'
  end

  it 'go to page', :js => true do
    click_link 'personal'
  end
end

What could be the problem here?

PD: When i do this:

    puts valid_attributes[:email]
    puts find_field('user[login]').value
    puts valid_attributes[:password]
    puts find_field('user[password]').value

Im getting these:

alf_smitham@yahoo.com
alf_smitham@yahoo.com
misteriolopmg32
misteriolopmg32

So the fill action is working correctly. PD2: getting same problem with Poltergeist now.

twalpole commented 8 years ago

Usually this means you're still using transactional testing so the records created in your test aren't visible to the app - see https://github.com/jnicklas/capybara#transactions-and-database-setup

jferris commented 8 years ago

I'd also recommend using FactoryGirl.create or calling User.create! so that you see a failure message when a record fails to save.

This doesn't look like a bug in capybara-webkit, so I'm going to close this issue. However, feel free to continue commenting and asking for help.

Xosmond commented 8 years ago

Alright, twaddle was correct, i had to use database_cleaner to use truncation.