问题
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.
回答1:
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.
回答2:
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);
来源:https://stackoverflow.com/questions/22958721/start-chrome-emulation-from-command-line