6

I love the new emulation feature introduced in the new Chrome. In fact so much that I like to use it to test a mobile website for multiple resolutions/devices. To do so I would require some sort of control over the emulation feature.

Is there any way to control wish device is emulated?

It would be nice to know how to start OpenQA.Selenium.Chrome.ChromeDriver emulating a mobile device.

Thanks in advance.

vtortola
  • 34,709
  • 29
  • 161
  • 263
scheffield
  • 6,618
  • 2
  • 30
  • 31

2 Answers2

0

You can try adding options to the Chrome driver.

ChromeOptions options = new ChromeOptions();
options.addArguments("--user-agent=Mozilla/5.0 (iPad; CPU OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3");

In the above example, "user-agent" switch has been provided. Similarly please try using "window-size" command line switch.

Please let me know if it works.

List of all command line switches of chrome are provided below.

http://peter.sh/experiments/chromium-command-line-switches/

NOTE: By installing the Chrome plugin given below, you can get the required user-agent settings for various devices.

https://chrome.google.com/webstore/detail/user-agent-switcher-for-c/djflhoibgkdhkhhcedjiklpkjnoahfmg

Purus
  • 5,701
  • 9
  • 50
  • 89
0

Here's how I did it in C#:

IWebDriver driver;
        string setDevice = "Apple iPhone 6";
        var mobileEmulation = new Dictionary<string, string> { { "deviceName", setDevice } };
        var chromeOptions = new ChromeOptions();
        chromeOptions.AddAdditionalCapability( "mobileEmulation", mobileEmulation );
        driver = new ChromeDriver( chromeOptions );
        driver.Manage().Timeouts().SetPageLoadTimeout( TimeSpan.FromSeconds( 90 ) );
        driver.Manage().Timeouts().ImplicitlyWait( TimeSpan.FromSeconds( Convert.ToDouble( 30 ) ) );
        return driver;