Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Karma customLauncher configuration for Chrome/Chromium

I have configured Karma to use Chrome for its test:

browsers: [ 'Chrome' ];

each time I run Karma it starts Chromium in some kind of default configuration which has hardware acceleration enabled.

Hardware acceleration has some issues on my system and makes the browser rather unuseable so I would like it to be switched off by default. I have tried to turn it off in the settings, but my changes are not persistent and every time I restart Karma or the Browser the hardware acceleration is enabled again.

Is there any way I can create a customLauncher configuration for Chrome where I am able to deactivate hardware acceleration?

On a side note it would also be nice if I could use Google Chrome instead of Chromium, it seems that Karma always prefers Chromium if it's installed on the system.

I have tried to create the following customLaunchers configuration, but it fails to load with an error:

customLaunchers: {
    Chrome_Persistent: {
        base: 'Chrome',
        chromeDataDir: path.resolve('.chrome')
    }
}

The error is:

ERROR [config]: Error in config file! [ReferenceError: path is not defined] ReferenceError: path is not defined

like image 953
lanoxx Avatar asked Sep 20 '25 14:09

lanoxx


1 Answers

You are asking two questions.

For your main question, Chrome and Chromium have a number of switches/flags that you can use when starting the application. You can add those when defining a custom launcher:

customLaunchers: {
  chrome_sans_ha: { //give it whatever name you want
    base: 'Chrome',
    flags: ['--disable-gpu',
            '--disable-accelerated-video-decode',
            '--disable-accelerated-mjpeg-decode']
  },

I think you'll only need the first flag. A list of possible flags can be found here.

For invoking Chrome rather than Chromium, the CHROME_BIN environmental variable has to point to chrome's executable.

On my POSIX shell, I added this line:

export CHROME_BIN=/usr/bin/google-chrome-stable

Yours will be different. If you're on Windows, you have a couple of options.

The first using cmd.

C:> SET CHROME_BIN=C:\Program Files\PathToGoogleChrome.exe

The other is using PowerShell, you can find more about it on karma-runner faq

like image 190
abdulhaq-e Avatar answered Sep 22 '25 04:09

abdulhaq-e