JoelEinbinder / karma-playwright-launcher

8 stars 4 forks source link

How to Configure? #1

Open carl-parrish opened 4 years ago

carl-parrish commented 4 years ago

Trying to install in an Angular environment.

I'm going to preface this by saying I don't know puppeteer well but as it seems like playwright was created to be its successor so I thought I'd just skip directly to using it. Using this guide I've attempted to configure Karma and Protractor just as I would puppeteer only substituting playwright wherever I was told to put puppeteer instead. This line

 process.env.CHROME_BIN = require('playwright').executablePath();

Doesn't work however as playwright doesn't have an exectablePath() function itself Instead I tried

 process.env.CHROME_BIN = require('playwright').chromium.executablePath()

-- Which seemed like it would do what I wanted. however I'm still getting the following error message. when trying to run ng test --watch=false

  40% building 84/84 modules 0 active15 02 2020 20:41:52.310:INFO [launcher]: Trying to start ChromeHeadless again (2/2). 15 02 2020 20:41:52.360:ERROR [launcher]: Cannot start ChromeHeadless         /workspace/vr2k2/node_modules/playwright-core/.local-chromium/linux-740847/chrome-linux/chrome: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory  15 02 2020 20:41:52.360:ERROR [launcher]: ChromeHeadless stdout:  15 02 2020 20:41:52.361:ERROR [launcher]: ChromeHeadless stderr: /workspace/vr2k2/node_modules/playwright-core/.local-chromium/linux-740847/chrome-linux/chrome: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory  15 02 2020 20:41:52.436:ERROR [launcher]: ChromeHeadless failed 2 times (cannot start). Giving up. ``` Anyone have a better resource on how to setup Angular with `playwright`? | ```  40% building 84/84 modules 0 active15 02 2020 20:41:52.310:INFO [launcher]: Trying to start ChromeHeadless again (2/2). 15 02 2020 20:41:52.360:ERROR [launcher]: Cannot start ChromeHeadless         /workspace/vr2k2/node_modules/playwright-core/.local-chromium/linux-740847/chrome-linux/chrome: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory  15 02 2020 20:41:52.360:ERROR [launcher]: ChromeHeadless stdout:  15 02 2020 20:41:52.361:ERROR [launcher]: ChromeHeadless stderr: /workspace/vr2k2/node_modules/playwright-core/.local-chromium/linux-740847/chrome-linux/chrome: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory  15 02 2020 20:41:52.436:ERROR [launcher]: ChromeHeadless failed 2 times (cannot start). Giving up.

My next attempt was to find a karma plugin for playwright (which brought me here) thank you much for that but to be honest I'm mostly guessing with out to use it. I began with this command

npm i karma-playwright-launcher --save-dev

Then I configured my karma.config like so

// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html

process.env.CHROME_BIN = require('playwright').chromium.executablePath()

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-playwright-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular-devkit/build-angular/plugins/karma')
    ],
    client: {
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    coverageIstanbulReporter: {
      dir: require('path').join(__dirname, '../coverage'),
      reports: ['html', 'lcovonly'],
      fixWebpackSourcePaths: true
    },
    reporters: ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['ChromeHeadlessNoSandbox','Chromium'],
    customLaunchers: {
        ChromeHeadlessNoSandbox: {
            base: 'ChromeHeadless',
            flags: ['--no-sandbox']
        }
    },
    singleRun: false
  });
};

but when I try to run the test

ng test --browsers ChromeHeadlessNoSandbox
endyjasmi commented 4 years ago

Hello, this is a karma launcher, all you need to is just npm install karma-playwright-launcher and then use it on browsers: ["Chromium", "WebKit", "Firefox"] and that's all. You can choose from any of the 3 browser.

Cheers.

rameshrc commented 4 years ago

Could you please provide a example for this karma file?