We’ve been using Selenium, Webrat, Cucumber and any number of other gems together for quite a while with very few problems. Just recently our Selenium tests just stopped working on the login step, and given our application requires users to login to do anything, it meant out test suite was basically broken from step one.

Given that we thought very little of any consequence had changed it was annoying trying to troubleshoot the problem. Typically you start off thinking it’s something you did, then maybe it’s something someone you know did, then you start to branch out and think that maybe, just maybe, it was a bug elsewhere!

I initially started to check the logs and they seemed perfect, but it wasn’t finding the user record in the database. So I loaded the database in sqlite and lo-and-behold there were no user records to be found. I started a debug session and it reported that the user had in fact been created. I thought it had to be something to do with transactions being used. Trying to insert a record into the database and being told the database was locked confirmed this.

I turned out that the Cucumber gem writer determined that there should be no more global setting for turning on or off transaction support when running tests. Previously transactions were turned off by default in Cucumber, and you’d generally turn them back on if you needed them. This change is annoying because a good chunk of our suite uses Selnium for testing and it requires transactions to be turned off. It’s also a bit odd to reverse a default option and have no way to enable it at all.

Apparently the work around is to tag all the features and scenarios that rely on non-transactional database operations with this new tag of @no-txn. After implementing this, we’ve found it does work and so our tests are back to usual condition.

So if you’re running into problems with your Selenium tests using Cucumber with Rails and your database isn’t updating within a test then check out the ‘@no-txn’ tag and see what happens after you use that.