Selenium Chrome Mobile Emulator testing with specific phone resoultion

1,633 views
Skip to first unread message

Chandra Sekhar Kakarla

unread,
May 3, 2016, 1:34:20 AM5/3/16
to Selenium Users

I am writing selenium script for testing different mobile views,
I used below code to run the script for "Apple iPhone 5" for the instance.

static DesiredCapabilities  capabilities;
     static String deviceName;
     public static void main(String[] args) {
      //some Sample Devices. Complete list can be found here: https://code.google.com/p/chromium/codesearch#chromium/src/chrome/test/chromedriver/chrome/mobile_device_list.cc
      //pick any of the device

    //  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";

      System.setProperty("webdriver.chrome.driver", "C:\\path\\to\\driver\\chromedriver.exe");

      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");

     }


When I run this I am getting error like unknown error: unrecognized chrome option: mobileEmulation

Please help me to get proper reference to write selenium script for mobile emulation(mobile height and width should be changed based on device),
and let me know the issue with the existing code.

⇜Krishnan Mahadevan⇝

unread,
May 3, 2016, 2:32:55 AM5/3/16
to Selenium Users
I quickly gave this a shot and I can't recreate the problem. Looks like you may be on an older version of chromedriver which doesn't know how to handle this capability. Please try again using Chromedriver v.2.21

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/1d02bcf4-78c6-4d81-b034-59d38f77e341%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

anemuday

unread,
May 3, 2016, 4:26:08 AM5/3/16
to Selenium Users
As Krishnan said, i tried your code and it works perfect.

In fact i worked with older version of ChromeDriver(2.16) and latest Chrome browser(49.0)

So just better check latest of these both and give a try.

Thanks,
Uday
Reply all
Reply to author
Forward
0 new messages