Take a Screenshot when a Test Fails in Playwright Mocha

How to set up screenshotting on test failure in Playwright Mocha!

Courtney Zhan

--

Running Playwright with Mocha (the most widely used test syntax framework in JavaScript) is beneficial and has several advantages over running with Playwright Test runner. See this article for running Playwright with Mocha in a Continuous Testing server.

This article will cover setting up screenshots on test failure for viewing in a CT Server like BuildWise. The video below shows the screenshot functionality in action.

Why Screenshots

Screenshots can benefit a Continuous Testing (CT) Server when tests fail. It can show what the screen was when the test failed. This is good in a CT situation as it can provide information at a glance (e.g. assertion failed because the message is incorrect).

Note that taking screenshots when tests pass is not valuable and likely won’t be looked at, so there is no need to store and display these.

--

--