Test iOS vs Android
Different devices have different capabilities, viewport sizes, and behaviors. Emulation allows testing mobile experiences without physical devices, though real device testing is still important for final validation.
Detected device information
User Agent
Click to select
Selected device info
Select a device preset to see details
Platform comparison
-webkit- prefixes commonposition: fixed quirks with keyboardAutomation hints
import { devices } from '@playwright/test';
// Use built-in device descriptors
const iPhone = devices['iPhone 14'];
const pixel = devices['Pixel 7'];
test('iPhone emulation', async ({ browser }) => {
const context = await browser.newContext({
...iPhone,
});
const page = await context.newPage();
// Verify emulation is active
const isMobile = await page.evaluate(() =>
/iPhone|iPad|iPod/.test(navigator.userAgent)
);
expect(isMobile).toBe(true);
});
// Custom device configuration
const customDevice = {
viewport: { width: 390, height: 844 },
userAgent: 'Custom UA string',
deviceScaleFactor: 3,
isMobile: true,
hasTouch: true,
};
// Test touch capability
await page.evaluate(() => navigator.maxTouchPoints);
// Emulate geolocation
await context.setGeolocation({
latitude: 51.5074,
longitude: -0.1278
});
// Emulate timezone
await context.setTimezone('Europe/London');
// Set permissions
await context.grantPermissions(['geolocation']);// iOS capabilities
DesiredCapabilities ios = new DesiredCapabilities();
ios.setCapability("platformName", "iOS");
ios.setCapability("platformVersion", "16.0");
ios.setCapability("deviceName", "iPhone 14");
ios.setCapability("automationName", "XCUITest");
ios.setCapability("browserName", "Safari");
// Android capabilities
DesiredCapabilities android = new DesiredCapabilities();
android.setCapability("platformName", "Android");
android.setCapability("platformVersion", "13");
android.setCapability("deviceName", "Pixel 7");
android.setCapability("automationName", "UiAutomator2");
android.setCapability("browserName", "Chrome");
// Check device info
String platformName = driver.getCapabilities()
.getCapability("platformName").toString();
// Get device metrics
Map<String, Object> metrics = (Map<String, Object>)
driver.executeScript("mobile: deviceInfo");
// Simulate network conditions
driver.setNetworkConnection(
new NetworkConnectionSetting(
false, // airplane mode
true, // wifi
true // data
)
);
// iOS specific
((IOSDriver) driver).shake();
((IOSDriver) driver).lockDevice();
// Android specific
((AndroidDriver) driver).pressKey(
new KeyEvent(AndroidKey.BACK)
);