如何使用Xvfb在Firefox上运行Karma? [英] How to run Karma with Firefox using Xvfb?

查看:141
本文介绍了如何使用Xvfb在Firefox上运行Karma?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Xvfb启动Firefox 在无头服务器中运行 Karma .

Karma需要启动器插件才能自动启动和停止浏览器.我找到了 karma-xvfb-chrome-launcher ,但是没有人适合Firefox.

安装Xvfb(Ubuntu)后,我知道可以使用以下命令启动Firefox:

$ xvfb-run firefox <app-under-test-url> 

我不知道如何使Karma这样启动Firefox.

是否可以为Karma提供自定义的启动/停止浏览器脚本?

是否可以通过 Karma.conf.js 来做到这一点?

我该怎么做?

谢谢!

解决方案

您可以使用xvfb-run启动Karma,它启动的任何浏览器都将在新的Xvfb实例中运行.

在我的Makefile中,我有以下命令,该命令在我要运行基于Karma的测试时运行:

xvfb-run karma start --single-run

xvfb-run的运行方式是启动Xvfb实例,获取其显示号并设置DISPLAY环境变量,然后运行您作为参数传递的命令.这意味着通过xvfb-run执行的所有操作(包括从初始位置开始的任何新进程)都使用xvfb-run设置的DISPLAY值,因此将出现在xvfb-run启动的Xvfb实例上. /p>

I want to start Firefox using Xvfb to run Karma in a headless server.

Karma needs a launcher plugin to start and stop browsers automatically. I've found a karma-xvfb-chrome-launcher, but no one for Firefox.

After installing Xvfb (Ubuntu), I know I can start Firefox using the following command:

$ xvfb-run firefox <app-under-test-url> 

What I don't know is how to make Karma start Firefox this way.

Is there a way to provide a custom start/stop browser script to Karma work with?

Is possible to do it via Karma.conf.js?

How can I do that?

Thanks!

解决方案

You can use xvfb-run to start Karma, and any browser it launches will run in a new Xvfb instance.

In a Makefile of mine I have this command which is run when I want to run my Karma-based tests:

xvfb-run karma start --single-run

xvfb-run operates by starting an Xvfb instance, grabbing its display number and setting the DISPLAY environment variable, then it runs the command you passed as argument. This means that everything that is executing through xvfb-run (including any new processes started from the initial one) is using the DISPLAY value that xvfb-run has set and consequently will appear on the Xvfb instance that xvfb-run started.

这篇关于如何使用Xvfb在Firefox上运行Karma?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