Chắc rất nhiều bạn sử dụng mode này của chrome để test các website có hỗ trợ mobile mà team ko có đủ device để test.
Và Chrome cũng hỗ trợ để mình dùng selenium chạy với mode này bằng code. Đoạn code dưới đây là một ví dụ:
Code: Select all
public static void main(String[] args) {
// DeviceName = "Google Nexus 5";
// DeviceName = "Samsung Galaxy S4";
// DeviceName = "Samsung Galaxy Note 3";
// DeviceName = "Samsung Galaxy Note II";
// DeviceName = "Apple iPhone 4";
DeviceName = "Apple iPhone 5";
// DeviceName = "Apple iPad 3 / 4";
// String ChromeDriverPath = System.getProperty("user.dir") + "/lib/chromedriver.exe";
// System.setProperty("webdriver.chrome.driver", ChromeDriverPath);
Map<String, String> mobileEmulation = new HashMap<String, String>();
mobileEmulation.put("deviceName", DeviceName);
Map<String, Object> chromeOptions = new HashMap<String, Object>();
chromeOptions.put("mobileEmulation", mobileEmulation);
capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
WebDriver driver = new ChromeDriver(capabilities);
driver.manage().window().maximize();
driver.navigate().to("http://www.google.com");
}