不启动浏览器运行selenium 的webdriver:HtmlUnit Driver(python)

slemium webdriver 支持多种情况模拟用户操作浏览器。如:IE,chrome,Firefox等。同时,selenium还有一种HtmlUnit Driver驱动能够在不启动浏览器的情况下运行相关测试用例。
 
利用HtmlUnit Driver方式运行测试用例大大减少了等待浏览器展现的时间。
 
如果需要使用HtmlUnit Driver方式,需要下载一个selenium-server-standalone.jar程序,进行模拟代理服务器运行。
 
运行selenium-server-standalone.jar程序前提条件是机器上安装了java运行环境。
 
由于selenium官网总是不能访问,只能从其他地方下载相关程序。selenium-server-standalone.jar程序可以从github.com的网站上获得。我找了一个项目从中获取了该程序。地址如下:
 
 
在机器存放selenium-server-standalone.jar的路径下运行命令:
java -jar selenium-server-standalone.jar -port 4446
 
端口号一般设定为4444,我自己设定为4446.
 
程序启动后,在浏览器中输入:
 
可以看到服务启动后的session信息。用于实时监控运行情况。
 
在python代码中调用HtmlUnit Driver命令如下:
from selenium import webdriver 
 或者 (支持javascript方式)
 
运行程序后,可以看到浏览器没有启动,但是在selenium-server-standalone.jar程序的运行cmd窗口和   http://localhost:4446/wd/hub/static/resource/hub.html页面中均显示了相关的执行信息。

猜你喜欢

转载自www.cnblogs.com/x666-6/p/9103626.html