-
-
Notifications
You must be signed in to change notification settings - Fork 67
Writing System Tests
System tests are tests that mimic normal user behavior as close as possible. They load the full page in a browser, and then click buttons and fill in information on the page to check whether the system really works.
Use rails test:system
to execute the system tests. By default they will run in firefox in so-called headless mode. In headless mode, you don't get to actually see what happens.
If you want to use a different browser or want to actually see the tests in action, you can set the DRIVER
environment variable to specify the browser:
DRIVER=firefox rails test:system
DRIVER=chrome rails test:system
DRIVER=headless_chrome rails test:system
System tests can be defined just like any other test. There is a good official manual available for how to write these: https://guides.rubyonrails.org/testing.html#system-testing
There are some very important helpers available through a gem (library) called capybara. Its documentation can be found at: https://rubydoc.info/github/teamcapybara/capybara/master#the-dsl
If you only want to know about the available assertions, see: https://rubydoc.info/github/teamcapybara/capybara/master/Capybara/Minitest/Assertions
Finally, we define a few helpers of our own for some actions. Their definitions can be found in test/application_system_test_case.rb
. For example, log_in
, log_out
and confirm_email
. Note that all of these may change the page you are looking at, since they need to visit different pages to perform their action.