Selenide启用chrome移动模式

JAVA代码

public class TestSelenide {
    // chromedriver路径
    private static final String CHROME_DRIVER_PATH = "d:/webdrivers/chromedriver.exe";
    // 手机型号
    private static final String DEVICENAME = "iPhone 6";

    @Before
    public void before() {
        System.setProperty("webdriver.chrome.driver", CHROME_DRIVER_PATH);

        Map mobileEmulation = new HashMap();
        mobileEmulation.put("deviceName", DEVICENAME);

        // 配置ChromeOptions
        ChromeOptions options = new ChromeOptions();
        options.setExperimentalOption("mobileEmulation", mobileEmulation);

        // 声明ChromeDriver并把ChromeOptions传入
        WebDriver driver = new ChromeDriver(options);

        // 设置Selenide使用的webdriver为我们创建并配置的ChromeDriver
        WebDriverRunner.setWebDriver(driver);

        Configuration.baseUrl = "https://m.zhihu.com";
    }

    @Test
    public void test() {
        // 打开页面
        open("/");
    }
    
    @After
    public void after() {
        // 关闭浏览器
        close();
    }
}

你可能感兴趣的:(Selenide启用chrome移动模式)