Skip to content

Instantly share code, notes, and snippets.

@sahajamit
Created February 15, 2016 07:49
Show Gist options
  • Save sahajamit/cca0ca97b76240bcaa81 to your computer and use it in GitHub Desktop.
Save sahajamit/cca0ca97b76240bcaa81 to your computer and use it in GitHub Desktop.
import java.util.HashMap;
import java.util.Map;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
public class MobileEmulation {
static DesiredCapabilities capabilities;
static String DeviceName;
public static void main(String[] args) {
//some Sample Devices. Complete list can be found here: https://code.google.com/p/chromium/codesearch#chromium/src/chrome/test/chromedriver/chrome/mobile_device_list.cc
//pick any of the device
// 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");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment