If you're using WebDriver with Chrome (via Chromedriver) you may want to emulate mobile viewport characteristics. Similarly, you may want to automate tests on desktop without having to use a proper Chrome on Android setup.
How do you do that?
If you're using WebDriver with Chrome (via Chromedriver) you may want to emulate mobile viewport characteristics. Similarly, you may want to automate tests on desktop without having to use a proper Chrome on Android setup.
How do you do that?
The
mobile_emulation
capability was added to ChromeDriver in 2.11Full documentation: https://sites.google.com/a/chromium.org/chromedriver/mobile-emulation
My notes below:
Creating a driver in Python with the mobile_emulation capability options:
Currently you can emulate devicepixelratio, useragent, viewport height and width.
Possible properties for the mobile_emulation dict:
deviceName
: if used, must be the only property. Matches a device preset in Chrome (e.g.'Google Nexus 5'
).deviceMetrics
: a dict that can include width (int), height (int), pixelRatio (double) as shown above.userAgent
: a string to spoof at the request header and navigator object.This is in the latest official chromedriver build (2.11).
Example in java:
The mobileEmulation option is implemented in the last ChromeDriver release (v 2.11). Using WebDriverJs you have to add it as property to the capabilities object.