I have a command-line-only Ubuntu 11.04 (GNU/Linux 2.6.35.4-rscloud x86_64) and I'm working through the Angular Phonecat tutorial which uses the Karma for testing. The Karma browser config page says Chrome launcher is "shipped with Karma by default."
But it's not working for me. This is the karma.conf.js. Below is the output.
$ ./scripts/test.sh
Starting Karma Server (http://karma-runner.github.io)
-------------------------------------------------------------------
INFO [karma]: Karma v0.10.4 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
This answer points out that I need chromium.
So I tried to install Chrome on my Ubuntu with this guide with "download 64 bit version using command line". Everything went well until sudo apt-get -f install
, which ended with a lot of "failed to fetch" from ubuntu IP addresses, such as 91.189.91.15 or 91.189.92.. Even with /usr/bin/googlesomething* that the "Can not find the binary google-chrome" goes away, I still got the "Cannot start Chrome" on the individual test level. Then while trying to fix errors, I deleted /usr/bin/googlesomething.
Currently, I have these node_modules:
angular-phonecat/node_modules$ ls
karma karma-html2js-preprocessor karma-requirejs
karma-chrome-launcher karma-jasmine karma-script-launcher
karma-coffee-preprocessor karma-junit-reporter
karma-firefox-launcher karma-phantomjs-launcher
Q 1: Since my machine has only command-line access, no GUI, is the other Karma launcher, PhantomJS, a better choice than Chrome/Chromium?
Q 2: If I should still use Chrome/Chromium, should I get Chrome or Chromium?
Q 3: Does anyone know what exactly do I need to get google-chrome or chromium for Karma to work in the Angular app?
To launch Chrome from karma, we need to use karma-chrome-launcher. Run the command npm install karma-chrome-launcher --save to install to the application. Add the karma-chrome-launcher plugin to the plugins list in your karma.
You need to run it with singleRun = false in karma. conf. js and then click the button on the top corner that says "DEBUG". Then you should see the output and it won't disappear or close.
Correct - Karma requires a browser to run. BUT - you can run Chrome in Headless mode, which means although you do need the browser installed, it will not open it's UI, and you can therefore run the tests purely through an SSH session for example.
The Headless mode is a feature which allows the execution of a full version of the Chrome Browser. It provides the ability to control Chrome via external programs. The headless mode can run on servers without the need for dedicated display or graphics.
I'll expand on Ludwig's third point for answer seekers and for my own reference in the future...
The first thing you need to do is find where chromium-browser
is installed. Run:
which chromium-browser
This will return the path to the executable, which will look something like this:
/usr/bin/chromium-browser
Then simply set the path:
export CHROME_BIN=/usr/bin/chromium-browser
Now Karma can find the browser it needs to execute your tests (assuming you've decided to use a graphical interface).
google-chrome
and it does not exist. The name of the executable for chrome varies from OS to OS. Therefore you need to set an enviroment variable called CHROME_BIN which has the value of the name of your chrome executable. On my system (Linux desktop 13.10) this is chromium-browser
.My solution is to create an alias in linux to windws's chrome
alias launchchrome="\"/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe\""
and after that export that alias as linux env variable
export CHROME_BIN=launchchrome
That's it, now if you run ng test
your windows chrome will be used! In my particular case this solution worked
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With