Class EmulateDevice
java.lang.Object
net.serenitybdd.screenplay.playwright.interactions.EmulateDevice
- All Implemented Interfaces:
net.serenitybdd.core.SkipNested,net.serenitybdd.screenplay.Performable
Emulate different devices by setting viewport size, user agent, and device characteristics.
Sample usage:
// Emulate predefined devices
actor.attemptsTo(EmulateDevice.iPhone12());
actor.attemptsTo(EmulateDevice.iPadPro());
actor.attemptsTo(EmulateDevice.pixel5());
actor.attemptsTo(EmulateDevice.galaxyS21());
// Set custom viewport
actor.attemptsTo(EmulateDevice.withViewport(1920, 1080));
// Emulate mobile with touch
actor.attemptsTo(
EmulateDevice.withViewport(375, 667)
.withDeviceScaleFactor(2)
.asMobile()
);
// Desktop viewport
actor.attemptsTo(EmulateDevice.desktop());
actor.attemptsTo(EmulateDevice.desktopHD());
actor.attemptsTo(EmulateDevice.desktop4K());
Note: For full device emulation including user agent and other properties, configure the browser context when creating the actor's ability.
-
Method Summary
Modifier and TypeMethodDescriptionasMobile()Mark as a mobile device (enables mobile-specific behaviors).static EmulateDevicedesktop()Standard desktop viewport (1280x720).static EmulateDevice4K desktop viewport (3840x2160).static EmulateDeviceHD desktop viewport (1920x1080).static EmulateDeviceEmulate Samsung Galaxy S21 viewport.static EmulateDeviceEmulate Samsung Galaxy Tab S7 viewport.Get the device scale factor (if set).intGet the viewport height.intgetWidth()Get the viewport width.static EmulateDeviceiPad()Emulate iPad viewport.static EmulateDeviceiPadPro()Emulate iPad Pro 11" viewport.static EmulateDeviceiPhone12()Emulate iPhone 12 / 12 Pro viewport.static EmulateDeviceEmulate iPhone 14 Pro viewport.static EmulateDeviceiPhoneSE()Emulate iPhone SE viewport.isMobile()Check if this is configured as a mobile device.static EmulateDevicelaptop()Laptop viewport (1366x768).static EmulateDeviceMacBook Pro 14" viewport (1512x982).<T extends net.serenitybdd.screenplay.Actor>
voidperformAs(T actor) static EmulateDevicepixel5()Emulate Google Pixel 5 viewport.static EmulateDevicepixel7()Emulate Google Pixel 7 viewport.withDeviceScaleFactor(double factor) Set the device scale factor (pixel density).Enable touch events.static EmulateDevicewithViewport(int width, int height) Set a custom viewport size.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.serenitybdd.screenplay.Performable
then
-
Method Details
-
withViewport
Set a custom viewport size.- Parameters:
width- Viewport width in pixelsheight- Viewport height in pixels
-
iPhone12
Emulate iPhone 12 / 12 Pro viewport. -
iPhone14Pro
Emulate iPhone 14 Pro viewport. -
iPhoneSE
Emulate iPhone SE viewport. -
iPad
Emulate iPad viewport. -
iPadPro
Emulate iPad Pro 11" viewport. -
pixel5
Emulate Google Pixel 5 viewport. -
pixel7
Emulate Google Pixel 7 viewport. -
galaxyS21
Emulate Samsung Galaxy S21 viewport. -
galaxyTabS7
Emulate Samsung Galaxy Tab S7 viewport. -
desktop
Standard desktop viewport (1280x720). -
desktopHD
HD desktop viewport (1920x1080). -
desktop4K
4K desktop viewport (3840x2160). -
laptop
Laptop viewport (1366x768). -
macBookPro14
MacBook Pro 14" viewport (1512x982). -
withDeviceScaleFactor
Set the device scale factor (pixel density).- Parameters:
factor- The device pixel ratio (e.g., 2 for Retina displays)
-
asMobile
Mark as a mobile device (enables mobile-specific behaviors). -
withTouch
Enable touch events. -
performAs
public <T extends net.serenitybdd.screenplay.Actor> void performAs(T actor) - Specified by:
performAsin interfacenet.serenitybdd.screenplay.Performable
-
getWidth
public int getWidth()Get the viewport width. -
getHeight
public int getHeight()Get the viewport height. -
getDeviceScaleFactor
Get the device scale factor (if set). -
isMobile
Check if this is configured as a mobile device.
-