Fail fast and move on
I like Capybara because of its idea to test web applications by simulating how a real user would interact with the app, and capybara syntax is pretty straight forward to understand but when you have a big project using the default customisation that capybara provides will not allow you to ‘fail fast and move on’.
You might say from where this whole idea of fail fast , it’s pretty simple to me , I don’t want to wait in order to fail , I just want to fail and move on.
Given the following code :
When you reach the assertion and having the default timeout of 30 seconds , Capybara will wait 30 seconds to fail in case a actual results are not the same with expected results.
Honestly to me it doesn’t make sense to wait that much for something that is not on the page, so I was thinking that we can have a helper method :
Create a capybara helper
This gives use some flexibility because is returning a boolean value and using test unit assertions we can have something like this :
Assert using test unit assertions
You can create helpers like the above one for presence of elements , for a locator having text and so on .
You might say but why I should add that much extra work just for this ?
Well it’s simple, Imagine you have couple or thousand of tests that are running in the continuos integration , when you developers are pushing a dodgy branch and you have hundreds of failures each failure will take the time from Capybara default timeout so that means hundreds of minutes lost. This is completely against any CI principle , when you need to deliver your feedback as fast as possible.
A while ago I wrote an article about selenium performance tips , you can consider trying any of those in your project to see if is working out.