karma-runner / karma-chrome-launcher

A Karma plugin. Launcher for Chrome and Chrome Canary.
MIT License
469 stars 119 forks source link

Headless Chrome times out without executing any tests #154

Open applecool opened 7 years ago

applecool commented 7 years ago

I have configured the headless chrome in my project getting rid of Phantom. When I run the tests on my OSX machine, all the tests get executed with the test runner on the headless chrome. But the same doesn't happen on my linux server. It connects to the socket and then after some time, it disconnects and shows the error message saying "Karma tests failed". Error:

25 09 2017 13:56:19.075:INFO [karma]: Karma v1.5.0 server started at http://0.0.0.0:9876/build/
25 09 2017 13:56:19.076:INFO [launcher]: Launching browser ChromeHeadless with unlimited concurrency
25 09 2017 13:56:19.080:INFO [launcher]: Starting browser Chrome
25 09 2017 13:56:19.263:INFO [HeadlessChrome 0.0.0 (Linux 0.0.0)]: Connected on socket zDM7md2A7Je8kqsPAAAA with id 1679961
25 09 2017 13:58:19.552:WARN [HeadlessChrome 0.0.0 (Linux 0.0.0)]: Disconnected (1 times), because no message in 120000 ms.
HeadlessChrome 0.0.0 (Linux 0.0.0) ERROR
  Disconnected, because no message in 120000 ms.

Here is my configuration:

const ChromiumRevision = require('puppeteer/package.json').puppeteer.chromium_revision;
const Downloader = require('puppeteer/utils/ChromiumDownloader');
const revisionInfo = Downloader.revisionInfo(Downloader.currentPlatform(), ChromiumRevision);

process.env.CHROME_BIN = revisionInfo.executablePath;
module.exports = function (config) {
    config.set({
        basePath: 'build/',
        frameworks: ['jasmine'],
        plugins: [
            require('karma-jasmine'),
            require('karma-chrome-launcher'),
        ],
        files: ['tests.js'],
        customLaunchers: {
            'ChromeHeadless': {
                base: 'Chrome',
                flags: [
                    '--headless',
                    '--disable-gpu',
                    // Without a remote debugging port, Google Chrome exits immediately.
                    '--remote-debugging-port=9222'
                ],
                debug: true
            }
        },
        autoWatch: false,
        browsers: ['ChromeHeadless'],
        singleRun: true,
        browserNoActivityTimeout: 120000,
        urlRoot: '/build/'
    })
}

Using karma-chrome-launcher: "2.1.1". Tried with the latest 2.2.0 version too. Tried with karma: "1.5.0", "1.6.0", and the latest "1.7.1".

I tried other flags like "--no-sandbox", "--disable-web-security" as suggested on a bunch of issues on karma repo. But still no luck. Is there a fix or workaround for this issue? Is there a reason why it's not working on the Linux server [Ubuntu Server 14.04.5 LTS].

vargarobert commented 7 years ago

Can someone address this please. I've tried so many karma configurations, using different package versions etc to make it work, but still no luck.

ghost commented 7 years ago

The way that you define CHROME_BIN has been updated in recent version (see the readme for more details). It is now:

process.env.CHROME_BIN = require('puppeteer').executablePath();
vargarobert commented 7 years ago

@saimaheshgaya this basically reaches the same result

ghost commented 7 years ago

try npm install && npm rebuild && npm test This worked for me

Also adding --no-sandbox to the flag list helps

applecool commented 7 years ago

@saimaheshgaya That is not going to resolve the issue. If you increase the timeout to x, it times out after those x ms.

andrewl-telnyx commented 7 years ago

npm install && npm rebuild && npm test

const process = require('process');
process.env.CHROME_BIN = require('puppeteer').executablePath();

//later:
 browsers: ['HeadlessChrome'],
    customLaunchers:{
      HeadlessChrome:{
        base: 'ChromeHeadless',
        flags: ['--no-sandbox']
      }
    },

appears to have worked for us.

ghost commented 7 years ago

npm rebuild is the key if you are switching platform. It recompiles the C++ addons for Node JS.

vargarobert commented 7 years ago

Still no luck here.

applecool commented 7 years ago

Same here! Hey @vargarobert I have posted the issue on the puppeteer's repo and they closed mine asking me to remove karma and try it out. I have to do that. Link here. Maybe try that out.

vargarobert commented 7 years ago

