Selenium Java : Mobile mode trên chrome

Nơi thông tin về các vấn đề liên quan đến khóa học Automation Test.
Forum rules
Nơi thông tin về các vấn đề liên quan đến khóa học Automation Test.
Post Reply
cuhavp
Jr. Tester
Posts: 61
Joined: Mon 21 Jan, 2013 3:52 pm
Contact:

Selenium Java : Mobile mode trên chrome

Post by cuhavp »

Image

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");
 
}



Post Reply

Return to “Đào tạo Automation Tester”