I have a spec as follows.
it 'should login with correct user/password',
js: true, driver: :selenium do
visit new_user_session_path
fill_in 'user_email', with: user.email
fill_in 'user_password', with: user.password
click_on 'loginButton'
expect_current_path(home_path)
end
If I removed driver: :selenium
, it works. I thought it's because of RSpec Configuration for transactions. Hence, I added Database Cleaner and disabled config.use_transactional_fixtures = false
. However, it was still failing. I debugged Devise (devise-4.2.1/l ib/devise/strategies/database_authenticatable.rb) as follows.
def authenticate!
resource = password.present? && mapping.to.find_for_database_authentication(authentication_hash)
hashed = false
debugger
if validate(resource){ hashed = true; resource.valid_password?(password) }
remember_me(resource)
resource.after_database_authentication
success!(resource)
end
mapping.to.new.password = password if !hashed && Devise.paranoid
fail(:not_found_in_database) unless resource
end
After checking I can see mapping.to.find_for_database_authentication(authentication_hash)
does return the user as wanted. However, validate(resource)
failed for selenium ON. I checked more into it and found out def self.compare(klass, hashed_password, password)
is the root cause (in devise-4.2.1/l ib/devise/encryptor.rb).
So the main reason was because it couldn't compare the password. I suspect it has to do with Encryption. Can someone help?
After crazy time, I found the answer to this. The problem is with Capybara Selenium, it doesn't like number 3. Let me explain. My user.password was '12345678' and the code only fills in '1245678'
fill_in 'user_email', with: user.email
fill_in 'user_password', with: user.password
I've tried with different combinations such as '331', '123'. They all got the number 3 removed. Hence, I changed my test password to 'abcd' and it worked. Following is what I've got in my Gemfile.lock.
capybara (2.13.0)
rspec (3.6.0)
selenium-webdriver (3.4.3)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.