美文网首页
Selenide启用chrome移动模式

Selenide启用chrome移动模式

作者: Ksewen | 来源:发表于2017-12-06 11:34 被阅读0次

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

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

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

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

相关文章

网友评论

      本文标题:Selenide启用chrome移动模式

      本文链接:https://www.haomeiwen.com/subject/lxukixtx.html