3

The angular-phonecat tutorial assumes you are running angular-phonecat on a server that has chrome installed.

After entering npm test the local chrome-browser should open and run the tests continously.

Of course this does not work on my headless server:

/var/www/angular-phonecat$ npm test

> angular-phonecat@0.0.0 pretest /var/www/angular-phonecat
> npm install


> angular-phonecat@0.0.0 postinstall /var/www/angular-phonecat
> bower install


> angular-phonecat@0.0.0 test /var/www/angular-phonecat
> karma start test/karma.conf.js

INFO [karma]: Karma v0.10.10 server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
ERROR [launcher]: Cannot start Chrome
Can not find the binary google-chrome
Please set env variable CHROME_BIN

I would like to do this on a linux machine that is a server and has no X installed.

One way would to tunnel the X session but I'd rather connect the npm testenvironment to my local chrome over http manually.

How would I do this?

I would need to tell npm test that it should not start chrome? I see the server is running on http://localhost:9876/ so I would connect manually.

The angular-phonecat tutorial assumes you are running angular-phonecat on a server that has chrome installed.

After entering npm test the local chrome-browser should open and run the tests continously.

Of course this does not work on my headless server:

/var/www/angular-phonecat$ npm test

> angular-phonecat@0.0.0 pretest /var/www/angular-phonecat
> npm install


> angular-phonecat@0.0.0 postinstall /var/www/angular-phonecat
> bower install


> angular-phonecat@0.0.0 test /var/www/angular-phonecat
> karma start test/karma.conf.js

INFO [karma]: Karma v0.10.10 server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
ERROR [launcher]: Cannot start Chrome
Can not find the binary google-chrome
Please set env variable CHROME_BIN

I would like to do this on a linux machine that is a server and has no X installed.

One way would to tunnel the X session but I'd rather connect the npm testenvironment to my local chrome over http manually.

How would I do this?

I would need to tell npm test that it should not start chrome? I see the server is running on http://localhost:9876/ so I would connect manually.


Edit 1: What i tried was this, create a dummy binary instead of not existing chrome:

/var/www/angular-phonecat$ cat dummy.sh 
#!/bin/sh
read -p "Press enter to terminate ... "  dummy_userinput

... and pass this to the tests:

/var/www/angular-phonecat$ export CHROME_BIN="/var/www/angular-phonecat/dummy.sh" && npm test

It somehow works but the dummy chrome does not give the correct answers I suspect:

INFO [karma]: Karma v0.10.10 server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
INFO [Chrome 34.0.1847 (Windows 7)]: Connected on socket Ri4I_SRpM8UA1q_Kq6V6
WARN [launcher]: Chrome have not captured in 60000 ms, killing.
INFO [launcher]: Trying to start Chrome again.
WARN [launcher]: Chrome have not captured in 60000 ms, killing.
INFO [launcher]: Trying to start Chrome again.
WARN [launcher]: Chrome have not captured in 60000 ms, killing.
Alojz Janez
  • 530
  • 1
  • 3
  • 13
  • @mpm thank you. Is karma-phantomjs an alternative way or is it to go deeper into what angular-phonecat does? I am watching the video right now, so karma-phantomjs uses a real webkit while the angular phonecat karma only unit-tests the javascript using javascript? I am not sure. – Alojz Janez May 14 '14 at 11:28
  • I found the same problem, but I actually installed google-chrome-stable from google's repository on my headless debian installation. I still repeatedly got errors.
    INFO [launcher]: Trying to start Chrome [[again (2/2)]] ERROR [launcher]: Cannot start Chrome ERROR [launcher]: Chrome failed 2 times (cannot start). Giving up. Should we assume that you can't test Angular apps on a headless server? Seems dubious, but I'd love clarification from someone with more experience.
    – mightypile Sep 14 '14 at 17:34

1 Answers1

2

PhantomJS is meant for this purpose. From the PhantomJS website:

One major use case of PhantomJS is headless testing of web applications. It is suitable for general command-line based testing, within a precommit hook, and as part of a continuous integration system.

In your karma-conf.js, set the following:

browsers: ['PhantomJS']
DanArl
  • 1,113
  • 8
  • 10
  • I ran to the same problem, see the detailed answer for the fix: http://stackoverflow.com/questions/39005993/cannot-start-chrome-cannot-start-firefox-errors-with-karma-in-vagrant-box-ubun – Mahshid Zeinaly Aug 17 '16 at 22:33