Reputation: 573
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 :)
Upvotes: 4
Views: 18253
Reputation: 6026
In the playwright.config.ts, add launchoptions as given below.
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'],
launchOptions:
{
headless: false,
executablePath: "C:\\Users\\Admin\\AppData\\Local\\ms-playwright\\chromium-1134\\chrome-win\\chrome.exe" }
},
}
]
Upvotes: 0
Reputation: 3222
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.
Upvotes: 3
Reputation: 8871
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()
})
})
Upvotes: 0