TA Basics: Device simulation with lapis_lazuli

Lapis_lazuli provides a way to simulate a mobile device. But when you want to test on real or virtual desktop and especially mobile devices instead of using this simulation option, here is what you need to keep in mind.

Dimensions

In the devices.yml file (briefly mentioned in the previous blog post), you store all browser width and height dimensions you want to test on. It will look something like this:
  • From the command line you could start a specific run with the command "cucumber DEVICE=desktop720"
  • From IRB or env.rb you could start a browser session with "browser :firefox, device: 'desktop900'"
  • Or you just add a default in the config.yml file "default_device: desktop1024", so you can run the cucumber command or the irb session without the need to enter a specific dimension
This even works on remote browsers via selenium grid (just add the device: 'desktop1080' to the capabilities).

Problem

But there is one issue with this setup related to mobile test automation that by default is not covert and will result into an error like this:
  "Selenium::WebDriver::Error::UnknownError: unknown error: operation is unsupported on Android"
And if you look to the rest of the error you might notice this line as well:
  "from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/watir-6.10.3/lib/watir/window.rb:68:in `resize_to'"
All this just indicates that resizing of the browser is not allowed on the Android devices. And that makes sense since there is no browser window you can make smaller or bigger like on a desktop. But now is the question, how can we run our tests without getting this error when using a project generated with the lapis_lazuli gem?

Solution

The solution is to add a new device to the devices.yml devices list with no values. So you get something like this:
When you have this configuration in place you can use it in the way you preffer/need:
  • Change the default in the config.yml file "default_device: disabled"
  • OR from the command line you can run "cucumber DEVICE=disabled ..."
  • OR in IRB or env.rb you can add it to the capabilities "device: 'disabled'"
  • What also works is "ENV['DEVICE'] = 'disabled'" before starting the browser session in IRB/env.rb but I prefer to add it as a capability

Desktop and Mobile example

Previously I set the default in config.yml, but if you run your test suite against desktop and mobile the default is kind of useless since you need one value for desktop and no value for mobile. So what I did, is I set a default for desktop (since most of my test machines are desktop machines). And for all mobile machines, I've added a capability in env.rb just like mentioned on the testautomation.info device simulation page. So the devices.yml configuration is cool to have if you want to make use of device simulation, but it's a bit in the way when you're testing on real/emulated mobile Android devices (I think iOS just ignored it anyway, but now I'm not sure anymore so that is something to test for yourself).

Comments

Popular posts from this blog

PowerShell - How to overcome Azure VM's fixed resolution limitation

TA Basics: Website Test Automation on mobile devices via Appium server

TA: How to get the Session Storage data from your browser