简体   繁体   中英

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

> 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 test environment 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 test environment 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM