Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running selenium-chromedriver using Protractor on linux

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)
like image 205
SimplGy Avatar asked Aug 13 '14 19:08

SimplGy


People also ask

How do I start WebDriver in Protractor?

To install and start the standalone Selenium Server manually, use the webdriver-manager command line tool, which comes with Protractor. Run the update command: webdriver-manager update This will install the server and ChromeDriver. Run the start command: webdriver-manager start This will start the server.


1 Answers

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

like image 61
Leo Gallucci Avatar answered Oct 14 '22 10:10

Leo Gallucci