XVFB实现selenium在linux上无界面运行安装篇
selenium在linux上无界面运行,其实是非常简单的。具体的方法有使用HtmlUnitDriver或者PhantomJSDriver,有时间我会写写关于这两个东东的文章,其实基本和ChromeDriver 和FirefoxDriver是一样的。但是有些人或者会比较排斥他们说HtmlUnitDriver对JS支持不好,PhantomJSDriver估计也很少有人用,其实他是对Phantomjs的封装,对这些不做多过评论,我用下来感觉还好。
还有另一种方法,就是使用XVFB, 有人说XVFB是什么,没听说过,没听说过就自己Google吧。
这里就主要是讲一下XVFB的安装使用。以chrome + ubuntu 和 firefox + centOS 为例子(chrome linux版好像是到6的时候就不支持centOS了, 都自带firefox )
一、 XVFB在Ubuntu上的安装(chrome)
1. 安装ubuntu(百度google安装步骤)
2. putty.exe 连接ubuntu
安装openssh-server:sudo apt-get install openssh-server
启动openssh-server: sudo /etc/init.d/ssh start
确认openssh-server是否启动:ps -e | grep ssh
telnet ip 端口号
3. 安装oracle JDK6:(可跳过:自带penjdk-6-jre)
$ remove openjdk: sudo apt-get autoremove openjdk-6-jre
$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java6-installer
$ sudo update-java-alternatives -s java-6-oracle
4. 装chrome:(自带firefox)
http://www.ubuntuupdates.org/ppa/google_chrome
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
sudo apt-get update
sudo apt-get install google-chrome-stable
5. 装xvfb 及各种:
sudo apt-get update && sudo apt-get install -y xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic xvfb x11-apps imagemagick firefox google-chrome-stable
OK, 到这一步都装好了。
二、测试安装
putty连接Ubuntu运行下面命令:
1. 启动Xvfb服务
Xvfb -ac :7 -screen 0 1280x1024x8 (注意这个是x, 不是* 哦)
2. 启动firefox or chrome
export DISPLAY=:7
/usr/bin/google-chrome-stable http://www.investopedia.com //chrome 浏览www.investopedia.com
或者
export DISPLAY=:7
firefox http://www.investopedia.com //firefox 浏览www.investopedia.com
如果运行完后,出现:
Xlib: extension "RANDR" missing on display ":7"
我想说,you made it. 这是个无关紧要的信息,之前我试图解决掉它,没有成功。最后我在运行selenium脚本后,完全没有出现这个信息,脚本执行很正常,所以现在我把它当做是安装成功的信息。
当然运行selenium 脚本前总不能老是敲一遍这些命令,太麻烦了。
弄成一个服务,先 touch /etc/init.d/xvfb
脚本如下:
- #! /bin/bash
- if [ -z "$1" ]; then
- echo "`basename $0` {start|stop}"
- exit
- fi
- case "$1" in
- start)
- /usr/bin/Xvfb :7 -ac -screen 0 1024x768x8 &
- ;;
- stop)
- killall Xvfb
- ;;
- esac
修改脚本权限,启动服务:
chmod +x /etc/init.d/xvfb
chkconfig xvfb on
service xvfb start
停止服务的话就是: service xvfb stop
完毕了。
三、Xvfb在CentsOS安装
- Install Xvfb with library:
- yum install Xvfb
- yum -y install libXfont
- yum install xorg-x11-fonts*
- touch /etc/init.d/xvfb with content:
- #!/bin/bash
- #
- # /etc/rc.d/init.d/xvfbd
- #
- # chkconfig: 345 95 28
- # description: Starts/Stops X Virtual Framebuffer server
- # processname: Xvfb
- #
- . /etc/init.d/functions
- [ "${NETWORKING}" = "no" ] && exit 0
- PROG="Xvfb"
- PROG_OPTIONS=":7 -ac -screen 0 1024x768x24"
- PROG_OUTPUT="/tmp/Xvfb.out"
- case "$1" in
- start)
- echo -n "Starting : X Virtual Frame Buffer "
- $PROG $PROG_OPTIONS>>$PROG_OUTPUT 2>&1 &
- disown -ar
- /bin/usleep 500000
- status Xvfb & >/dev/null && echo_success || echo_failure
- RETVAL=$?
- if [ $RETVAL -eq 0 ]; then
- /bin/touch /var/lock/subsys/Xvfb
- /sbin/pidof -o %PPID -x Xvfb > /var/run/Xvfb.pid
- fi
- echo
- ;;
- stop)
- echo -n "Shutting down : X Virtual Frame Buffer"
- killproc $PROG
- RETVAL=$?
- [ $RETVAL -eq 0 ] && /bin/rm -f /var/lock/subsys/Xvfb /var/run/Xvfb.pid
- echo
- ;;
- restart|reload)
- $0 stop
- $0 start
- RETVAL=$?
- ;;
- status)
- status Xvfb
- RETVAL=$?
- ;;
- *)
- echo $"Usage: $0 (start|stop|restart|reload|status)"
- exit 1
- esac
- exit $RETVAL
- Registering in system and start:
- chmod +x /etc/init.d/xvfb
- chkconfig xvfb on
- service xvfb start
- now
- export DISPLAY=:7 (actually you should add this to your etc/bashrc)
selenium 脚本测试一下环境:
随便丢个简单的selenium 写的脚本到配制好的测试机子上运行,如果没有任何报错,说明环境就是配制Ok的。
参考资料:
http://rrroutes.blogspot.com/2013/04/settup-environment-for-selenium-tests.html
http://www.installationpage.com/selenium/how-to-run-selenium-headless-firefox-in-ubuntu/
http://ralf.schaeftlein.de/2012/05/26/running-headless-webdriver-based-selenium-junit-tests-inside-jenkins-under-ubuntu-linux/
https://gist.github.com/textarcana/5855427
http://stackoverflow.com/questions/17944234/xlib-extension-randr-missing-on-display-21-trying-to-run-headless-googl
XVFB实现selenium在linux上无界面运行安装篇的更多相关文章
- matlab linux下无界面运行
今日做吸引域的仿真,由于需要遍历100*100*100的空间,需要的时间比较长,发现程序没运行一段时间,就会出现Out of memory的错误,而且出错的部分在于截取figure内部图片的部分. 开 ...
- 第三百五十二节,Python分布式爬虫打造搜索引擎Scrapy精讲—chrome谷歌浏览器无界面运行、scrapy-splash、splinter
第三百五十二节,Python分布式爬虫打造搜索引擎Scrapy精讲—chrome谷歌浏览器无界面运行.scrapy-splash. splinter 1.chrome谷歌浏览器无界面运行 chrome ...
- 三十一 Python分布式爬虫打造搜索引擎Scrapy精讲—chrome谷歌浏览器无界面运行、scrapy-splash、splinter
1.chrome谷歌浏览器无界面运行 chrome谷歌浏览器无界面运行,主要运行在Linux系统,windows系统下不支持 chrome谷歌浏览器无界面运行需要一个模块,pyvirtualdispl ...
- centos 无界面 服务器 安装chrome部署chromedriver
转:https://blog.csdn.net/u013849486/article/details/79466359 基本 做完了,要弄进docker里面去了的时候,才搜到 docker-chrom ...
- 在Linux上显示正在运行的进程的线程ID
在Linux上显示正在运行的进程的线程ID 在上Linux," ps -T"可以显示正在运行的进程的线程信息: # ps -T 2739 PID SPID TTY STAT TIM ...
- linux无界面模式安装selenium+chrome+chromedriver并成功完成脚本(亲测可用)
环境:docker centos 7.4 能通外网 写好的selenium脚本. 具体步骤: 一:安装selenium 这是最简单的 直接利用 pip3 install selenium 二 安装c ...
- 无界面运行Jmeter压测脚本 --后知者
原文作者---后知者 原文地址:http://www.cnblogs.com/houzhizhe/p/8119735.html [后知者的故事]:针对单一接口压测时出现了从未遇到的问题,设好并发量后用 ...
- 无界面运行Jmeter压测脚本
今天在针对单一接口压测时出现了从未遇到的问题,设好并发量后用调度器控制脚本的开始和结束,但在脚本应该自动结束时间,脚本却停不下来,手动stop报告就会有error率,卡了我很久很久不能解决,网络上也基 ...
- 在 linux 上部署并运行 JavaFX 项目
环境 redhat 6.4.eclipse安装JavaFX插件 项目详情及代码参见 在linux上配置并创建JavaFX项目 ,该部署即此文章中项目的部署 配置build.fxbuild 生成buil ...
随机推荐
- 20165203 Mypwd的解读与实现
20165203 Mypwd的解读与实现 pwd 含义:在Linux层次结构中,想要知道当前所处的目录,可以用pwd命令,该命令显示整个路径名. 语法:pwd [option] 描述:pwd 命令将当 ...
- Qt_mingw搭建opencv开发环境
Qt在windows下共有2个版本:mingw和msvc.其中mingw使用gcc编译器,msvc使用微软的VC编译器.针对不同版本Qt,使用Opencv的方式也不同. 区别 msvc, 可以使用op ...
- PHP实现数据分页显示
分页在后台管理中是经常使用的功能,分页显示方便大量数据的管理. 实例代码如下: <!DOCTYPE html> <html> <head> <meta cha ...
- ETL数据清洗工具总结
[国外] 1. datastage点评:最专业的ETL工具,价格不菲,使用难度一般 下载地址:ftp://ftp.seu.edu.cn/Pub/Develop ... taStage.v7.5.1A- ...
- NOI.AC NOIP模拟赛 第三场 补记
NOI.AC NOIP模拟赛 第三场 补记 列队 题目大意: 给定一个\(n\times m(n,m\le1000)\)的矩阵,每个格子上有一个数\(w_{i,j}\).保证\(w_{i,j}\)互不 ...
- poj 1511 优先队列优化dijkstra *
题意:两遍最短路 链接:点我 注意结果用long long #include<cstdio> #include<iostream> #include<algorithm& ...
- 20172308《Java软件结构与数据结构》第三周学习总结
教材学习内容总结 第 5 章 队列 队列: 一种线性集合,其元素从一端加入,从另一端删除 元素处理:FIFO 与栈的比较 异:(1) 栈的处理过程只在栈的某一端进行:队列的处理过程在队列的两端进行.( ...
- java基础学习总结——super关键字
一.super关键字
- LPC1800 and LPC4300 Boot/ISP/CRP
MCU的启动方式有很多种:UART接口,扩展的静态存储单元(NOR Flash), SPI Flash,quad SPI Flash,高速USB0和USB1.另外可以通过对OTP存储单元的编程. 首先 ...
- SRM 449 DIV 1 总结(550p标记下,下次做)
今天的250p搞得有点久了,500p是个类似铺瓷砖的dp题,这样先占个坑,给个poj的这类题列表,下次刷完了回来做! POJ 相关DP列表 http://blog.csdn.net/jayye1994 ...