随着移动设备使用率的不断增加,移动页面的测试也变得越来越重要。

对于互联网公司M站的测试,如果不通过专用的appium等移动端测试工具是否还有方便快捷的办法呢?答案当然是有啊。

使用chrome driver和chrome浏览器并进入chrome的 toggle device mode 模式,就可以很好的模拟手机端,下面直接上代码。

public class Test{
public static void main(String args[])
{
System.setProperty("webdriver.chrome.driver", "E:/Software/自动化软件/chromedriver.exe");
Map<String, String> mobileEmulation = new HashMap<String, String>();
mobileEmulation.put("deviceName", "Google Nexus 5");
Map<String, Object> chromeOptions = new HashMap<String, Object>();
chromeOptions.put("mobileEmulation", mobileEmulation);
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
WebDriver driver = new ChromeDriver(capabilities);
Navigation navigation=driver.navigate();
navigation.to("https://m.baidu.com/");
String title=driver.getTitle();
System.out.println("title:"+title); } }

  说一下我使用的chrome版本和chromedriver版本,这两个如果配合不好会有坑。

Chrome version:

Chrome driver:

去这个地方 http://chromedriver.storage.googleapis.com/index.html 打不开自己想办法吧,哈哈,下载2.15版本 我是windows平台,下载的32那个,这样selenium每次打开浏览器就是手机模式了,可以操作对手机方面的一些测试。

-----------------------from 鑫测试

最新文章

  1. POJ1753(位操作和枚举)
  2. Java异常体系及分类
  3. CSS的一些零碎总结
  4. Python基于pandas的数据处理(二)
  5. Java 并发和多线程(二) 多线程的优点 [转]
  6. Careercup - Google面试题 - 4847954317803520
  7. Ext 面向对象程序设计 入门篇
  8. HDU4666 Hyperspace(曼哈顿)
  9. python的hashlib模块
  10. HTML5 canvas translate() 方法
  11. HDU 3788 和九度OJ 1006测试数据是不一样的
  12. 使用SoapUI 测试Web Service
  13. 【高斯消元】兼 【期望dp】例题
  14. DevExpress VCL Controls 2019发展路线图(No.2)
  15. Use Generic Replacements of 1.X Framework API Classes 用泛型替换Framework 1.X版本的API类
  16. css sprite实例
  17. win10无法访问samba共享
  18. C语言 字符串处理函数 转自 http://blog.chinaunix.net/uid-25885064-id-3175049.html
  19. 小菜读书---《Effective C#:改善C#程序的50种方法》
  20. ElasticSearch 2.0以后的改动导致旧的资料和书籍需要订正的部分

热门文章

  1. 微信小程序-提示框
  2. 深入理解IOC模式及Unity框架
  3. Spring基于注解ehCache缓存整合
  4. medoo–高效的轻量级PHP数据库操作类
  5. 7 -- Spring的基本用法 -- 6...
  6. web.xml中的contextConfigLocation在spring中的作用
  7. Configure Apache Virtual Hosts - CentOS 7
  8. SPSS数据分析—配对Logistic回归模型
  9. python 基本语法
  10. linux 挂载光盘:mount: you must specify the filesystem type