1

Rails system tests use Capybara. Capybara uses rack_test driver by default, while System tests uses selenium by default.

Capybara Drivers:

I want to know why these were chosen and what are sensible choices for a Rails programmer writing System tests.

notapatch
  • 6,569
  • 6
  • 41
  • 45
  • Selenium is browser automation software and is used to test applications by driving an actual browser (headless or not). rack_test just simulates a browser by crawling HTML with a parser. `rack_test` thus cannot test be used to test JavaScript or any real browser behavior. And of course `rack_test` is faster. Its only doing 1/100th of the job that an actual browser does. – max Apr 13 '20 at 15:14
  • And yes there are edge cases where an actual browser and rack test will differ even when you're not testing javascript so your conclusions are kind of nonsensical. Use rack_test if the trade-off is worth it but don't delude yourself that they are in any way equatable. – max Apr 13 '20 at 15:20
  • I think the title was wrong. It gave the impression that it was a run off between the two. When it was really "can I _still_ use rack_test in system tests" The original conclusion gave a lukewarm "If your system test isn't using Javascript you may consider using rack_test instead. " - which I would hope didn't lead people to the conclusion the drivers were the same - however, I have now emphasized that they are different. I hope that addresses your issues? – notapatch Apr 20 '20 at 12:42

1 Answers1

0

System tests run using Capybara. Capybara use drivers to complete the testing. Capybara drivers can be defined as:

The driver is the part of Capybara that actually manages a web page as a series of DOM elements - Rails 5 Test Prescriptions - Noel Rappin.

Capybara uses by default a rack_test driver, a faster but JavaScript unaware version. while Rails system tests uses by default, a slower but Javascript aware version, selenium - think this code sets the Rails default.

I wanted to know the reasons for the default and if I could still be using rack_test. I found a quote from the original PR:

I chose the Selenium driver as default because the purpose of adding system testing to Rails is for the initial setup to be absolutely zero. Capybara does that through their default, Rack Test, but it's not really a useful demonstration of the merits of system testing since it doesn't support JavaScript testing. Comment in PR from Eileen codes

So there's no technical reason to choose Selenium vs Rack. Selenium was chosen as it was a fuller functioned low configuration default.

Rack test is limited it was described as:

If you don't want a full browser - if you just want to assert on HTML instead of just executing Javascript ... What rack test does is basically fakes out communication between a real browser with a fake one which Capybara can use to parse the response without making a web request at all. You can make assertions about what the page contains.

Rails conf 2018 - Sam Phippen

If your system test isn't using Javascript you may consider using rack_test instead. However, it's a trade off - rack will be faster because it doesn't know about Javascript but it can't replace the complexity of a physical browser.

notapatch
  • 6,569
  • 6
  • 41
  • 45