Headless Browser Testing With Xvfb

2023-11-06

Jan 09 ’15·javascripttesting

These days, when the phrase "headless browser" is mentioned, you immediately think of PhantomJS, but - there are alternatives. In this article, I am going to introduce a nice alternative you can use on Linux which allows you to run real browsers - Firefox and Chrome, headless - using Xvfb.

What's Wrong With PhantomJS?

PhantomJS is great tool and is widely used by companies and developers around the world. It has particularly been widely adopted for running JavaScript test suites. However, using PhantomJS isn't without drawbacks. Although it is built on top on WebKit - the same rendering engine both Safari and Chrome use, it still behaves in subtly different ways from those browsers, which can cause false positives (tests failing when there is not a real defect) and in some cases performance degradation of your test suite. Since PhantomJS isn't a real browser in the sense that no end-user actually use it, fixing these issues specifically for PhantomJS becomes an upkeep cost of the test suite, rather than something that directly improves the product. Getting developers to write tests consistently is hard enough, but if maintaining the tests becomes annoying - which false positives definitely are - it can become demoralizing.

Run Real Browsers Headless

Because of the above reasons, at one point in my career I decided to use real browsers only to run JavaScript test suites. This has meant opening up a separate browser window to run the tests during development which I would simply hide in the background. I am okay with this. However, in many cases the continuous integration servers we use are Linux servers, and do not have displays. This is where Xvfb comes in.

Xvfb is a virtual display framebuffer for X - the display system used by Linux. It provides a fake display buffer for graphical programs to write to, thus allowing any program to run headlessly.

Installing Xvbf

If you are running Debian or Ubuntu and are using apt-get, installing is simply as:

apt-get install xvfb

If you are on CentOS and using yum, it's

yum install xorg-X11-server-Xvfb

Installing the Browsers

On Ubuntu, I found installing Chrome and Firefox painless.

  • For Chrome simply go to the Chrome download page, download the .deb file, then do dpkg -i <the path to the .deb file> to install.
  • For Firefox, it's just apt-get install firefox.

On CentOS, I have had more trouble.

  • For starters, Chrome is not supported on CentOS and I haven't even found a simply way to build Chrominum and I gave up.
  • Installing firefox also had a little hiccup: I ran yum install firefox, but then running firefox resulted in an error, which I solved by also installing gdk-pixbuf2 via yum install gdk-pixbuf2.

If you are on other Linux distros I haven't mentoned, checkout the Chrome download page and the Firefox on Linux page.

Xvfb Usage

The usage of Xvfb is:

xvfb-run <some command>

That's all you need to know! For example, you can run Firefox within Xvfb:

xvfb-run firefox http://google.com

This should just start a firefox process in the background. You may see a cryptic warning in the terminal, but otherwise it's not very exciting because you don't actually see anything.

If you use Testem to run tests, you can do:

xvfb-run testem -l firefox

to run your tests in Firefox or

xvfb-run testem -l chrome

to run them in Chrome - headless!

Of course, this is not limited to Testem, you can use xvfb-run with Karma, Grunt, Gulp or any other test runner that spawns a real browser and it will just work.

Implications

If you use Linux for development, this is an attractive solution. It allows you to run your tests without having an unwanted window and it's easy to setup and use. However, even if you don't use Linux for development, you may still use Linux for continuous integration, in which case, maybe you are currently using PhantomJS to run tests. If that's working well for you, great. But if PhantomJS is starting to create unwanted overhead for you, consider switching to this setup.


