mannual和adhoc模式比较

Manual vs. Adhoc

In the script above, we start the ChromeDriver server process when we create the WebDriver object and it is terminated when we call quit(). For a one-off script, that isn’t a problem, but this can waste a nontrivial amount of time for a large test suite that creates a ChromeDriver instance for each test. Luckily, we can manually start and stop the server ourselves, and it only requires a few changes to the script above.

说的在使用selenium+chromeheadless做自动化测试时候,如果测试用例数量大,给每个测试用例启动一个浏览器要话费更多的时间。

#coding=utf8
import os,traceback
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
service = webdriver.chrome.service.Service('/home/xxxx/Downloads/phantomjs-2.1.1-linux-x86_64/bin/chromedriver')
service.start()
class ChromeHeadless(object): def __init__(self): chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--disable-images')
chrome_options.add_argument('--disable-plugins')
chrome_options.binary_location = '/opt/google/chrome/chrome'
#prefs = {"profile.managed_default_content_settings.images": 2} # 关图片
#chrome_options.add_experimental_option("prefs", prefs)
self.chrome_options=chrome_options
self.driver = webdriver.Remote(service.service_url,desired_capabilities=self.chrome_options.to_capabilities())
self.driver.set_page_load_timeout(120) def fun(self,url): try:
proxy_http_list = list(r.smembers('kuaidaili:http')) + list(r.smembers('zhima'))
pr=random.choice(proxy_http_list)
self.chrome_options.add_argument('--proxy-server=%s'%pr) #设置代理
self.driver.start_session(self.chrome_options.to_capabilities())
#print self.driver.session_id
self.driver.get(url) except Exception,e: print '\033[7;32;0m%s\033[0m' %traceback.format_exc()
												

selenium +chrome headless Adhoc模式渲染网页的更多相关文章

  1. selenium +chrome headless Manual 模式渲染网页

    可以看看这个里面的介绍,写得很好.https://duo.com/blog/driving-headless-chrome-with-python from selenium import webdr ...

  2. ubuntu服务器端使用无界面selenium+ chrome + headless

    本来想直接用Ubuntu系统里面的firefox来实现selenium自动操作签到的,但是总是出各种问题.没办法,改为Chrome.参考:Ubuntu 线上无界面服务器 使用selenium chro ...

  3. 笔记-selenium+chrome headless

    笔记-selenium+chrome headless 1.      selenium+chrome headless phantomjs与selenium分手了,建议使用其它无头浏览器. chro ...

  4. chrome浏览器爬虫WebDriverException解决采用python + selenium + chrome + headless模式

    WebDriverException: Message: unknown error: Chrome failed to start: crashed 第一种:如果出现下面情况: chrome浏览器有 ...

  5. selenium chrome headless无界面引擎

    注意:PhantomJS已被舍弃 chrome headless 在打开浏览器之前添加参数 import time import sys from selenium import webdriver ...

  6. Selenium + Chrome headless 报ERROR:gpu_process_transport_factory.cc(1007)] Lost UI shared context 可忽略并配置不输出日志

    Selenium不再推荐使用PhantomJS,会报如下警告 UserWarning: Selenium support for PhantomJS has been deprecated, plea ...

  7. ubuntu中如何安装selenium+chrome(headless)无界面浏览器?

    selenium是一个Web的自动化测试工具,它可以根据我们的指令,让浏览器自动加载页面,获取需要的数据,甚至页面截屏,或者判断网站上某些动作是否发生.但是它自身不带浏览器,不支持浏览器的功能,因此它 ...

  8. Ubuntu 无界面使用selenium chrome + headless

    1. 安装 selenium : sudo pip install selenium 2. 安装 chromdriver: 进入 淘宝镜像源 下载 chromdriver, 可以查看 notes.tx ...

  9. 关于强制IE不使用兼容模式渲染网页

    现在IE11是唯一受微软支持的IE浏览器. IE11有兼容模式,开启后有网页会出错. 在html header标签下加上 <meta http-equiv="X-UA-Compatib ...

随机推荐

  1. 一、安装MYSQL

    数据库就是数据的仓库.MYSQL数据库软件它也是一个独立的软件.它是和PHP配合最好的一种数据库.MYSQL数据库也可以作为其它编程语言的数据源. MYSQL的官方网站:http://www.mysq ...

  2. es 剩余磁盘空间达到es最小值,添加数据被block

    剩余磁盘空间达到es最小值,添加数据被block PUT _all/_settings {"index.blocks.read_only_allow_delete": null} ...

  3. SpringBoot2 启动报错 Failed to auto-configure a DataSource

    今天Spring Boot 2.0正式版发布,寻思着搭个小demo尝试一下Spring Boot的新特性,使用idea创建项目.在选择组件时添加了mysql.mybatis 然后在第一次启动的时候启动 ...

  4. Spring MVC异常处理SimpleMappingExceptionResolver

    Spring MVC异常处理SimpleMappingExceptionResolver[转] (2012-12-07 13:45:33) 转载▼ 标签: 杂谈 分类: 技术分享 Spring3.0中 ...

  5. Error:Error converting bytecode to dex: Cause: com.android.dex.DexException: Multiple dex files define Lcom/lidroid/xutils/task/TaskHandler;

    Error:Error converting bytecode to dex: Cause: com.android.dex.DexException: Multiple dex files defi ...

  6. jQuery 与 prototype 共存

    方法一: <html>   <head>     <script src="prototype.js"></script>     ...

  7. 更改虚拟机UUID

    如何更改虚拟机UUID?以下方法适用于:Parallels Desktop 10 for MacParallels Desktop 9 for MacParallels Desktop 8 for M ...

  8. USB2.0学习笔记连载(十):关于WIN8及以上系统哈希值问题

    笔者上一篇博客讲解了关于驱动的安装,笔者使用的系统是win8.1系统,那么对于win8系统及以上系统,会对外部设备,没有在windows系统中进行签名过的,都是不允许在windows系统中进行安装的, ...

  9. python公司内部语言规范与语言风格

    一.python语言规范 1.1导入 Tip: 仅对包和模块使用导入 定义: 模块间共享代码的重用机制. 优点: 命名空间管理约定十分简单.每个标识符的源都用一种一致的方式指示.x.obj 表示obj ...

  10. Numpy 的数组转置和轴对换

    数组转置 转置(transpose)是重塑的一种特殊形式, 它返回的是源数据的视图(不会进行任何操作.)数组不仅有transpose,还要特殊的T属性 计算矩阵内积 高维数组transpose 详细讲 ...