Running selenium-chromedriver using Protractor on linux

匿名 (未验证) 提交于 2019-12-03 02:16:02

问题:

I am using protractor to run tests against an Angular application. They work on my OSX environment but not on Linux where TeamCity is trying to run it.

When I run this command on my local OSX environment, it works (tested on my co-workers machine, too):

./node_modules/protractor/bin/protractor protractor.conf.js  Using ChromeDriver directly... .. Finished in 5.55 seconds 2 tests, 2 assertions, 0 failures

When I run this on a linux machine, or a TeamCity job tries to run it, it fails:

./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)

Attempts to resolve:

I have looked at this issue, but a standalone webdriver server is no solution.

I looked at this issue but my version of selenium-wedriver is 2.42.1, so, not the same bug.

Versions:

$ 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

Progress Update:

Trying to get the version of chrome-webdriver exposed a problem:

$ ./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

From this I concluded there was a dependency issue and found that Selenium requires Chrome. (more).

I installed Chrome on the Linux box using steps like this:

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

This didn't work exactly like that, but after a few back and forths with dependencies and sudo apt-get install I think I got Chrome installed:

$ google-chrome --version Google Chrome 36.0.1985.143 

This made the chromedriver version work:

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

However, running Protractor still does not work:

$ ./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)

回答1:

You need to be able to run Chrome or Firefox headless and for that you'll need to configure Xvfb among other things, otherwise Chrome will fail to launch without a proper $DISPLAY.

You could also use PhantomJS but, IMHO, what good does that to e2e testing since is not a real browser.

This is what I'm successfully using for continuous testing: https://github.com/elgalu/docker-selenium



回答2:

I had the same problem and it resolved just after installing unity-gtk3-module !!

yum install unity-gtk3-module

Installing:  PackageKit-gtk3-module                                        Updating:                                                           Installing for dependencies:  PackageKit-glib                                                   adwaita-cursor-theme                                            adwaita-icon-theme                                               at-spi2-atk                                                     at-spi2-core                                                     cairo-gobject                                                    colord-libs                                                      gtk3                                                              json-glib                                                         libXevie                                                         libgusb                                                    rest                                                             Updating for dependencies:  glib2

i hope this helps



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!