使用selenium grid与BrowserMobProxyServer联合使用
背景:项目主要是做埋点数据,要使用 BrowserMobProxyServer,它相当于做一个代理,在你访问一个网页时,通过代理,获取打开网页的数据,对比你需要对比数据,所以这个工具提供获取页面请求的功能,因为我这里是使用的grid分发,demo如下
public class fg {
public static void main(String[] args) {
String browser = "chrome";
BrowserMobProxyServer proxy = null;
// TODO Auto-generated method stub
DesiredCapabilities brwosers = null;
try {
System.out.println("使用的平台进行启动的浏览器,使用的浏览器为:" + browser);
System.setProperty("webdriver.chrome.driver", "resources/chromedriver.exe");
proxy = new BrowserMobProxyServer();
int port = 8750;
proxy.start(port);
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(new InetSocketAddress("10.32.5.199", port)); //IP地址一定是你运行的ip地址,不然会提示代理设置错误的
brwosers = DesiredCapabilities.chrome();
brwosers.setCapability(CapabilityType.PROXY, seleniumProxy);
RemoteWebDriver driver = new RemoteWebDriver(new URL("http://10.40.6.232:4444/wd/hub"), brwosers);
driver.manage().window().maximize(); // 设置窗口为最大
// 获取driver的session
String getSession = driver.toString().substring(driver.toString().indexOf("(") + 1,
driver.toString().indexOf(")"));
// get请求,获取在hub上分发到某台电脑运行
Map<String, String> getIP = Pub.get("http://10.40.6.232:4444/grid/api/testsession?session=" + getSession);
Gson gson = new Gson();// 从返回内容中获取到需要的内容
Map<String, Object> map = new HashMap<String, Object>();
map = gson.fromJson(getIP.get("Response"), map.getClass());
String proxyId = (String) map.get("proxyId");
System.out.println("服务器运行的ip为:" + proxyId);
driver.get("https://login.rosewholesale.com/m-users-a-sign.htm");
Har har = new Har();
proxy.newHar("login.rosewholesale.com/m-users-a-sign.htm");
har = proxy.getHar();
har.writeTo(new java.io.File("C:\\a.txt"));
proxy.stop();
} catch (Exception e) {
e.printStackTrace();
}
}
}
获取的数据

使用selenium grid与BrowserMobProxyServer联合使用的更多相关文章
- 搭建selenium grid简单配置
1.使用selenium提供的服务端独立jar包 :服务端.客户端都是运行于java7环境. 2.启动hub: hub配置文件如下: Java -jar selenium-server-standal ...
- Robot Framework + Selenium2Library环境下,结合Selenium Grid实施分布式自动化测试
最近一段时间,公司在推行自动化测试流程,本人有幸参与了自定义通用控件的关键字封装和脚本辅助编写.数据驱动管理.测试用例执行管理等一系列工具软件的研发工作,积累了一些经验,在此与大家做一下分享,也算是做 ...
- Selenium Grid 学习笔记
Selenium Grid 学习笔记http://www.docin.com/p-765680298.html
- Selenium Grid 运行报错 Exception thrown in Navigator.Start first time ->Error forwarding the new session Empty pool of VM for setup Capabilities
Selenium Grid 运行报错 : Exception thrown in Navigator.Start first time ->Error forwarding the new se ...
- selenium Grid(一)
selenium grid Quick Start selenium-grid是用于设计帮助我们进行分布式测试的工具,其整个结构是由一个hub节点和若干个代理节点组成.hub用来管理各个代理节点的注册 ...
- selenium Grid
Selenium Grid 的机制是启动一个 hub,然后启动多个 Selenium RC 注册到 hub 上, 当测试请求到 hub 时,hub 会将测试分发给 Selenium RC, Selen ...
- selenium grid java 资料
Grid TestNG: 使用Selenium Grid改进Web应用程序的测试: http://www.ithov.com/server/117464.shtml
- Selenium Grid跨浏览器-兼容性测试
Selenium Grid跨浏览器-兼容性测试 这里有两台机子,打算这样演示: 一台机子启动一个作为主点节的hub 和 一个作为次节点的hub(系统windows 浏览器为ie) ip为:192.16 ...
- selenium grid的使用与配置
一.selenium grid的组成与作用:由一个集线器hub和多个客户机node组成,如果你的程序需要在不用的浏览器,不同的操作系统上测试,而且比较多的case需要多线程远程执行,那么一个比较好的测 ...
随机推荐
- Ansible故障
常见问题一: [root@m01 ~]# ansible -k 172.16.1.51 -m ping SSH password: [WARNING]: No hosts matched, noth ...
- management & Actuator
self define indicator https://docs.spring.io/spring-boot/docs/current/reference/html/production-read ...
- MB Star C5 Functions
The MB STAR C5 notion and brand combination for hardware and software program components will be the ...
- mapreduce求平均数
1. 现有某电商关于商品点击情况的数据文件,表名为goods_click,包含两个字段(商品分类,商品点击次数),分隔符“ ”,由于数据很大,所以为了方便统计我们只截取它的一部分数据,内容如下 ...
- 终极版clearFix——支持IE6+
/*兼容IE6.7*/ /*这段代码非常暴力,from internet,墙裂推荐*/ .clearFix:before,.clearFix:after{ content:""; ...
- 对象池1(方法功能)PoolOption
2.对象池PoolOption(方法功能) //单类型缓冲对象管理(单模池操作管理)功能: 激活.收回.预加载等. namespace kernal { [System.Serializable] p ...
- express中connect-flash中间件的使用
在学习node的时候,flash是困扰我最久的一个中间件,之前一直都没有很好的理解,这里做一个总结. 参考自:http://yunkus.com/connect-flash-usage/ 什么是fla ...
- DEDE把变量放进session中,结果取值为null的问题
最近在基于织梦CMS(dedecms)做公司网站,可以说改动不少,而其中最令我印象深刻的就是织梦的session. 自己想在前台页面限制一些用户的访问,且后台用户可以访问.必须验证织梦后台用户的 ...
- MS-DOS
MS-DOS doskey /history /reinstall /buffersize /macros doskey di=dir /w/p defrag 磁盘碎片整理 xcopy deltree ...
- mustache语法 转自小花大方
mustache语法 mustache 模板,用于构造html页面内容.在实际工作中,当同一个模板中想要调用不同的函数来渲染画面,在已经自定义好了的前提下,可以在渲染页面时对传入的参数进行手动判断.[ ...