在linux上使用量角器运行硒硒

前端之家收集整理的这篇文章主要介绍了在linux上使用量角器运行硒硒前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用量角器对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)

尝试解决

我看过this issue,但一个独立的webdriver服务器是没有解决方案.

我看着this issue,但是我的selenium-wedriver版本是2.42.1,所以不是同一个bug.

版本:

$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 requires Chrome. (more).

我使用steps like this在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安装之后,我想我已经安装了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)

解决方法

您需要能够运行Chrome或Firefox无头,因此您需要配置Xvfb等等,否则如果没有正确的$DISPLAY,Chrome将无法启动.

您也可以使用PhantomJS,但是IMHO,e2e测试的好处并不是真正的浏览器.

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

原文链接:https://www.f2er.com/linux/400285.html

猜你在找的Linux相关文章