Lapis Lazuli:Device Simulation

From Test Automation Wiki
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.

Setup

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

Usage

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:

devices:
  desktop720:
    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'.

Examples

# 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 = Selenium::WebDriver::Firefox::Profile.new
  profile['network.http.phishy-userpass-length'] = 255
  profile['network.http.use-cache'] = false
  browser :firefox, :profile => profile, device:'iphone'
end

# 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 'google.com' # Will navigate the chrome browser to google
browser.goto 'spritecloud.com' # Will navigate the firefox browser to spriteCloud

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.