zoukankan      html  css  js  c++  java
  • selenium 使用谷歌浏览器模拟wap测试

        /**
         * 使用谷歌浏览器模拟手机浏览器
         * @param devicesName
         * @author xxx
         * 创建时间:2017-06-15,更新时间:2017-06-15
         * 备注
         */
        public void initdriver(String devicesName){
            System.setProperty("webdriver.chrome.driver", "resources/chromedriver.exe");
            Map<String, String> mobileEmulation = new HashMap<String, String>();
            //设置设备,例如:Google Nexus 7/Apple iPhone 6
            //mobileEmulation.put("deviceName", "Google Nexus 7"); 
            Log.logInfo("使用谷歌浏览器模拟手机设备为:"+devicesName);
            mobileEmulation.put("deviceName", devicesName); 
            Map<String, Object> chromeOptions = new HashMap<String, Object>();     
            chromeOptions.put("mobileEmulation", mobileEmulation);     
            DesiredCapabilities capabilities = DesiredCapabilities.chrome();       
            capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
            try {
                Log.logInfo("开始启动driver~~~");
                driver = new ChromeDriver(capabilities);
                Log.logInfo("启动driver成功~~~");
            } catch (Exception e) {
                Log.logInfo("启动driver失败~~~");
                Log.logInfo(e.getMessage());
            }        
        }

    devicesName名称规范,可安如下图填写:

    运行的效果:

  • 相关阅读:
    我总结的面试题系列:kafka
    RabbitMQ大厂面试题
    [Algorithm] 并查集
    [LintCode] 编辑距离
    [LeetCode] Length of Longest Fibonacci Subsequence
    [LintCode] 交叉字符串
    [LeetCode] Permutation Sequence
    Permutation Sequence
    [LeetCode] Next Permutation
    [LeetCode] Longest Palindromic Substring
  • 原文地址:https://www.cnblogs.com/lincj/p/7068347.html
Copyright © 2011-2022 走看看