Rails offers a robust testing environment making it extremely easy to test all aspects of an application.
With system test cases, one can test workflows by simulating user interactions.
Here’s a simple example,
This example simulates a user,
creates a new rocket
and then navigates back to the rockets index page.
Now in case a test fails, it’s useful to have a screenshot or HTML dump of the page.
This fastens the process of debugging.
Before
Rails provides options to take screenshots of the page at any point during the test.
Simply call the take_screenshot method multiple times.
In order to also include HTML dumps, use the RAILS_SYSTEM_TESTING_SCREENSHOT_HTML environment variable.
Here’s an example.
First let’s add a take_screenshot method to the test.
Now we will get debug data before and after updating the form.
Let’s run the test.
The screenshots
and HTML dumps are stored in the tmp/screenshots directory.
After
However Rails will always take both images and HTML dumps every time the environment variable is used.
This quickly becomes a problem when debugging to find HTML only issues.
To mitigate this, Rails now allows the html parameter in the take_screenshot method.
We can now run the test without the environment variable.
This time only two files will be created, instead of four.
One image
and one HTML file.
This PR introduces four variations of the take_screenshot method.