37. Centralized Test Configuration & Device Emulation

Centralized Configuration in Java

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);
}
}

Task

  • Implement configureDesktopViewport:
  • 1. Accept int width and int height.
  • 2. Return new Browser.NewContextOptions().setViewportSize(width, height).
πŸ’‘Common doubts
Did you like the problem?
Lesson 37 of 38
Java
Loading code editor…
Next