As I mentioned yesterday, we are getting close to the official release of TestCafe v15.1. Among the new features we'll introduce in this release is the ability to automatically capture screenshots during test execution so you can track down defects more effectively and get a dynamic look at the state of your web app or failure conditions of any test.
Capturing Screenshots on Demand
You can command TestCafe to capture screenshots by using its special Screenshot action. This action can be used anywhere within a test and as many times as needed. There are two ways to add the Screenshot action to a test. The first is to record it with TestCafe's Visual Test Recorder by clicking the "Add Screenshot" button within the recorder’s toolbar...
...The second way to capture a screenshot during a test is to add the act.screenshot API method to your test code using the code editor.
Once you command TestCafe to capture a screenshot - via the Visual Test Recorder or by using its API - it will automatically capture and post the image to your test report within the Results tab. To view the screenshots TestCafe captures, simply click the "Screenshot" icon in the Screenshot column of the report.
TestCafe displays the captured image collection in a new window. As you can see below, screenshots are grouped by test steps.
Capturing Screenshots on Failure
TestCafe also allows you to capture screenshots when a test fails. These captured images help you quickly isolate the cause of failures within any test. To enable this functionality, check the "Take a screenshot if a test fails" option when starting a test.
If an error occurs or an assertion fails during the test run, TestCafe will snap an image of the tested application and post it to your test report.
To view the captured image:
- Switch to the Results tab and click the task report. TestCafe will display detailed results;
- Click the failed test to view an extended message about the failure.
As you can see in the image above, the test failed because the assertion did not pass: the actual text for the article header did not match the expected value. The auto-captured screenshot makes it infinitely easier to understand the cause and effect of test failures. In order to view the screenshot in full screen mode, simply click it - TestCafe will display it in a new browser tab.
Hopefully I've been able to show you the value of this new feature - automated screenshots truly make test analysis easier. We'd love to hear your feedback - let us know what you think about TestCafe's automated screenshot capture option.