Medium Brush Stroke

Capture screenshots and videos in java playwright

Medium Brush Stroke

Introduction

Playwright is an automation tool with built-in features for capturing screenshots and recording videos in Java. The article will discuss the various types of screenshots and provide steps for including them.

Medium Brush Stroke

Playwright

Playwright enables reliable end-to-end testing for modern web apps

Medium Brush Stroke

Screenshot

Playwright supports various types of screenshots including Page Screenshot, Full Scrollable Page Screenshot, Element Screenshot, Attaching Screenshot to Cucumber Report, and Web Element Screenshot.

Medium Brush Stroke

Full Page Screenshot

To capture a full-page screenshot for a comprehensive test, the "setFullPage" feature can be enabled with the code provided in this method. This code takes a snapshot of the entire page regardless of its length.

Medium Brush Stroke

Element Screenshot

With Playwright, you can take a screenshot of a specific element by passing its locator path as a parameter in the ".screenshot()" method, as shown in the code.

Medium Brush Stroke

Hooks Implementation

Hooks are one of the key where you can manage where you want to take screenshot.

Medium Brush Stroke

Video Recording

Playwright allows testers to record a video of their test execution, which can help to better understand the test results. Later, the article will demonstrate how to integrate this video into the test report.

Medium Brush Stroke

Cucmber Report

Cucumber utilizes reporter plugins to generate reports that provide details about the scenarios being tested. Moreover, both screenshots and videos can be added to the Cucumber report.

Medium Brush Stroke

View Screenshot and Video

You can attached screenshot and video in the report itself. You can have look in the blog link below.

Medium Brush Stroke

Conclusion

Playwright, an automation tool, enables taking multiple screenshots when required, as well as recording screenshots and videos in Java, which helps to identify the root cause of failures without having to review the report.