Launching chrome in mobile emulation in Selenium in node

Chrome driver allows you to test your web application on emulated mobile devices(Android and iOS). Below example illustrates how to launch chrome in Mobile Emulation using Selenium in Node.js
 
var assert = require(‘assert’);
var webdriver = require(‘selenium-webdriver’),
By = webdriver.By,
until = webdriver.until;

var chrome = require(“selenium-webdriver/chrome”);

//Below code snippet shows how to launch chrome with mobile emulation mode.
var driver = new webdriver.Builder()
.forBrowser(‘chrome’)
.setChromeOptions(new chrome.Options()
.setMobileEmulation({deviceName: ‘Apple iPhone 5’})
//.setMobileEmulation({deviceName: ‘Google Nexus 5’})
//.setMobileEmulation({deviceName: ‘Google Nexus 7’})
.addArguments(“start-maximized”)
.addArguments(“test-type”)
)
.build();

//Rest of the operations will be done in emulation mode
driver.get(‘https://www.softpost.org/selenium-test-page/’);

driver.quit();

Complex problems, Simple Solutions