4

I need to run some tests using Playwright among different Chromium versions. I have different Chromium folders with different versions, but I don't know how to switch from a version to another using the CLI to run my tests. Some help? Thanks :)

Ciccios_1518
  • 435
  • 1
  • 6
  • 13

2 Answers2

3

You can use the executablePath argument when launching the browser to use a custom executable. See here. Note, that this only works with Chromium based browsers, see here.

const playwright = require('playwright');

(async () => {
  const browser = await playwright.chromium.launch({
    executablePath: '/your/custom/chromium', 
    headless: false, // to see the browser
    slowMo: 4000 // to slow it down
  });
  // example for edge on msft windows 
  // executablePath: 'C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe',


  const page = await browser.newPage();
  await page.goto('http://whatsmyuseragent.org/');
  await page.screenshot({ path: `example.png` });
  await browser.close();
})();

Also Playwright does only test against the latest stable version, so other Chromium versions might miss-behave. See here under the releases.

surfmuggle
  • 5,527
  • 7
  • 48
  • 77
Max Schmitt
  • 2,529
  • 1
  • 12
  • 26
  • As I commented under @theDavidBarton answer, I'd like to switch different chromium versions, included some old ones, to see how my code misbehave. – Ciccios_1518 Sep 17 '21 at 07:35
0

Max Schmitt is right: the library is not guaranteed to work with non-bundled Chromiums. Anyway, you can give it a try to multiple Chromium-based browsers in the executablePath. As it is not builtin in the Playwright Test you will need to implement it yourself.

Note: like this you lose some of the simplicity of Playwright Test.

In my example I used Jest as a test runner so yarn add --dev jest is required. The last CLI argument - reserved for the browser version - can be retrieved with process.argv.slice(-1)[0] within Node, like this you can tell your tests what browser version you want to use. Here they will be edge, chrome and the default is the bundled chromium.

MS Edge (Chromium)

yarn test chrome.test.js edge

Chrome

yarn test chrome.test.js chrome

Chromium (default - bundled with Playwright) (but any string, or the lack of this argument will also launch this as the default)

yarn test chrome.test.js chromium_default

chrome.test.js
(with Windows-specific executable paths)

const playwright = require('playwright')

let browser
let page

beforeAll(async function () {
  let chromeExecutablePath
  switch (process.argv.slice(-1)[0]) {
    case 'chrome':
      chromeExecutablePath = 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe'
      break
    case 'edge':
      chromeExecutablePath = 'C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe'
      break
    default:
      chromeExecutablePath = ''
  }
  browser = await playwright.chromium.launch({ 
    headless: false, 
    executablePath: chromeExecutablePath 
  })
  page = await browser.newPage()
})

describe('Google Search', function () {
  test('should respond with HTTP 200 - OK', async function () {
    const response = await page.goto('https://google.com')
    const responseCode = response.status()
    expect(responseCode).toBe(200)
  })
  afterAll(async function () {
    await browser.close()
  })
})
theDavidBarton
  • 7,643
  • 4
  • 24
  • 51
  • Hi, sorry for the the delay, maybe I didn't make myself quite clear about what I want to do: For chromium versions I mean for example "chromium-888113" or "chromium-907428" and so on and so forth. Is your code adaptable to achieve this goal? Because as I can see you put the path to the .exe of those browsers (useful as well). So I wonder if I can point to the path "C:\Users\admin\AppData\Local\ms-playwright\*browser-name*" to switch at will among different chromium versions, just to see how my test misbehave with them. – Ciccios_1518 Sep 17 '21 at 07:33
  • Also, as I'm not using Jest as runner, what would be the lines of code the would differ from using the native test runner offered by Playwright? Thank you in advance :) – Ciccios_1518 Sep 17 '21 at 07:37
  • 1
    (1) you can do the above with any chrome versions, of course, it means you need to install them yourself and get their proper executable path the same way (it is needed as Playwright only bundles the latest compatible Chromium version). (2) I am not that deeply familiar with the Playwright runner, as far as I see you can not set a custom executable path there, hence you need to drop it for another runner (like Jest). – theDavidBarton Sep 17 '21 at 08:31
  • And do you know if it's possible to have different test runners inside the same project folder? Maybe it's a trivial question but I'm really new to this world :D – Ciccios_1518 Sep 17 '21 at 08:40
  • I am sure it is possible to have multiple runners, but mixing them within the project might be tricky. I am familiar with Jest only. – theDavidBarton Sep 17 '21 at 12:33