Selenium script to run on mobile mode of chrome Desktop

First step, you can launch mobile mode with chrome developer tool :

mobile_mode


public static void main(String[] args) {

// DeviceName = "Google Nexus 5";
// DeviceName = "Samsung Galaxy S4";
// DeviceName = "Samsung Galaxy Note 3";
// DeviceName = "Samsung Galaxy Note II";
// DeviceName = "Apple iPhone 4";
DeviceName = "Apple iPhone 5";
// DeviceName = "Apple iPad 3 / 4";
// String ChromeDriverPath = System.getProperty("user.dir") + "/lib/chromedriver.exe";
// System.setProperty("webdriver.chrome.driver", ChromeDriverPath);

Map<String, String> mobileEmulation = new HashMap<String, String>();
mobileEmulation.put("deviceName", DeviceName);

Map<String, Object> chromeOptions = new HashMap<String, Object>();
chromeOptions.put("mobileEmulation", mobileEmulation);

capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
WebDriver driver = new ChromeDriver(capabilities);
driver.manage().window().maximize();
driver.navigate().to("http://www.google.com");

}

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.