Hinweis: Diese Inhalte wurden mit Unterstützung von Künstlicher Intelligenz erstellt und redaktionell überprüft (Transparenzhinweis gemäß Art. 50 EU AI Act).
Praxis-Guide: Playwright Multi-Device & Geolocation Emulation¶
Emulation mobiler Geräte (iPhone, Pixel), Touch-Gesten, Geolocation (GPS-Koordinaten), Zeitzonen und Sprachen in Playwright für globale Web-Tests.
🐍 1. Python Skript (device_emulation.py)¶
import asyncio
from playwright.async_api import async_playwright
async def run_mobile_geo_test():
async with async_playwright() as p:
# 1. Gerät-Profil wählen (z. B. iPhone 13 Pro)
iphone = p.devices['iPhone 13 Pro']
# 2. Browser-Kontext mit Emulation starten (Standort: Tokio, Japan)
browser = await p.chromium.launch(headless=False)
context = await browser.new_context(
**iphone,
geolocation={"latitude": 35.6762, "longitude": 139.6503},
permissions=["geolocation"],
locale="ja-JP",
timezone_id="Asia/Tokyo"
)
page = await context.new_page()
await page.goto("https://maps.google.com")
await page.screenshot(path="tokyo_mobile.png")
await browser.close()
if __name__ == "__main__":
asyncio.run(run_mobile_geo_test())
🔗 Verwandte Themen¶
- Playwright Trace Viewer – Test-Debugging
- Playwright Visual Regression – UI-Vergleich
- Playwright Network Interception – Network Mocking
Hinweis: Diese Inhalte wurden mit Unterstützung von Künstlicher Intelligenz erstellt und redaktionell überprüft (Transparenzhinweis gemäß Art. 50 EU AI Act).