Simulate mobile device with selenium

1 comment, 636 points
simulate mobile device with selenium
simulate mobile device with selenium

Simulate mobile device with selenium

Now that mobile technologies becomes so popular most of the traffic that businesses receives comes from mobile. Your team might not have a setup to run the tests using appium in house or using some third part service provider. There is a solution that you can rely on , to simulate mobile device with selenium using chrome browser.

I know there might be voices saying that you might miss important bugs , I would say not really because:

User Agent Recognition

One important concept in the mobile world is the so called User Agent of a device. The detection of a mobile device can be done on the client-side (browser) and/or the server-side, and these approaches have certain major differences.


When you want to see how a site would look on a certain mobile phone model without using the actual device, your best bet for accurate results is to mimic the User Agent string (UA) of the device. What happens when you download a web page is your browser sends its UA to the server.

args = []
args << "–window-size=320,480"
args << "–user-agent='Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3'", :browser => :chrome, :args => args)

So basically you can run your tests using docker in parallel using this browser capabilities and emulate a mobile device.

  • It’s an emulator, so you don’t need any real phones for testing.
  • Customizable User Agents – Users can freely change the UA string.
  • Super simple to instantiate and easy to use. No need to install any complex SDKs or the like.
  • no special infrastructure required to run the tests , can use the desktop one
  • Media support may not be perfect.
  • By default, only User Agent Strings for the platforms Chrome runs on are included. However, it’s possible to add iPhone User Agent to Chrome Mobile Emulator as a custom UA string.
  • The emulator displays how pages look using the mobile browser — as known, not all features work similarly in different browsers. Even more so in the mobile world.

Happy Testing!

Like it? Share with your friends!

1 comment, 636 points
Test engineer

One Comment

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.