Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Selenium Mobile Emulation in landscape

Tags:

c#

selenium

I'm doing some mobile UI testing using Selenium in a .Net environment using c#.

I'm able to do testing quite successfully using the chrome mobile emulation in portrait mode, but I can not found how to put the emulation in Landscape mode.

I would like to be able to programmatically rotate during testing but through research it appears this is not possible yet.

Working in Portrait mode.

        ChromeOptions chromeCapabilities = new ChromeOptions();         

        chromeCapabilities.EnableMobileEmulation("Apple iPhone 6");

        ChromeDriverService service = ChromeDriverService.CreateDefaultService(@"C:\chromedriver");            

        IWebDriver driver = new ChromeDriver(service, chromeCapabilities);
        driver.Navigate().GoToUrl("www.google.com");

However how do I put the iPhone emulation in to a landscape orientation?

I have tried this but it does't work and the browser opens without the size limitations

        ChromeMobileEmulationDeviceSettings CMEDS = new ChromeMobileEmulationDeviceSettings();
        CMEDS.Width = 66;
        CMEDS.Height = 37;
        CMEDS.PixelRatio = 1.0;
        CMEDS.UserAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25";

        ChromeOptions chromeCapabilities = new ChromeOptions();

        chromeCapabilities.EnableMobileEmulation(CMEDS);

        ChromeDriverService service = ChromeDriverService.CreateDefaultService(@"C:\chromedriver");

        IWebDriver driver = new ChromeDriver(service, chromeCapabilities);
        driver.Navigate().GoToUrl("www.google.com");

Any help or advice greatly received!! Thanks in advance

like image 581
Tom Martin Avatar asked Nov 09 '22 17:11

Tom Martin


1 Answers

From what I understand, it is not possible to change the screen orientation at the moment.

Here is a related open issue:

  • Support setting screen orientation on mobile device

There are some and few hints in the source code that got me thinking that it might be possible to have a "landscape" oriented emulated device by adding a custom brand new device (how to add a device programmatically is an open question though).

like image 78
alecxe Avatar answered Nov 14 '22 23:11

alecxe