We use Selenium WebDriver Show archive.org snapshot integrated with Cucumber/Capybara for full-stack integration testing.
Try and use it
Your forked MovieDB should already include a feature that uses a real browser. Add the @javascript
tag to your other features to test it yourself.
When you run your cucumber feature now with NO_HEADLESS=1 geordi cucumber
, you should see a browser opening. Get someone to help you if this does not work.
Some of your features might now fail. You might find solutions below:
Making peace with Selenium
Selenium is a powerful tool that you can use to test almost all user interfaces. However it has a lot of quirks you have to deal with. Luckily for you, someone else has already solved all major issues that the Capybara/Selenium combo brings with it.
Understand the following issues and solutions in depth:
- Difference between Capybara drivers
- Fixing flaky integration tests (also watch the video on YouTube Show archive.org snapshot )
- What does the
@javascript
tag do and how does it work? - We used to use Selenium with Firefox, but now we run Selenium tests with Chrome instead, which doesn't have the same incompatibility issues as Firefox
- Therefore we use Chrome in headless mode running Chrome in headless mode
-
Use capybara lockstep to ensure requests don't bleed between steps
Show archive.org snapshot
- Read through the README of the capybara-lockstep Show archive.org snapshot gem. What problem does it solve and how does it work?
- Threads and processes in a Capybara/Selenium session
- Why do we need the
database_cleaner
gem for integration tests? - Why your Cucumber feature loses cookies when run under Selenium
- Capybara cannot interact with the browser while a blocking dialog is open
- Taking screenshots in Capybara
- Capybara/Selenium: evaluate_script might freeze your browser, use execute_script
- How to: Start Selenium browser maximized or with custom window size
- Mock the browser time or time zone in Selenium features
Exercise: A walk through the forest
Work through the code of all Spreewald steps Show archive.org snapshot . Do you understand the implementation of each step?
Exercise: Recognize common culprits
Have a look at this code:
class User < ApplicationRecord
def self.find_by_email(email)
@cached_users ||= {}
@cached_users[email] ||= User.find_by_email!(email)
end
end
Could it cause your tests to become flaky?