Martijn Kerckhaert
Martijn Kerckhaert

Reputation: 494

testing with selenium not able to log in

It's the first test im writing that requires :js => true so I installed selenium.

I am always able to login with some credentials I create before but unable to log in when I run them through selenium.

A sanity check to see if I'm still creating my user (recruiter)

puts "RECRUITER NAME => #{Recruiter.first.email}"

returns

RECRUITER NAME => [email protected]

I always set my password to "testtesttest"

But it always fails to login. Is it using a different (empty?) database? Am I missing some settings that are required?

Note => Logging in with the exact same file works flawless if I remove :js => true. But somehow it breaks on this step.

Upvotes: 0

Views: 78

Answers (1)

Thomas Walpole
Thomas Walpole

Reputation: 49910

When performing js tests the app being tested runs in a different thread than the test, which means they no longer share the same database connection - see https://github.com/jnicklas/capybara#transactions-and-database-setup. There are ways to force the two threads to share the connection, but it ends up being flaky on some edge cases and limiting what database access you can do at specific times in your test, and really isn't something a beginner wants to deal with. The better/easiest solution is to disable transactional testing and use truncation or deletion to manage the database state. The easiest way to do that is to use database_cleaner and setup a config that will swap to the needed strategy for each test - https://github.com/DatabaseCleaner/database_cleaner#rspec-with-capybara-example

Upvotes: 1

Related Questions