一尘不染

在Linux上使用Protractor运行selenium-chromedriver

selenium

我正在使用量角器针对Angular应用程序运行测试。它们可以在我的OSX环境上工作,但不能在TeamCity试图运行它的Linux上工作。

当我在本地OSX环境上运行此命令时,它可以工作(也在我的同事计算机上进行了测试):

./node_modules/protractor/bin/protractor protractor.conf.js

Using ChromeDriver directly...
..
Finished in 5.55 seconds
2 tests, 2 assertions, 0 failures

当我在Linux机器上运行此程序时,或者TeamCity作业尝试运行它时,它失败了:

./node_modules/protractor/bin/protractor protractor.conf.js

Using ChromeDriver directly...

/usr/share/TeamCity/buildAgent/work/57bd89f9c9abb5d5/webapp/node_modules/protractor/node_modules/selenium-webdriver/http/util.js:87
          Error('Timed out waiting for the WebDriver server at ' + url));
          ^
Error: Timed out waiting for the WebDriver server at http://127.0.0.1:52959/
    at Error (<anonymous>)
    at onResponse (/usr/share/TeamCity/buildAgent/work/57bd89f9c9abb5d5/webapp/node_modules/protractor/node_modules/selenium-webdriver/http/util.js:87:11)
    at /usr/share/TeamCity/buildAgent/work/57bd89f9c9abb5d5/webapp/node_modules/protractor/node_modules/selenium-webdriver/http/util.js:42:21
    at /usr/share/TeamCity/buildAgent/work/57bd89f9c9abb5d5/webapp/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/http/http.js:96:5
    at ClientRequest.<anonymous> (/usr/share/TeamCity/buildAgent/work/57bd89f9c9abb5d5/webapp/node_modules/protractor/node_modules/selenium-webdriver/http/index.js:136:7)
    at ClientRequest.EventEmitter.emit (events.js:95:17)
    at Socket.socketErrorListener (http.js:1547:9)
    at Socket.EventEmitter.emit (events.js:95:17)
    at net.js:440:14
    at process._tickCallback (node.js:415:13)
==== async task ====
WebDriver.createSession()
    at Function.webdriver.WebDriver.acquireSession_ (/usr/share/TeamCity/buildAgent/work/57bd89f9c9abb5d5/webapp/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:131:49)
    at Function.webdriver.WebDriver.createSession (/usr/share/TeamCity/buildAgent/work/57bd89f9c9abb5d5/webapp/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:111:30)

尝试解决:

我已经看过这个问题,但是独立的webdriver服务器无法解决。

我看了这个问题,但是我的selenium-wedriver版本是2.42.1,所以不是相同的错误。

版本:

$ node --version
v0.10.26

$ ./node_modules/protractor/bin/protractor --version
Version 1.0.0

$ uname -mrs
Linux 3.11.0-15-generic x86_64

进度更新:

尝试获取chrome-webdriver暴露问题的版本:

$ ./node_modules/protractor/selenium/chromedriver --version
./node_modules/protractor/selenium/chromedriver: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory

据此,我得出了一个依赖性问题,并发现Selenium需要Chrome(更多)

我使用以下步骤在Linux机器上安装了Chrome :

sudo apt-get install libxss1 libappindicator1 libindicator7
sudo wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome*.deb

这不是完全一样的,但是经过几次来回依赖后,sudo apt-get install我认为我安装了Chrome:

$ google-chrome --version
Google Chrome 36.0.1985.143

这使得chromedriver版本可以正常工作:

$ ./node_modules/protractor/selenium/chromedriver --version
ChromeDriver 2.10.267518

但是,运行量角器仍然不起作用:

$ ./node_modules/protractor/bin/protractor protractor.conf.js
Using ChromeDriver directly...

/usr/share/TeamCity/buildAgent/work/57bd89f9c9abb5d5/webapp/node_modules/protractor/node_modules/selenium-webdriver/lib/atoms/error.js:109
  var template = new Error(this.message);
                 ^
UnknownError: unknown error: Chrome failed to start: exited abnormally
  (Driver info: chromedriver=2.10.267518,platform=Linux 3.11.0-15-generic x86_64)
    at new bot.Error (/usr/share/TeamCity/buildAgent/work/57bd89f9c9abb5d5/webapp/node_modules/protractor/node_modules/selenium-webdriver/lib/atoms/error.js:109:18)
    at Object.bot.response.checkResponse (/usr/share/TeamCity/buildAgent/work/57bd89f9c9abb5d5/webapp/node_modules/protractor/node_modules/selenium-webdriver/lib/atoms/response.js:106:9)

阅读 321

收藏
2020-06-26

共1个答案

一尘不染

您需要能够无头运行Chrome或Firefox,为此,您需要配置Xvfb,否则,如果没有适当的$ DISPLAY,Chrome将无法启动。

您也可以使用PhantomJS,但是恕我直言,由于e2e测试不是真正的浏览器,因此对e2e测试有什么好处。

这是我成功用于连续测试的内容:https :
//github.com/elgalu/docker-selenium

2020-06-26