Playwright + Java · Lesson 10 of 38
Module 10: Java Modern Features for Automation
Your task
Implement getPassingTests:
Write it in the editor, then press Check answer (Ctrl + Enter).
import java.util.*;
import java.util.stream.Collectors;
List<String> rawTexts = Arrays.asList(" Product A ", " Product B", " ");
// Clean and filter empty items in one pipeline:
List<String> cleanTitles = rawTexts.stream()
.map(String::trim)
.filter(t -> !t.isEmpty())
.collect(Collectors.toList());
// Find first matching element safely with Optional:
Optional<String> match = cleanTitles.stream()
.filter(t -> t.contains("Product A"))
.findFirst();
if (match.isPresent()) {
System.out.println("Found target product: " + match.get());
}Modern Java introduces Lambdas, Streams, and Optional. These features let you filter tables, transform element text, and verify test assertions in concise, declarative lines of code. Let's master modern Java features for automation!
Part of the Playwright + Java course (Playwright with Java). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.
Streams make data transformations declarative, readable, and less error-prone when filtering UI rows or extracting column values.
Ready? Solve the task in the editor
Use Check answer to mark it complete. Hints are there if you need them.
___