本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Headless Browser Testing With Xvfb 的相关文章

  • JavaScript常见调试方法

    编辑导语 javascript调试方法 常见使用alert和console来定位出错和输出的结果是否是想要的 在chrome中 还可以使用断点来看运行的情况等 本文介绍了比较全面的调试方法 你知道console table console
  • tomcat如何配置context的docBase

    docbase是web应用和本地路径 path是tomcat访问这个应用的URL路径 Tomcat的项目部署方式有以下三种 1 直接把项目复制到Tomcat安装目录的webapps目录中 这是最简单的一种Tomcat项目部署的方法 也是初学
  • IAR个人常用配置

    IAR个人常用配置 文章目录 IAR个人常用配置 1 设置 2 设置tab和indent为4空格 3 设置编码为UTF 8 4 自动缩进设置 5 修改背景颜色和字体 6 修改全局搜索快捷键 1 设置 Tools gt Options 2 设
  • Python - 我写代码时如果有一行过长该怎么处理?

    Python的编码规范要求每行的长度不超过80 那就就有一个问题 如果我真的需要在一行写80个字符以上的代码怎么办 Python语句都可以很简单的实现把一行分为多行 比如下面这两种写法是等价的 l 1 2 3 4 5 6 l 1 2 3 4
  • IDEA——》安装Scala插件

    推荐链接 总结 Java 总结 Mysql 总结 Redis 总结 Kafka 总结 Spring 总结 SpringBoot 总结 MyBatis MyBatis Plus 总结 Linux 总结 MongoDB 总结 Elasticse
  • java.lang.IllegalAccessError: class javax.activation.SecuritySupport12 cannot access its superclass

    最近加入新的项目组 eclipse tomcat7 spring ibatis restful 遇到了这样的问题 说是不能访问父类 我一开始以为是版本的原因 但是久经更改 错误依然 实在累了 最终的解决办法是我把SecuritySuppor
  • Visual Studio和idea自用快捷键

    写代码不停的在键盘与鼠标之间切换真的是非常影响心情 多学点快捷键 一能服务自己 二能在妹子前耍帅 何乐不为 因为自己还是菜鸡一个 很多功能自己还用不到 所以先贴上几个自己常用的还有想用的吧 网上的太全了自己看着也不方便 VS Studio快
  • Compile Options--编译选项

    目的 其主要作用是用于调试跟踪和测试 主要包含 MT TASK MT ZDO FUNC and other MT compile options LCD SUPPORTED LCD SUPPORTED DEBUG BLINK LEDS 且看
  • Pipenv:作为 Python 开发人员为什么应该使用它

    Pipenv 是一个旨在将所有打包世界中最好的东西带到 Python 世界的工具 它将 Pipfile pip 和 virtualenv 整合到一个命令中 它会自动为您的项目创建和管理虚拟环境 并在您安装 卸载包时从您的 Pipfile 添
  • IntelliJ IDEA(Community版本)本地模式的下载、安装及其使用

    对于初学者来说可以先使用免费的社区版本练练手 ideaIC 2017 3 5 gt 社区版 ideaIU 2017 3 5 gt 旗舰版 一 IntelliJ IDEA Community版本 下载 下载链接 https www jetbr
  • git资料

    IDEA中Git的使用 https www cnblogs com javabg p 8567790 html 如何用git将项目代码上传到github https blog csdn net laozitianxia article de
  • Headless 无法使用 Playwright 和 BeautifulSoup 4 工作

    这段代码正在运行 from playwright sync api import sync playwright from bs4 import BeautifulSoup from datetime import datetime imp
  • 我在使用 PyVirtualDisplay==0.2.5 包运行使用虚拟显示器(无头模式)的测试时遇到问题

    我的测试正在按预期工作和运行PyVirtualDisplay 0 2 1 但我对该软件包的最新版本有疑问 例如 PyVirtualDisplay 0 2 5 我的代码片段 def set up self Creation of instan
  • Ruby/Watir:firefox 无头

    根据这个 https developer mozilla org en US Firefox Headless modefirefox 57 能够以无头模式运行 我尝试将它与此一起使用 omg3r Watir Browser new fir
  • 如何在 Linux 无头服务器上安装 chrome 扩展

    我需要在无头服务器上安装 chrome 扩展 一种方法是使用组策略 我正在寻找其他方法来做到这一点 对于 Firefox 我只需将我的 XPI 扩展 放在配置文件目录 扩展文件夹中 Firefox 就会选择该扩展 我想知道对于 chrome
  • 【神器】wakatime代码时间追踪工具

    文章目录 wakatime简介 支持的IDE 安装步骤 API文档 插件费用 写在最后 wakatime简介 wakatime就是一个IDE插件 一个代码时间追踪工具 可自动获取码编码时长和度量指标 以产
  • 【神器】wakatime代码时间追踪工具

    文章目录 wakatime简介 支持的IDE 安装步骤 API文档 插件费用 写在最后 wakatime简介 wakatime就是一个IDE插件 一个代码时间追踪工具 可自动获取码编码时长和度量指标 以产
  • 使用八度无头

    是否有可能使用 Octave 无头 像这样的东西 octave lt 5 4 gt result txt Using octave silent eval 5 4 gt result txt 你会得到 ans 9 in result txt
  • 以编程方式设置 java.awt.headless=true

    我正在尝试设置java awt headless true在应用程序启动期间 但似乎我来得太晚了 非无头模式已经开始 static System setProperty java awt headless true java awt Gra
  • 在 Eclipse RCP 无头构建中使用 customBuildCallbacks.xml

    我正在尝试将一些自定义构建步骤添加到 Eclipse RCP 应用程序的无头构建过程中 据我了解 推荐的方法是在插件目录中提供 customBuildCallbacks xml 文件 并在 build properties 文件中添加指向该

