Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start Chrome emulation from command line

I use Google Chrome with Intern to run automated tests and I would like to know if there is a way to launch Chrome in emulation mode from CLI or using a specific flag to test mobile rendering. If not, do you know a good workaround ?

I could directly use the Android Emulator (from Android SDK) with Selenium Webdriver apk or with mobile Chrome but tests are crashing most of the time, emulators don't respond and I have to restart it. Also, I need to test on the largest possible scope, not limited to Android devices. Chrome on desktop is a lot more stable and even if a test fails, chrome always respond and can be closed automatically by Intern.

I tried a workaround with the "--enable-touch-events" flag and with a custom userAgent but it's producing weird behaviors. Maybe some other flags would help me ?

Thank you in advance for your answer.

like image 304
Fenrir31 Avatar asked Apr 09 '14 09:04

Fenrir31


People also ask

How do I open Chrome from command line?

Open Chrome Using Command Prompt You can also do the same thing from the “Run” window. Open Run by typing “Run” in the Windows 10 search bar and selecting the “Run” application. Here, type Chrome and then select the “OK” button. The web browser will now open.

How do I enable emulation?

To start the Android Emulator and run an app in your project: In Android Studio, create an Android Virtual Device (AVD) that the emulator can use to install and run your app. In the toolbar, select the AVD that you want to run your app on from the target device drop-down menu. Click Run .


2 Answers

This is currently not possible in Chrome.

It's a feature I've been wanting myself too so I've gone ahead and filed a feature request for it at the following link:

https://code.google.com/p/chromium/issues/detail?id=373169&thanks=373169&ts=1400050662

I'm crossing my fingers but it wouldn't hurt if you and other people interested in this went and left a comment on the thread too. The more people asking for it, the higher the chance of it being implemented. And it does seem like it would be trivial to implement since it currently only takes a couple of mouse clicks to enter emulation mode.

like image 146
Scottmas Avatar answered Sep 19 '22 08:09

Scottmas


Selenium allows users to emulate Chrome on a mobile device using code like this:

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

ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption("mobileEmulation", mobileEmulation);
WebDriver driver = new ChromeDriver(chromeOptions);
like image 32
Matthew K Avatar answered Sep 21 '22 08:09

Matthew K