如何在Chrome for Mobile网站中运行Selenium WebDriver测试用例



如何使用谷歌浏览器移动网站运行我的硒"网络驱动程序",没有任何线索来运行我的脚本,

我有火狐的用户代理,并在火狐移动网站中轻松运行我的测试用例

FirefoxProfile ffProfile = new FirefoxProfile();
ffProfile.addExtension(new File(CONFIG.getProperty("agentswitcher")));
String samsung3 = "Mozilla/5.0 (Linux; U; Android 4.0.3; de-de; Galaxy S II Build/GRJ22) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30";
ffProfile.setPreference("general.useragent.override", samsung3);

这里代理切换器是user_agent_switcher-0.7.3-fx+sm.xpi文件从 WEB 下载它

这很简单。

您需要将 ChromeOptions 的参数传递给 ChromeDriver 的构造函数

代码是下一个:

string device = "Samsung Galaxy S4";
ChromeOptions options = new ChromeOptions();
options.EnableMobileEmulation(device);
IWebDriver driver = new ChromeDriver(options);//this will open Chrome in mobile mode

您可以从 Chrome 移动模拟器获取的可用设备列表。

其中一些是:"苹果iPhone 4","苹果iPhone 6","三星Galaxy S4"

使用以下代码在移动视图中启动 chrome 浏览器

System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver.exe");

Map<String,> mobileEmulation

= new HashMap<>(); mobileEmulation.put("deviceName", "Galaxy S5");

ChromeOptions options = new ChromeOptions(); options.setExperimentalOption("mobileEmulation", mobileEmulation);ChromeDriver driver = new ChromeDriver(options) driver.get("http://google.com");log.info(driver.getTitle());driver.quit();

最新更新