如何使用无头浏览器在Jenkins中运行量角器测试用例?

如何使用无头浏览器在Jenkins中运行量角器测试用例?

问题描述:

我使用了phantomjs,但是phantom js与量角器的兼容性不好.尽管在chrome和firefox浏览器中我可以找到元素,但是在phantomjs中找不到相同的定位符.

I have used phantomjs but compatibility of phantom js is bad with protractor. Though in chrome and firefox browser I am able to find elements but same locators are not found in phantomjs.

如果您使用的是Linux OS,则可以使用xvfb以无头模式启动chrome浏览器.

If you are using linux OS then you can use xvfb to launch the chrome browser in headless mode.

要安装xvfb,请在终端中运行以下命令

To install xvfb, run the below commands in terminal

sudo apt-get update

sudo apt-get install -y xvfb

一旦安装了xfvb,就可以使用以下命令运行量角器脚本,

Once you install xfvb, you can run your protractor scripts using the below command,

xvfb-run protractor configuration.js

以上命令将以无头模式启动chrome浏览器,并将执行configuration.js文件中提到的所有规范.

The above command will start your chrome browser in headless mode and will execute all specs mentioned in the configuration.js file.