随机推荐

  • jmeter学习所采的坑

    1 jdk安装是32位与jmeter版本不兼容 jdk安装是32位 jmeter5 4 1 卸载jdk安装64后问题解决 2 jmeter安装后保存不了测试计划 解决方案 各种百度 最后在选项 外观 选择windows 可以保存测试计划 3
  • (代码审计)zzcms存储型XSS

    1 漏洞成因是stripfxg 函数引起的 先来看看这个函数 inc function php function stripfxg string htmlspecialchars decode false nl2br false 去反斜杠
  • flask mvc模式开发_MVC设计模式

    MVC的全名是Model View Controller 是模型 Model 视图 view 控制器 controller 的缩写 是一种设计模式 它是用一种业务逻辑 数据与界面显示分离的方法来组织代码 将众多的业务逻辑聚集到一个部件里面
  • RuntimeError: Error(s) in loading state_dict for BASE_Transformer

    最近跑一个深度学习变化检测的项目BIT CD 严格按照作者的说明页进行训练和测试 但是跑出来的模型就是无法正常工作 而用作者的预训练模型就正常工作 百思不得其解 根据错误 逐步调试 输出 总算是找到了问题的所在 其实这个问题如果对于老手 估
  • 全面解析大语言模型的工作原理

    当ChatGPT在去年秋天推出时 在科技行业乃至世界范围内引起了轰动 当时 机器学习研究人员尝试研发了多年的语言大模型 LLM 但普通大众并未十分关注 也没有意识到它们变得多强大 如今 几乎每个人都听说过LLM 并有数千万人用过它们 但是
  • 3D模型的渲染,这一篇就够了

    3D模型的渲染 这一篇就够了 效果图及源码 1 mapbox 2 threebox tube line logistics raycaster mercator object3D 效果图及源码 1 mapbox https docs map
  • ORACLE(student)表习题与答案

    1 查询Student表中的所有记录的Sname Ssex和Class列 SELECT sname ssex class FROM student 2 查询教师所有的单位即不重复的Depart列 SELECT distinct depart
  • 集中式日志存储架构

    Hello大家好 欢迎回来 我们今天的视频课程要讨论的内容是 AWS的集中式日志存储架构 包括集中式日志存储架构需要考虑的事项 以及使用了两个AWS账户对架构的实现做了个快速的演示 我们开始今天的内容 集中式日志存储架构 当前 在绝大多数组
  • 对话力码科技:保险科技应用有待深入,价值落地更重要

    保险行业的数字化时机已来 更加专业化的企业才能立于不败之地 数科星球原创 作者丨苑晶 编辑丨大兔 对于国内的大多数企业来说 2023年是个极为重要的年份 在软件行业 随着人工智能等新技术的日益成熟和普及 软件行业迎来黄金时代 在这种趋势下
  • 多点双向重发布

    实验题目 要求 1 两个协议间进行多点双向重发布 2 R7的环回没有宣告在OSPF协议中 而且是后期重发布进去 3 解决环路 所有路径选择最优 且存在备份 实验拓扑图 IP地址与ospf和rip的配置 R1 int g0 0 0 ip ad
  • 华为OD机试真题-计算网络信号 【2023.Q1】

    题目内容 网络信号经过传递会逐层衰减 且遇到阻隔物无法直接穿透 在此情况下需要计算某个位置的网络信号值 注意 网络信号可以绕过阻隔物 array m n 的二维数组代表网格地图 array i j 0代表i行j列是空旷位置 array i
  • 开源协议比较:BSD、Apache、GLP、LGLP、MIT

    BSD开源协议 original BSD license FreeBSD license Original BSD license BSD开源协议是一个给于使用者很大自由的协议 基本上使用者可以 为所欲为 可以自由的使用 修改源代码 也可以
  • Python报错UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte的最新解决办法2022-09-30

    合并txt文件内容时候 Python报错UnicodeDecodeError gbk codec can t decode byte 这个错误是做NLP的小伙伴常见的一个错误 报错原因是读取的文件中有中文 网上找到的解决办法 将 with
  • ProtocolBuffers-3.0.0 For Objective C 的快速集成指南

    一 前言 最近调研 Google的Protocol Buffer 在网上看了几篇相关博客 发现他们讲的都比较复杂 所以就想写一篇简单点的文章 配置环境 mac OS 10 11 5 Xcode7 3 二 Protocol Buffer简介
  • 汉诺塔(Tower of Hanoi)--------递归思路

    汉诺塔问题简介 有三根相邻的柱子 标号为A B C A柱子上从下到上按金字塔状叠放着n个不同大小的圆盘 要把所有盘子一个一个移到柱子C上 并且每次移动 同一根柱子上都只能是大盘子在下 小盘子在上 请问至少需要多少次移动 汉诺塔问题分析 1
  • 剑指 Offer 57. 和为s的两个数字--双指针问题

    这道题有点像之前一道用hashmap做的乱序数组求两数之和等于指定数的问题 两数相加 时间复杂度小于 O n2 而今天这道题 用hashmap也可以做出 但是空间复杂度实在太大 又因为它是排序好的数组 所以二分法或者双指针法比较简单 双指针
  • DRF视图组件

    目录 视图 APIView APIView与View的不同之处 GenericAPIView 通用视图类 类属性 类方法 基于APIView写五个接口 基于GenericAPIVIew写5个接口 五个视图扩展类 ListModelMixin
  • c/c++位字段

    位字段 定义 位字段是C语言中一种存储结构 不同于一般结构体的是它在定义成员的时候需要指定成员所占的位数 所有基础的数据类型 最大的也不过 10 个字节 我们可以自定义的数据类型 struct 通过把若干类型组合在一起 让一种类型可以大很多
  • linux自动安装trojan客户端的shell脚本

    bin bash 安装Trojan客户端 echo 开始安装Trojan客户端 curl O https github com trojan gfw trojan releases download v1 17 0 trojan 1 17
  • Headless Browser Testing With Xvfb

    Jan 09 15 javascripttesting These days when the phrase headless browser is mentioned you immediately think of PhantomJS