Alojz Janez
Alojz Janez

Reputation: 540

How do I run the angular-phonecat tutorial tests when it is running on a headless server

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

> [email protected] pretest /var/www/angular-phonecat
> npm install


> [email protected] postinstall /var/www/angular-phonecat
> bower install


> [email protected] 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

> [email protected] pretest /var/www/angular-phonecat
> npm install


> [email protected] postinstall /var/www/angular-phonecat
> bower install


> [email protected] 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.

Upvotes: 3

Views: 721

Answers (1)

DanArl
DanArl

Reputation: 1143

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']

Upvotes: 2

Related Questions