Here we learn to use Protractor with Selenium WebDriver providing the functionality to take screenshots.
Update: Andrew Batz has kindly put together an NPM-installable package with the code in this article. Click here to check it out or download it using
npm install screenshot-protractor
As I work with SPAs (Single Page Applications) it becomes more obvious that some parts of a web app can only be inspected visually. As part of an end2end test or user acceptance testing, manually checking screenshots is still faster than manual testing. Screenshots at different steps of a process can be put together into a presentation or PDF and presented to clients or other stakeholders to show them that not only is the backend code working, but the frontend looks and feels right.
So here’s a snippet for taking a screenshot with Protractor, which is designed for AngularJS, and an end2end test that uses Jasmine and Protractor:
When to take screenshots during an end2end test:
- to inspect the layout/styling
- to inspect how the site looks across multiple browsers
- to verify with client/stakeholders that we’re building the right thing
- to share with other developers when debugging an issue