JAVA代碼
public class TestSelenide {
// chromedriver路徑
private static final String CHROME_DRIVER_PATH = "d:/webdrivers/chromedriver.exe";
// 手機(jī)型號(hào)
private static final String DEVICENAME = "iPhone 6";
@Before
public void before() {
System.setProperty("webdriver.chrome.driver", CHROME_DRIVER_PATH);
Map<String, String> mobileEmulation = new HashMap<String, String>();
mobileEmulation.put("deviceName", DEVICENAME);
// 配置ChromeOptions
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("mobileEmulation", mobileEmulation);
// 聲明ChromeDriver并把ChromeOptions傳入
WebDriver driver = new ChromeDriver(options);
// 設(shè)置Selenide使用的webdriver為我們創(chuàng)建并配置的ChromeDriver
WebDriverRunner.setWebDriver(driver);
Configuration.baseUrl = "https://m.zhihu.com";
}
@Test
public void test() {
// 打開(kāi)頁(yè)面
open("/");
}
@After
public void after() {
// 關(guān)閉瀏覽器
close();
}
}