Lapis Lazuli:Device Simulation

From Test Automation Wiki
Revision as of 13:16, 4 May 2018 by Mark0203 (talk | contribs) (typo fix)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

You can use device simulation in Lapis Lazuli. This will set a specific user-agent and browser size that you have attached to a configuration file.


A new project

  • Make sure you have at least lapis_lazuli 1.1.0
  • Use lapis_lazuli create <projectname> to create a project folder. (see Creating your first ta project)
  • All done! See ./config/devices.yml and start adding your own devices.

An existing project

  • You will need at least lapis_lazuli version 1.1.0 or above.
  • Copy devices.yml from here.
  • Add default_device to ./config/config.yml. (example)
    • Make sure the selected default_device exists in devices.yml


From console

You can add the line DEVICE=iphone to your cucumber command.

bundle exec cucumber -t @yourtag -p chrome DEVICE=iphone
# or
bundle exec cucumber -p production DEVICE=iphone

Ofcorse, you could also create a new profile for devices in cucumber.yml:

iphone: DEVICE=iphone

And run:

bundle exec cucumber -t @yourtag -p chrome -p iphone

Default device

The config.yml now has a new value: default_device. The value of this variable will automatically be loaded from devices.yml unless you've set a different device from console or code.

Best practise here is to have a dekstop device setup in devices.yml as following:

    width: 1280
    height: 720

Note that there is no user-agent set. This way the browser default user-agent will be used. And then add the following to config.yml

default_device: desktop720

From your ruby code

You can restart the browser from your code to run a certain step in specific settings. It's also possible to open a secondary browser with specific device settings. All you need to add is device: 'iphone'.


# Simply restarting the browser using firefox with desktop720 settings
browser.restart :firefox, device: 'desktop720'

# With specific browser settings
if !ENV['BROWSER'] || ENV['BROWSER'] == 'firefox'
  ENV['BROWSER'] = 'firefox'
  # Get Selenium to create a profile object
  profile =
  profile['network.http.phishy-userpass-length'] = 255
  profile['network.http.use-cache'] = false
  browser :firefox, :profile => profile, device:'iphone'

# Adding no device:... will load either the default_device (if this is the first time opening the browser) OR the device that was set when first running the browser.
browser.restart :chrome

# Starting 2 browsers
browser :firefox, device: 'iphone'
secondary = browser.create :chrome
secondary.goto '' # Will navigate the chrome browser to google
browser.goto '' # Will navigate the firefox browser to spriteCloud

# Starting remote desktop browser (via selenium-grid)
browser :firefox, {
  device: 'iphone',
  url: 'http://<selenium-grid-hub>:4444/wd/hub',
  platform: "WINDOWS"

# Starting remote mobile browser (via selenium-grid and appium)
browser :chrome, {
  device: 'disabled', #make sure to have a device config with no values (in devices.yml) in this case called 'disabled'
  url: 'http://<selenium-grid-hub>:4444/wd/hub',
  platformName: "Android",
  browserName: "chrome",

Defined device priority

  1. Coded device (E.G. browser :firefox, device: 'desktop1080')
  2. Cucumber variable (E.G. bundle exec cucumber DEVICE=galaxys6)
  3. default_device variable in config.yml (E.G. default_device:iphone5)

So the config value is overwritten by de cucumber value and the cucumber value is overwritten by the coded value.