Difference between revisions of "Lapis Lazuli:Device Simulation"
(Added remote browser examples for desktop and mobile) |
m (typo fix) |
||
Line 90: | Line 90: | ||
# Starting remote mobile browser (via selenium-grid and appium) | # Starting remote mobile browser (via selenium-grid and appium) | ||
browser :chrome, { | browser :chrome, { | ||
− | device: 'disabled', #make sure to have a device config with no values (in devices.yml) in this case | + | 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', | url: 'http://<selenium-grid-hub>:4444/wd/hub', | ||
platformName: "Android", | platformName: "Android", |
Latest revision as of 14:16, 4 May 2018
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.
Contents
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
version1.1.0
or above. - Copy
devices.yml
from here. - Add
default_device
to./config/config.yml
. (example)- Make sure the selected
default_device
exists indevices.yml
- Make sure the selected
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 # 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
- Coded device (E.G.
browser :firefox, device: 'desktop1080'
) - Cucumber variable (E.G.
bundle exec cucumber DEVICE=galaxys6
) default_device
variable inconfig.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.