Test mobile and responsive web pages on your desktop.
Note that Mobile Emulation is subject to this known issue.
Chrome allows users to emulate Chrome on a mobile device (e.g. a “Nexus 7” tablet, or an “iPhone 5”) from the desktop version of Chrome, by enabling the Mobile Emulation feature in Chrome DevTools. This feature speeds up web development, allows developers to quickly test how a website will render in a mobile device, without requiring a real device. ChromeDriver can also enable Mobile Emulation, via the “mobileEmulation” capability, specified with a dictionary value.
Just as in the DevTools Emulation panel, there are two ways in ChromeDriver to enable Mobile Emulation: by specifying a known device, or by specifying individual device attributes. The format of the “mobileEmulation” dictionary depends on which method is desired.
To enable Mobile Emulation with a specific device name, the “mobileEmulation” dictionary must contain a “deviceName.” Use a valid device name from the DevTools Emulation panel as the value for “deviceName.”
Java
Map<String, String> mobileEmulation = new HashMap<>();
mobileEmulation.put('deviceName', 'Nexus 5');
![Google Google](/uploads/1/2/5/8/125866829/101294226.png)
ChromeOptions chromeOptions = new ChromeOptions();chromeOptions.setExperimentalOption('mobileEmulation', mobileEmulation);
WebDriver driver = new ChromeDriver(chromeOptions);
Ruby
mobile_emulation = { 'deviceName' => 'Nexus 5' }
caps = Selenium::WebDriver::Remote::Capabilities.chrome(
'chromeOptions' => { 'mobileEmulation' => mobile_emulation })
driver = Selenium::WebDriver.for :remote, url: 'http://localhost:4444/wd/hub', desired_capabilities: caps
Python
from selenium import webdriver
mobile_emulation = { 'deviceName': 'Nexus 5' }
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option('mobileEmulation', mobile_emulation)
driver = webdriver.Remote(
command_executor='http://127.0.0.1:4444/wd/hub',
desired_capabilities
= chrome_options.
to_capabilities()
)
Note: ChromeDriver’s list of known devices is generated from those found in the DevTools Emulation panel. However, it is possible to use a version of ChromeDriver against a version of Chrome that has a newer or older list of devices. If you try to use a device name that ChromeDriver doesn’t recognize, you will see an error: “<your device name> must be a valid device.” To emulate a device that ChromeDriver doesn’t know of, enable Mobile Emulation using individual device metrics, as described below.
It is also possible to enable Mobile Emulation by specifying individual attributes. To enable Mobile Emulation this way, the “mobileEmulation” dictionary can contain a “deviceMetrics” dictionary and a “userAgent” string. The following device metrics must be specified in the “deviceMetrics” dictionary:
- “width” - the width in pixels of the device’s screen
- “height” - the height in pixels of the device’s screen
- “pixelRatio” - the device’s pixel ratio
- 'touch' - whether to emulate touch events (defaults to true, usually does not need to be set)
The phones and tablets that are available under the Mobile Emulation panel can be found in the DevTools source code.
Java
Map<String, Object> deviceMetrics = new
Hash
Map<>();
deviceMetrics.put('width', 360);
deviceMetrics.put('height', 640);
deviceMetrics.put('pixelRatio', 3.0);
Map<String, Object> mobileEmulation = new
Hash
Map<>();
mobileEmulation.put('deviceMetrics', deviceMetrics);
mobileEmulation.put('userAgent', 'Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19');
ChromeOptions chromeOptions = new ChromeOptions();chromeOptions.setExperimentalOption('mobileEmulation', mobileEmulation);WebDriver driver = new ChromeDriver(chromeOptions);
Ruby
mobile_emulation = {
'deviceMetrics' => { 'width' => 360, 'height' => 640, 'pixelRatio' => 3.0 },
'userAgent' => 'Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19'
}
caps = Selenium::WebDriver::Remote::Capabilities.chrome('chromeOptions' => mobile_emulation)
driver = Selenium::WebDriver.for :remote, url: 'http://localhost:4444/wd/hub', desired_capabilities: caps
Python
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
mobile_emulation = {
'deviceMetrics': { 'width': 360, 'height': 640, 'pixelRatio': 3.0 },
'userAgent': 'Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19' }
chrome_options = Options()
chrome_options.add_experimental_option('mobileEmulation', mobile_emulation)
driver = webdriver.Chrome(chrome_options = chrome_options)
- entirely different GPU, which may lead to big performance changes;
- mobile UI is not emulated (in particular, the hiding url bar affects page height);
- disambiguation popup (where you select one of a few touch targets) is not supported;
- many hardware APIs (for example, orientationchange event) are unavailable.
If you'd like to develop and test your app on a Chrome OS device, such as aPixelbook, but you don't have the hardware, you can use a virtual Chrome OSdevice on the Android Emulator.
Note: Chrome OS virtual devices on the Android Emulator are available as apreview while we test and gather feedback. Please keep in mind that previewfeatures are not stable, and you may experience slow performance and otherissues with this preview version. If you encounter a problem, let us know byfiling an issue.Setup
To run your app on a virtual Chrome OS device, you only need to download acouple of add-ons and take a few setup steps:
1. Install Android Studio
See Download Android Studio for instructions.
2. Enable VM acceleration for the Android Emulator
The Android Emulator can use extensions to accelerate the running of a VM(virtual machine). To enable VM acceleration, follow the instructions inConfiguring VM acceleration.
3. Install Chrome OS SDK add-ons
To run a virtual Chrome OS device on the emulator, you need to download theappropriate system image through the Android StudioSDK Manager.
- In Android Studio, select Tools > SDK Manager.
- Click the SDK Update Sites tab.
- Click Add at the bottom of the window.
- Enter the following name and URL, then click OK:Chrome OS Repository: https://storage.googleapis.com/chrome_os_emulator/addon2-1.xml
- Click Add again.
- Enter the following name and URL, then click OK:Chrome OS System Images: https://storage.googleapis.com/chrome_os_emulator/sys-img2-1.xml
- Click Apply.
- Click the SDK Tools tab and select the checkbox for Chrome OS device.
- Click OK to install the Chrome OS device.
- Restart Android Studio.
4. Create an AVD using the AVD Manager
![Google Chrome Emulator Google Chrome Emulator](https://windows-cdn.softpedia.com/screenshots/Ripple-Emulator-for-Chrome_1.png)
Now that you have the system image for the Chrome OS device installed in AndroidStudio, you can use it to create a Chrome OS virtual device that can run on theemulator.
See Create and manage virtual devices forinstructions to create an AVD.
The Pixelbook (beta) hardware profile is in the Tablet category.
If you do not already have the required SDK Platform component installed forthe AVD, you can download it from the Recommended tab of the Select asystem image page of the Virtual device configuration window.
Run the virtual device on the emulator
You can now run your virtual Chrome OS device on the emulator.
For instructions on running an app, seeRun an app in the Android Emulator.
When launching an AVD for the first time, you will need to set up the virtualdevice with a valid Google account and accept the Google Play Terms of Service.This is only required the first time a newly created Chrome OS virtual device islaunched. The ability to run Android apps is disabled when the virtualChromebook is used as a guest. To run your Android app on the emulator, you mustsign in with a valid Google account.
Known issues
- If you are using a Google account managed by your organization, your account might not be configured with a policy that allows Android apps to run on your Chromebook. For example, default G Suite accounts are not configured to run Android apps. If you are having trouble with a managed account, try with a personal account.
- Android Studio displays warnings for Chrome OS images.
- The virtual Chrome OS device does not include the Google Play Store. However, Google Play services do function on the virtual device.
- Running
adb root
closes the connection to the AVD until you sign out and sign back in. A workaround is to usesu
instead. - The default RAM size for an AVD is 1536 MB. We recommend increasing the RAM for the AVD to 2048 MB. To increase the RAM for the AVD, click Show Advanced Settings in the Virtual Device Configuration window.
- The emulator's rotation controls do not cause the virtual device to switch between landscape and portrait modes.
- The mouse pointer behaves like a finger on a touchscreen. Hovering does not work.
- Using the mouse scroll wheel can cause unwanted clicks to be sent to the device. A workaround is to swipe by holding the mouse button down while moving the mouse.
- When you close the emulator window or stop the emulator from AVD Manager before Android has finished booting, Chrome OS detects a hard shutdown. On the next boot, Chrome OS will show the crash restore dialog. To avoid this, hold the Power button in the emulator controls to shut down the virtual Chromebook.
- The ChromeVox screen reader does not work on this preview version of a virtual Chrome OS device on the Android Emulator. We intend to address this issue in a future update.