@applecool Pupetteer works as expected, just tried it out. It must be something related to karma-chrome-launcher not launching the headless browser.

applecool commented 7 years ago

@vargarobert That's cool. So, its clearly a problem with the karma-chrome-launcher then. I hope this problem gets the attention to the dev's on the team.

kumvem commented 7 years ago

@applecool The launcher is starting incorrect browser "Starting browser Chrome". it should launch "ChromeHeadless" Check my log below (mine is OSX as well, not Linux). When logs start flushing from HeadlessChrome 0.0.0 Google chromeheadless stated its execution, means Karma-chrome-launcher is fine. Did you report this to google chrome headless?

@applecool @vargarobert Puppeteer is not mandatory for ChromeHeadless browser in Karma. I can successfully run my tests without puppeteer.

package.json "karma": "^1.7.1", "karma-chrome-launcher": "^2.2.0",

my karma.conf.js starts with module.exports = function (config) { config.set({

My browser in karma.conf.js browsers: ['ChromeHeadless']

Im not using any custom launcher configurations. All options you have given are handled by karma-chrome-launcher line 168 in "node_modules/karma-chrome-launcher/index.js"

This is my log. [exec] Running "karma:unit" (karma) task [exec] 09 10 2017 22:52:13.282:INFO [karma]: Karma v1.7.1 server started at http://0.0.0.0:8090/ [exec] 09 10 2017 22:52:13.283:INFO [launcher]: Launching browser ChromeHeadless with unlimited concurrency [exec] 09 10 2017 22:52:13.289:INFO [launcher]: Custom Starting browser ChromeHeadless [exec] 09 10 2017 22:52:13.639:INFO [HeadlessChrome 0.0.0 (Mac OS X 10.12.6)]: Connected on socket D6nT8-N4aXCaoUpKAAAA with id 86242225

applecool commented 7 years ago

Thanks a lot @kumvem for the information. Yes, I did report it on the puppeteer.

I didn't had any problems on OSX either. And the log which I shared is from the linux execution not OSX. Thanks for pointing this out: Starting browser Chrome. I am not sure why that's getting showed up. I just tried to run the tests on OSX and in the logs, after ChromeHeadless is launched, It says the same Starting browser Chrome. Here's the latest log on OSX:

11 10 2017 09:44:41.589:INFO [karma]: Karma v1.6.0 server started at http://0.0.0.0:9876/build/
11 10 2017 09:44:41.590:INFO [launcher]: Launching browser ChromeHeadless with unlimited concurrency
11 10 2017 09:44:41.595:INFO [launcher]: Starting browser Chrome
11 10 2017 09:44:41.919:INFO [HeadlessChrome 0.0.0 (Mac OS X 10.12.6)]: Connected on socket hyN1lr9EWJpmp63QAAAA with id 5427296
HeadlessChrome 0.0.0 (Mac OS X 10.12.6): Executed 1 of 202 SUCCESS (0 secs / 0.004 secs)

I am completely confused with that log. Nevertheless, all the tests execute successfully.

You have mentioned that you aren't using puppeteer and still be able to execute the tests with the chrome headless. So, I am assuming you installed Chrome GUI on your machine which is being launched by the karma-chrome-launcher with the headless flag (which presumably should be mentioned in the customLaunchers property). Is that right? And, in your provided config, I don't see the customLaunchers property. Could you please share that too.

I will try to run the tests with ChromeHeadless without the puppeteer and see what's going on.

Thank you again.

applecool commented 7 years ago

@kumvem I removed puppeteer, and also the customLaunchers property in the config. As the base property in the customLaunchers was assigned to Chrome, the Starting browser Chrome was logged. This is my latest config and the log:

module.exports = function (config) {
    config.set({
        basePath: 'build/',
        frameworks: ['jasmine'],
        plugins: [
            require('karma-jasmine'),
            require('karma-chrome-launcher'),
        ],
        files: ['tests.js'],
        autoWatch: false,
        browsers: ['ChromeHeadless'],
        singleRun: true,
        browserNoActivityTimeout: 120000,
        urlRoot: '/build/'
    })
}

Log on OSX:

11 10 2017 10:03:03.895:INFO [karma]: Karma v1.7.1 server started at http://0.0.0.0:9876/build/
11 10 2017 10:03:03.896:INFO [launcher]: Launching browser ChromeHeadless with unlimited concurrency
11 10 2017 10:03:03.900:INFO [launcher]: Starting browser ChromeHeadless
11 10 2017 10:03:04.165:INFO [HeadlessChrome 0.0.0 (Mac OS X 10.12.6)]: Connected on socket PiVHGIQOtKEzQkEFAAAA with id 85884203
HeadlessChrome 0.0.0 (Mac OS X 10.12.6): Executed 1 of 202 SUCCESS (0 secs / 0.003 secs)

Successfully runs on OSX and executes the tests without Puppeteer. No, flags, nothing. Works out of the box with just the browser set to ChromeHeadless.

Same config, Log when running on Linux Server:

11 10 2017 10:10:37.190:INFO [karma]: Karma v1.7.1 server started at http://0.0.0.0:9876/build/
11 10 2017 10:10:37.191:INFO [launcher]: Launching browser ChromeHeadless with unlimited concurrency
11 10 2017 10:10:37.196:INFO [launcher]: Starting browser ChromeHeadless
11 10 2017 10:10:37.946:INFO [HeadlessChrome 0.0.0 (Linux 0.0.0)]: Connected on socket 8VVqH7pkzV8Pk3kEAAAA with id 14558080
11 10 2017 10:12:38.264:WARN [HeadlessChrome 0.0.0 (Linux 0.0.0)]: Disconnected (1 times), because no message in 120000 ms.
  HeadlessChrome 0.0.0 (Linux 0.0.0) ERROR
  Disconnected, because no message in 120000 ms.
[10:12:38] 'test' errored after 2.03 min
[10:12:38] Error: Karma tests failed

😞

applecool commented 7 years ago

@vargarobert any luck?

vargarobert commented 7 years ago

I've tried numerous combinations on different platforms. It works fine on my mac, as it does with yours because you have Chrome installed. However, not on linux (teamcity CI for example). On Mac you can also notice the icon showing up in your dock for a few seconds even though the window doesn't actually show up.

I would like to be able to run it independently of the Chrome GUI installed (just like phantomJS, slient). You download a binary for your platform and run heedlessly. Simple - to work in any environment.

Here is where the problems start to appear. You set CHROME_BIN or CHROMIUM_BIN to your local chromium binary or puppeteer chromium binary and it doesn't lunch (not even when you use ChromiumHeadless, regardless of the platform and browser configuration - I've tried all of them).

We should try to get an actual chrome binary from somewhere and try it out. Like I said so far I've used puppeteer and local binary (downloaded from https://www.chromium.org/getting-involved/download-chromium)

applecool commented 7 years ago

Thanks for sharing the info @vargarobert I wish it was as simple as Phantom JS though.

kumvem commented 7 years ago

@applecool I got timeout issue in Mac as well. I added 'captureTimeout' in karma.conf.js to solve the issue. On my Linux box upgraded NPM and Node to latest version to solve the issue as puppeteer need node 6+

applecool commented 7 years ago

@kumvem I didn't get the timeout issue on Mac at all. seems like you misunderstood. I am getting timeout problem when executing on linux box.

michaelkrone commented 7 years ago

@applecool We got the same problem: locally the tests run, on the Linux CI, chrome timed out randomly. Increasing the browserNoActivityTimeout in the karma.conf to a very high value (in our case 60000) did the trick.

applecool commented 7 years ago

@michaelkrone I already have 120000ms. I re-tried it with much higher value of 3 and 5 minutes too. It's still the same. It just times out. And I have also tried on the Linux GUI (Ubuntu Desktop 16.0.4 LTS). Still the same. Doesn't work with ChromeHeadless. It's so annoying 😞

reduckted commented 7 years ago

The workaround posted by @andrewl-telnyx appears to be working for me. I'm not using puppeteer. All I had to do was add this to my config:

browsers: ['HeadlessChrome'],
customLaunchers:{
    HeadlessChrome:{
        base: 'ChromeHeadless',
        flags: ['--no-sandbox']
    }
}

It always timed out when using ChromeHeadless as the browser, and always succeeds when using the custom HeadlessChrome. Now I just have to work out what the ramifications are for using --no-sandbox.

Edit: I may have spoken too soon. It's also timing out, but does occasionally succeed. 😢

applecool commented 7 years ago

@reduckted Which OS are you on? Linux or OSX?

reduckted commented 7 years ago

Sorry, should have mentioned that. I'm actually on Windows 10.

neutraali commented 6 years ago

@applecool FWIW we have a working Linux Mint (Ubuntu) and Alpine config using puppeteer, which I'll post here if it might help at all. This assumes that you have CHROME_BIN set with puppeteer:

process.env.CHROME_BIN = puppeteer.executablePath();

... And then as to the actual Karma config:

var KarmaConfig = {
. . .
browsers: ['ChromeHeadlessCustom'],
plugins: 'karma-chrome-launcher',
customLaunchers: {
    'ChromeHeadlessCustom': {
        base: 'ChromiumHeadless'
        flags: [
            '--no-sandbox',
            '--headless',
            '--disable-gpu',
            '--disable-translate',
            '--disable-extensions'
        ]
    }
}

This is done using:

"karma": "1.7.1",
"karma-chrome-launcher": "2.2.0",
"puppeteer": "0.13.0"

... Our problem is the reverse. We can't get ChromeHeadlessCustom to work on OSX. Same timeout problem ... :)

UPDATE: We also got it working on mac by switching the base to ChromeHeadless instead of ChromiumHeadless (when running the tests on OSX).

corsen2000 commented 6 years ago

Having the same issue on Windows 7 ChromeHeadless have not captured in 60000 ms, killing..

I've tried all of the flags listed in this issue, but non help it connect. Task manager shows that Chromium is running, but for some reason it is not connecting to karma.

Non headless chrome works fine.

bas-l commented 6 years ago

UPDATE: My issue was solved using the answer mentioned here https://github.com/karma-runner/karma/issues/2652#issuecomment-335599121

I have the same issue on Windows 7. Tried with all flags and also with the custom launcher. No luck.

    [36m08 01 2018 12:21:08.480:DEBUG [config]: autoWatch set to false, because of singleRun
    [36m08 01 2018 12:21:08.483:DEBUG [plugin]: Loading inlined plugin (defining framework:jasmine).
    [36m08 01 2018 12:21:08.483:DEBUG [plugin]: Loading inlined plugin (defining launcher:Chrome, launcher:ChromeHeadless, launcher:ChromeCanary, launcher:ChromeCanaryHeadless, launcher:Chromium, launcher:ChromiumHeadless, launcher:Dartium, test).
    [36m08 01 2018 12:21:08.483:DEBUG [plugin]: Loading inlined plugin (defining reporter:junit).
    [36m08 01 2018 12:21:08.483:DEBUG [plugin]: Loading inlined plugin (defining reporter:coverage-istanbul).
    [36m08 01 2018 12:21:08.483:DEBUG [plugin]: Loading inlined plugin (defining framework:@angular/cli, preprocessor:@angular/cli, reporter:@angular/cli, middleware:angularCliBlocker).
    [36m08 01 2018 12:21:08.483:DEBUG [plugin]: Loading inlined plugin (defining launcher:MyHeadlessChrome).
    [36m08 01 2018 12:21:08.640:DEBUG [web-server]: Instantiating middleware
    [36m08 01 2018 12:21:08.641:DEBUG [reporter]: Trying to load reporter: @angular/cli
    [36m08 01 2018 12:21:08.642:DEBUG [reporter]: Trying to load color-version of reporter: @angular/cli (@angular/cli_color)
    [36m08 01 2018 12:21:08.642:DEBUG [reporter]: Couldn't load color-version.
    [36m08 01 2018 12:21:08.653:DEBUG [reporter]: Trying to load reporter: junit
    [36m08 01 2018 12:21:08.654:DEBUG [reporter]: Trying to load color-version of reporter: junit (junit_color)
    [36m08 01 2018 12:21:08.654:DEBUG [reporter]: Couldn't load color-version.
    [32m08 01 2018 12:21:13.741:INFO [karma]: Karma v1.7.1 server started at http://0.0.0.0:9876/
    [32m08 01 2018 12:21:13.742:INFO [launcher]: Launching browser MyHeadlessChrome with unlimited concurrency
    [32m08 01 2018 12:21:13.748:INFO [launcher]: Starting browser Chrome
    [36m08 01 2018 12:21:13.748:DEBUG [temp-dir]: Creating temp dir at C:\Users\BAS~1.LUK\AppData\Local\Temp\karma-40242111
    [36m08 01 2018 12:21:13.749:DEBUG [launcher]: C:\Program Files (x86)\Google\Chrome\Application\chrome --user-data-dir=C:\Users\BAS~1.LUK\AppData\Local\Temp\karma-40242111 --no-default-browser-check --no-first-run --disable-default-apps --disable-popup-blocking --disable-translate --disable-background-timer-throttling --disable-renderer-backgrounding --disable-device-discovery-notifications --headless --disable-gpu  --remote-debugging-port=9222 --enable-logging --v=1 --no-sandbox --disable-web-security --disable-setuid-sandbox http://localhost:9876/?id=40242111
    [36m08 01 2018 12:21:23.995:DEBUG [web-server]: serving: C:\repo\nano\app\node_modules\karma\static/client.html
    [36m08 01 2018 12:21:28.502:DEBUG [web-server]: serving: C:\repo\nano\app\node_modules\karma\static/karma.js
    [36m08 01 2018 12:21:30.781:DEBUG [karma]: A browser has connected on socket J4snil3YHSxA4W_rAAAA
    [36m08 01 2018 12:21:33.465:DEBUG [karma]: A browser has connected on socket Nnd2FegD0gKJcjhbAAAB
    [36m08 01 2018 12:21:40.893:DEBUG [karma]: A browser has connected on socket 64QidqbZxK5TQnmCAAAC
    [36m08 01 2018 12:21:42.832:DEBUG [karma]: A browser has connected on socket NZiimJP4jpkHRFMMAAAD
    [36m08 01 2018 12:21:48.757:DEBUG [karma]: A browser has connected on socket GQL7_8T7X3cong11AAAE
    [36m08 01 2018 12:22:01.865:DEBUG [karma]: A browser has connected on socket vBzAg2xKLlqHml40AAAF
    [36m08 01 2018 12:22:08.319:DEBUG [karma]: A browser has connected on socket qJqcGZVouDEe0Ci7AAAG
    [33m08 01 2018 12:22:13.756:WARN [launcher]: Chrome have not captured in 60000 ms, killing.
    [36m08 01 2018 12:22:13.765:DEBUG [launcher]: Process Chrome exited with code 0
    [36m08 01 2018 12:22:13.766:DEBUG [temp-dir]: Cleaning temp dir C:\Users\BAS~1.LUK\AppData\Local\Temp\karma-40242111
bennypowers commented 6 years ago

Posting for posterity. I had this same issue with a project dependent on Karma 1.7.0, so I switched from ChromeHeadless to Chrome and noticed that the test runner launched Chrome to another local project running it's own local webserver running on the same port Karma expected (8080). After killing the unrelated local dev server that was running on 8080, and switching back to ChromeHeadless, everything was fine.

tl;dr: make sure you kill any servers running locally on your karma server's port (usually 8080)

eppsilon commented 6 years ago

Recently Karma became much less reliable for my team's project. I recently rebuilt the Docker image for our build agents, and I think it picked up a newer version of Chrome along the way. I noticed that karma-chrome-launcher passes --disable-gpu even though that is only recommended for running headless Chrome on Windows. So I tried adding --enable-gpu to counteract that, and so far it appears to be working.

Current Chrome version: 63.0.3239.132

Custom launcher:

ChromeHeadlessNoSandbox: {
  base: 'ChromeHeadless',
  flags: [
    '--no-sandbox', // required to run without privileges in Docker
    '--disable-web-security',
    '--enable-gpu'
  ]
}
applecool commented 6 years ago

To all, when you run the tests on a linux machine, what version number do you see? I always see this: HeadlessChrome 0.0.0 (Linux 0.0.0) Does anyone see the same 0.0.0 version number?

Update on the tests on Headless: I tried all the above suggestions in my project and sadly I am still unable to run the tests on a linux server. I tried tweaking the main.js from karma node modules as suggested here on this thread which worked for a bunch of people. You can take a look at it, maybe it might be helpful for you who are still searching for a solution. For some reason, I strongly believe that the issue is caused because of the SSL certificates on my end (esp. on linux) which is not yet supported by Chrome Headless yet. acceptInsecureCerts is the flag which they are going to introduce. It will be out soon as a part of Chrome 66 release according to the issue tracker here. As of now, I couldn't test that out because Chrome Canary builds are not available for Linux. I did try running the tests on the Chrome latest unstable dev build which is 65.0.3322.3 which didn't give me any fruitful results.

If anyone has any other suggestions for fixes, please do comment here. It is very valuable if it helps at least one of us who is looking for a solution :)

applecool commented 6 years ago

Another update: I did get rid of the SSL certificate error by installing/importing a proper certificate and still no luck. So, the SSL certificate error has nothing to do with the headless chrome timing out.

reduckted commented 6 years ago

I did some investigation into this not so long ago and came to the conclusion that the cause of this bug is a mystery. Here's what I discovered:

  1. Chrome was able to connect to the server via the web socket.
  2. The server (upon receiving a "connection" event) was able to send an "execute" message to Chrome (via the web socket) telling it to start the tests.
  3. Chrome successfully receives the "execute" message and navigates to the context.html page.
  4. Once at the context.html page, Chrome makes requests for the script files (the files listed in the files property of the config.

This is where it gets interesting. When these timeout occurs, some of these scripts are loaded successfully, while others fail. For example, it would successfully load the first three script files, but "hang" on the fourth script file.

I could see that Chrome requested the file from the server. I could see that the server sent a response. But Chrome never finished loading the script. I have no idea why. 😕

I made Chrome write console output to stdout. There were no errors (or any sort of messages) printed about why the script failed to load, but I could see other console.log statements that I had added to context.html.

Chris2011 commented 6 years ago

I have the same problem, but after I added this line to my karma.conf: process.env.CHROME_BIN = require('puppeteer').executablePath;

It is an angular-cli based project. When I remove this line, everything works fine, LOCAL, with ChromeHeadless. When I push my code and GitlabCI will execute the tests it says that I need CHROME_BIN, that's why I added this line.

Adding this line got the same problem with No captured browser and timeout on local and the docker image, which was created from GitlabCI.

I'm on Windows 10.

Chris2011 commented 6 years ago

Tried a lot of things, but couldn't find a solution, for executing the tests on remote (GitlabCI). When I run them locally, everything is fine, w/o using the line, which I mentioned above.

eppsilon commented 6 years ago

FWIW, the combination of the custom launcher I posted earlier and a patch to increase the socket connect timeout has fixed the issue for my team.

Here is the patch:

--- node_modules/karma/client/main.js   2017-05-02 02:29:20.000000000 -0700
+++ node_modules/karma/client/main-new.js   2018-01-29 15:40:47.000000000 -0700
@@ -14,7 +14,7 @@
 var socket = io(location.host, {
   reconnectionDelay: 500,
   reconnectionDelayMax: Infinity,
-  timeout: 2000,
+  timeout: 20000,
   path: KARMA_PROXY_PATH + KARMA_URL_ROOT.substr(1) + 'socket.io',
   'sync disconnect on unload': true
 })

To apply it, run patch -f node_modules/karma/client/main.js karma.patch. Note: the patch works for Karma 2.0.x, but the socket code is in a different file in older versions.

Pro7ect commented 6 years ago

Same issue here. I have two machines with Windows 7 on both of them. On one of them everything works fine, but on the other Chrome headless just doesn't open. But if I just open a tab with a corresponding port in Chrome - tests work, but it's not a headless Chrome now, obviously.

My config is the same as authors:

customLaunchers: { // ChromeHeadless - version 60 and above CH: { base: 'Chrome', flags: [ '--headless', '--disable-gpu', // Without a remote debugging port, Google Chrome exits immediately. '--remote-debugging-port=9222' ] },

mboughaba commented 6 years ago

Someone managed to solve this random issue?

Chido42 commented 6 years ago

@Pro7ect As we had exactly the same issue (working on some machine but not on the other). For us it was due to virtual box being installed on one of the machine but not the second one.

For more details: https://github.com/karma-runner/karma/issues/2652#issuecomment-376866611

Hope this helps

ryanki1 commented 6 years ago

Seems to be random - just replaced phantomjs-launcher with chromeheadless in my ionic3 project and ran it: first time tests complete successfully in half a second, second time tests fail (expected result having introduced a bug intentionally) third time timeout fourth time timeout fifth time tests complete successfully (having removed the bug)

ryanki1 commented 6 years ago

@eppsilon Setting the --enable-gpu:true didn't help in my case running on Ubuntu 16.04 :-( I wasn't able so far to change the Karma timeout which relates to part 2 of your solution.

severila commented 6 years ago

I had the same problem trying to run on the Gitlab CI Runner with alpine 8.9

I could not get it running using puppeteer. There is a alpine distrubution which comes with chromium (https://hub.docker.com/r/rastasheep/alpine-node-chromium/) but the current build for alpine-8 fails. In the end, I manually installed Chromium for the Gitlab Runner using:

- apk add --update --no-cache gifsicle ttf-freefont optipng libjpeg-turbo-utils udev chromium
- export CHROME_BIN=/usr/bin/chromium-browser
- export LIGHTHOUSE_CHROMIUM_PATH=/usr/bin/chromium-browser

and used following karma config:

browsers: ['ChromeHeadlessCustom'],
    customLaunchers: {
      ChromeHeadlessCustom: {
        base: 'ChromiumHeadless',
        flags: [
          '--no-sandbox',
          '--headless',
          '--disable-gpu',
          '--disable-translate',
          '--disable-extensions'
        ]
      }
    }

Maybe this helps somebody out.

Chris2011 commented 6 years ago

@severila yes, this solved the problem for me too, but I have now 2 configurations. Only to let you know. One for local und one for gitlab. For local I can still use the default behaviour.

abhaypuranik commented 6 years ago

Hi,

Can you guys please suggest me something here. I am not able to get jasmine karma test suite run in docker. I have tried with Puppeteer and without Puppeteer. I have tried on node-alpine base image and debian as well. Have tried installing various libs specific to each flavor as Puppeteer has problem with the OS level dependencies.

I have tried variety of approaches and spent lot of time making this run. But no luck yet.

All latest versions - node 9, "puppeteer": "^1.4.0", "karma": "~2.0.0", "karma-chrome-launcher": "^2.2.0", "karma-coverage-istanbul-reporter": "^1.2.1", "karma-jasmine": "~1.1.0", "karma-jasmine-html-reporter": "^0.2.2", "karma-junit-reporter": "^1.2.0",

Basically, I am trying to build the docker container from Jenkinsfile , I want this conatiner just to have the browser installed, so that I run npm test from jenkinsfile while running this container. Capture the junit test results in xml and show it as report in jenkins build.

Any github url where this sort of project is implemented or any other pointers you guys have, please suggest. Want to take a look at their Dockerfile, karma.config.js, Jenkinsfile.

Thank you in advance.

-Abhay

vlodko commented 6 years ago

this worked for me on build server:

  1. install puppeteer

  2. add this line to karma conf at the top: process.env.CHROME_BIN = require('puppeteer').executablePath();

  3. add this block to karma conf:

    browsers: ['Chrome'],
    browserDisconnectTimeout: 10000,
    browserDisconnectTolerance: 3,
    browserNoActivityTimeout: 60000,
    flags: [
      '--disable-web-security',
      '--disable-gpu',
      '--no-sandbox'
    ]
heeeman commented 6 years ago

The warning

02 07 2018 14:59:31.441:WARN [launcher]: ChromeHeadless have not captured in 210000 ms, killing.

is a little bit confusing. It also generted by karma in case of chrome binary is not found and the env var 'CHROME_BIN' is set (but wrong).

be sure 'CHROME_BIN' is needed ( karma checks the default install path of chrome) or correctly set.

vlodko commented 6 years ago

@heeeman please see my updated comment above

ladariha commented 6 years ago

I apologize in advance for posting "unrelated" comment, but after 2 days of fighting the combination of karma/docker/Chrome, I feel like it might be useful for someone...

In my case the "not captured, killing" was caused by corporate proxy as when Chrome was started by Karma, instead of loading localhost:9876 , it was "forwarded" by the proxy server to different address. So in my case I had to add --no-proxy-server to flags in karma.conf.js and also unset env var before running Karma (setting the flag alone was not enough)

SUAWAL commented 6 years ago

@ladariha can u please put your karma.conf.js contents here and tell me how to unset the env var? I'm new in karma and i have the same problem.

ladariha commented 6 years ago

Basically I have this in karma.conf.js

        browserDisconnectTimeout: 10000,
        autoWatch: true,
        browsers: ["ChromeHeadless2"],
        customLaunchers: {
            ChromeHeadless2: {
                base: "ChromeHeadless",
                flags: [
                    "--disable-setuid-sandbox",
                    "--no-sandbox", // required to run without privileges in docker
                    "--user-data-dir=/tmp/chrome-test-profile",
                    "--disable-web-security",
                    "--no-proxy-server",
                    "--enable-logging",
                    "--v=1"
                ]
            }
        },

the last 2 flags are for logging so you might not need them. Since I'm running karma via Grunt and Grunt from shell, I'm just calling unset http_proxy && grunt karma...

SUAWAL commented 6 years ago

Thanks a lot