I want to create some front-end automation for our web application. My plan is to use RSpec as the framework and Selenium to drive the browser. I see a lot of information (blog posts) around using Capybara with RSpec + Selenium. Are there advantages to using Capybara that I don't get by using RSpec + Selenium alone?
I think the Capybara benefits sum it up nicely:
- No setup necessary for Rails and Rack application. Works out of the box.
- Intuitive API which mimics the language an actual user would use.
- Switch the backend your tests run against from fast headless mode to an actual browser with no changes to your tests.
- Powerful synchronization features mean you never have to manually wait for asynchronous processes to complete.
Most of these Selenium frameworks try to achieve the same things. Easier and more readable syntax, easier configuration and auto-waiting.
If you write their DSL you could also switch to other frameworks then Selenium, but capybara does not offer that yet, but it could be an advantage in the future. If a new testing method comes along let the Capybara team implement it with the same DSL. You might not even have to change your tests to use the new tech.
The downsides are that these frameworks add a layer of magic. Where if something goes wrong it is harder to debug what is going on, but they "promise" to let you develop faster. So balance the trade off.