Mobile Emulation with ChromeDriver

We can use ChromeDriver to run automated Selenium tests against a whole stack of different devices with Chrome Dev Tools Mobile Emulation option.

Devices currently supported at the time of writing:

  • Amazon Kindle Fire HDX
  • Apple iPad
  • Apple iPad Mini
  • Apple iPhone 4, 5, 6 & 6+
  • Blackberry Playbook
  • Blackberry Z30
  • Google Nexus 4, 5, 6, 7 & 10
  • LG Optimus L70
  • Laptop with HiDPL Screen
  • Laptop with MDPI Screen
  • Laptop with touch
  • Nokia Lumia 520
  • Nokia N9
  • Samsung Galaxy Note 3
  • Samsung Galaxy Note II
  • Samsung Galaxy Note S III
  • Samsung Galaxy S4
Discovering the options available

ChromeDriver Mobile Emulation

Now it’s just a case of passing┬áthe device string to ChromeOptions’ EnableMobileEmulation option when instantiating the driver, like so:

public static void SetupIPadDriver()
{
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.EnableMobileEmulation("Apple iPad");
Driver = new ChromeDriver(chromeOptions);
}

Kick your test off and see it running in chrome but to the specification you supplied in the ChromeDriver option. There are of course subtle differences between emulators and real devices, weigh up the pros and cons for yourself and have a look at the official documentation.



  • And you’d think it would be a breeze to specify whether you wanted it in Portrait or Landscape mode wouldn’t you? After all there is an orientation button in DevTools that allows you to change it easily and obviously your Selenium tests will need to test both Portrait and Landscape but alas and bafflingly NO!

    There is no option to specify the device and the orientation you’d like, you are stuck with Portrait.

    The only other option is to go with the ChromeMobileEmulationDeviceSettings object alternative where you have to manually set width, height, pixel density, user agent…. making the first easy method useless. It’s frustrating because you’ll go down the chromeOptions.EnableMobileEmulation(“Apple iPad”); road thinking ‘gosh this is nice and easy’ then you’ll hit the ‘hey I’m stuck in Portrait mode’ brick wall and you’ll have to start all over again.

    • Given it runs from Chrome, I would imagine it would but it is not something I have tried, if you decide to give it a whirl then do let us know how you get on.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.