Skip to content

Commit 1916207

Browse files
[🐛] Fix playwright version in BrowserStack to match package.json (#3810)
* Fix playwright version in BrowserStack to match package.json * add getLocalPlaywrightVersion to get the playwright version from the package.json
1 parent 9625a8f commit 1916207

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

test/e2e/lib/helpers/playwright.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { PlaywrightWorkerOptions } from '@playwright/test'
22
import type { BrowserConfiguration } from '../../../browsers.conf'
33
import { getBuildInfos } from '../../../envUtils'
4+
import packageJson from '../../../../package.json'
45

56
export const DEV_SERVER_BASE_URL = 'http://localhost:8080'
67

@@ -22,6 +23,7 @@ export function getEncodedCapabilities(configuration: BrowserConfiguration) {
2223

2324
// see: https://www.browserstack.com/docs/automate/playwright/playwright-capabilities
2425
function getCapabilities(configuration: BrowserConfiguration) {
26+
const playwrightVersion = resolvePlaywrightVersionFromPackageJson()
2527
return {
2628
os: configuration.os,
2729
os_version: configuration.osVersion,
@@ -33,11 +35,23 @@ function getCapabilities(configuration: BrowserConfiguration) {
3335
build: getBuildInfos(),
3436
name: configuration.sessionName,
3537
'browserstack.local': true,
36-
'browserstack.playwrightVersion': '1.latest',
37-
'client.playwrightVersion': '1.latest',
38+
'browserstack.playwrightVersion': playwrightVersion,
39+
'client.playwrightVersion': playwrightVersion,
3840
'browserstack.debug': false,
3941
'browserstack.console': 'info',
4042
'browserstack.networkLogs': false,
4143
'browserstack.interactiveDebugging': false,
4244
}
4345
}
46+
47+
function resolvePlaywrightVersionFromPackageJson(): string {
48+
const rootPkg = packageJson as unknown as {
49+
devDependencies?: Record<string, string>
50+
dependencies?: Record<string, string>
51+
}
52+
const version = rootPkg.devDependencies?.['@playwright/test'] || rootPkg.dependencies?.['@playwright/test']
53+
if (!version) {
54+
throw new Error('Unable to resolve @playwright/test version from package.json')
55+
}
56+
return version
57+
}

0 commit comments

Comments
 (0)