谷歌浏览器模拟手机浏览器且指定IP运行
1.背景
因为现在项目是要做分布式,而以前使用谷歌浏览器模拟手机运行做的分布式,是指定在某台机器运行是通过Jenkins配置,来指定服务器,但是这样有一个问题,如果大家都同时配置到某台电脑,那台服务器压力就很大,所以需要根据每台服务器的情况,去分配任务,那我就需要解决第一个问题,如何让模拟器指定ip运行,我的项目的部署方式(分布式)使用的selenium grid 的方式,使用模拟器方式最开始一直使用的是ChromeDriver方式启动,但是这个ChromeDriver方式启动只能是启动本地浏览器,进行手机模拟,不能指定在某台IP上进行运行
最开始看了很多官网资料,https://sites.google.com/a/chromium.org/chromedriver/mobile-emulation ,针对ChromeDriver java没有办法指定IP,而python可以,最开始走了一大圈,想通过ChromeDriver的方法来进行改变,饶了一大圈的弯路,最后想通了一点只要更换启动方式就可以了

以前启动手机模拟代码是这样:
public void initdriver(){
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-infobars");
Map<String, Object> prefs = new HashMap<String, Object>();
// 是否加载图片
// prefs.put("profile.managed_default_content_settings.images", 2);
options.setExperimentalOption("prefs", prefs);
Map<String, Object> deviceMetrics = new HashMap<String, Object>();
deviceMetrics.put("width", 360);
deviceMetrics.put("height", 640);
deviceMetrics.put("pixelRatio", 3.0);
Map<String, Object> mobileEmulation = new HashMap<String, Object>();
mobileEmulation.put("deviceMetrics", deviceMetrics);
mobileEmulation.put("userAgent",
"Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19");
options.setExperimentalOption("mobileEmulation", mobileEmulation);
System.setProperty("webdriver.chrome.driver", "resources/chromedriver.exe");
driver = new ChromeDriver(options);
}
而现在我只需要把启动方式做更改
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-infobars");
Map<String, Object> prefs = new HashMap<String, Object>();
// 是否加载图片
// prefs.put("profile.managed_default_content_settings.images", 2);
options.setExperimentalOption("prefs", prefs);
Map<String, Object> deviceMetrics = new HashMap<String, Object>();
deviceMetrics.put("width", 360);
deviceMetrics.put("height", 640);
deviceMetrics.put("pixelRatio", 3.0);
Map<String, Object> mobileEmulation = new HashMap<String, Object>();
mobileEmulation.put("deviceMetrics", deviceMetrics);
mobileEmulation.put("userAgent",
"Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19");
options.setExperimentalOption("mobileEmulation", mobileEmulation);
System.setProperty("webdriver.chrome.driver", "resources/chromedriver.exe");
if(TestngListener2.getProjectCode().contains("platform")){//这里表示使用的平台,为了不影响以前框架使用
System.out.println("使用的平台进行启动的浏览器");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
try {
driver = new RemoteWebDriver(new URL("http://10.40.2.114:5555/wd/hub"), capabilities);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}else{
driver = new ChromeDriver(options);
} }
谷歌浏览器模拟手机浏览器且指定IP运行的更多相关文章
- 在PC上测试移动端网站和模拟手机浏览器的5大方法
在PC上测试移动端网站和模拟手机浏览器的5大方法 来源:互联网 作者:佚名 时间:03-19 10:14:54 [大 中 小] 最近公司要开发网站的移动版,让我准备准备知 ...
- Selenium操作Chrome模拟手机浏览器
目录 使用指定设备 使用自定义设备 在使用Chrome浏览网页时,我们可以使用Chrome开发者工具模拟手机浏览器,在使用Selenium操作Chrome时同样也可以模拟手机浏览器.主要有以下两种用途 ...
- 用PC浏览器模拟手机浏览器(一):无扩展版
想浏览手机版,打开对应网址却跳转到PC版?怎么办? 下面咱们来说下在只是安装了浏览器,无需其他安装操作的情况下来怎么用PC浏览器模拟手机浏览器,然后访问手机站点. 浏览器众多,IE系列的咱就不考虑了, ...
- Opera浏览器测试移动端网站和模拟手机浏览器的方法
链接地址:http://www.neirong.org/post-256.html?utm_source=tuicool Chrome浏览器请看:Chrome浏览器测试移动端网站和模拟手机浏览器的方法 ...
- 无插件,直接加参数,chrome它可以模拟手机浏览器
在目标出现,加上一些参数即可:--user-agent="mozilla/5.0 (linux; u; android 2.3.3; en-us; sdk build/ gri34) app ...
- python自动化--mock、webservice及webdriver模拟手机浏览器
一.mock实现 自定义一个类,用来模拟未完成部分的开发代码 class Say(): def say_hello(self): pass 自定义返回值 import unittest from un ...
- 在PC上测试移动端网站和模拟手机浏览器的5大方
查了很多资料,尝试了大部分方法,下面将这一天的努力总结下分享给大家,也让大家免去看那么多文章,以下介绍的方法,都是本人亲自测试成功的方法,测试环境winxp. 一.Chrome*浏览器 chrome模 ...
- 【转】在PC上测试移动端网站和模拟手机浏览器的5大方法
查了很多资料,尝试了大部分方法,下面将这一天的努力总结下分享给大家,也让大家免去看那么多文章,以下介绍的方法,都是本人亲自测试成功的方法,测试环境winxp. 一.Chrome*浏览器 chrome模 ...
- PC上测试移动端网站和模拟手机浏览器
一.Chrome*浏览器 chrome模拟手机总共有四种方法,原理都一样,通过伪装User-Agent,将浏览器模拟成Android设备.以下标星的为推荐方法. 1.新建Chrome快捷方式 右击桌面 ...
随机推荐
- Linux下如何使用Wireshark进行抓包
1. 安装wireshark Ubuntu 14.04.3 缺省安装后, 不包含Wireshark抓包软件,因此首先需要手工进行Wireshark的安装: apt-get update apt ...
- 7.JSP简介
---恢复内容开始--- 1.JSP简介 Java动态网页技术标准(Java Server Pages)是基于Servlet技术以及整个Java体系的Web开发技术是用于动态生成HTML文档的Web页 ...
- 转 Python多版本管理-pyenv
#######for linux https://www.cnblogs.com/saneri/p/7642316.html 经常遇到这样的情况: 系统自带的Python是2.x,自己需要Python ...
- java多线程-创建线程
大纲: Thread创建线程. Runnable接口. Callable接口. 小结 一.java创建线程--继承Thead类 创建一个类继承Thead类,并重写run方法. class Test { ...
- 性能测试工具Jmeter10-Jmeter集合点与关联
集合点 操作步骤: 注意:集合点要放在需要集合的元件前面 关联 正则表达式提取器 配置说明 引用名称:下一个请求要引用的参数名称,如token,则可用${token}引用它 正则表达式: () 括起来 ...
- Murano Weekly Meeting 2015.08.25
Meeting time: 2015.August.25th 1:00~2:00 Chairperson: Serg Melikyan, PTL from Mirantis Meeting summ ...
- (转)mkpasswd 的使用
原文:http://blog.csdn.net/u010339879/article/details/69788032 这个命令是随机生成 密码的一个工具, 如果没有这个命令,请安装相应的包. yum ...
- Linux Bird
o / : 2GB o /boot: 200MB o /usr : 4GB o /var : 2GB o /tmp : 1GB o swap : 1GB o /home: 5GB,并且使用 LVM 模 ...
- HDU 4009——Transfer water——————【最小树形图、不定根】
Transfer water Time Limit:3000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64u Subm ...
- java题目练手
大数阶乘 题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=28 代码如下: import java.io.*; import java.ma ...