Playwright + Java · Lesson 37 of 38
Module 37: Playwright Configuration
Your task
Implement configureDesktopViewport:
Write it in the editor, then press Check answer (Ctrl + Enter).
public class PlaywrightConfig {
public static Browser.NewContextOptions getStandardContextOptions() {
return new Browser.NewContextOptions()
.setBaseURL("https://staging.targetqa.com")
.setViewportSize(1920, 1080)
.setLocale("en-US")
.setTimezoneId("America/New_York");
}
public static Browser.NewContextOptions getMobileDeviceOptions(Playwright playwright) {
// Device emulation (e.g. iPhone 14):
return new Browser.NewContextOptions()
.setViewportSize(390, 844)
.setUserAgent("Mozilla/5.0 (iPhone; CPU iPhone OS 16_0 like Mac OS X)...")
.setIsMobile(true)
.setHasTouch(true);
}
}A professional framework maintains configuration in a centralized location. In this lesson, you will configure viewports, mobile device emulation, global timeouts, and environment URLs for staging and production. Let's master Playwright configuration!
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.
Yes! Playwright allows full mobile device emulation including screen size, user-agent, touch events, and device pixel ratio.
Ready? Solve the task in the editor
Use Check answer to mark it complete. Hints are there if you need them.
___