Tuesday 2 August 2016

Launch Selenium Browser in Emulation Mode or Mobile Mode


Responsive Design Websites are the hot website design in recent days which fits to all device resolutions. Testing the responsiveness of the website on multiple resolutions is very important.

In the absence of real devices or if the application is in development mode, one can launch the selenium browser in mobile/emulation mode by setting the desired capabilities.

Below code snippet would help in launching the browser in emulation mode.
NOTE: This option is very good alternative for Emulators while testing web-app responsiveness.




//build the emulation options
Map<String, String> mEmu = new HashMap<String, String>();
mEmu.put("deviceName", "Nexus 5X");
//mEmu.put("deviceName", "iPhone 6");
Map<String, Object> options = new HashMap<String, Object>();
options.put("mobileEmulation", mEmu);

//Add the options to DesiredCapabilities
DesiredCapabilities caps = DesiredCapabilities.chrome();
caps.setCapability(ChromeOptions.CAPABILITY, options);

//Call the webdriver constructor which takes capabilities.
WebDriver driver = new ChromeDriver(caps);
driver.get("anyurl");

Reference:
https://sites.google.com/a/chromium.org/chromedriver/mobile-emulation



No comments:

Post a Comment