diff --git a/Dockerfile b/Dockerfile index 940f766f..7bb1ba67 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,6 @@ -FROM mcr.microsoft.com/playwright:v1.46.1-noble +ARG PLAYWRIGHT_VERSION + +FROM mcr.microsoft.com/playwright:v${PLAYWRIGHT_VERSION}-noble COPY ./build/node_modules/e2ed /node_modules/e2ed diff --git a/autotests/tests/e2edReportExample/browserData.ts b/autotests/tests/e2edReportExample/browserData.ts index 93e1c9df..0c2720ee 100644 --- a/autotests/tests/e2edReportExample/browserData.ts +++ b/autotests/tests/e2edReportExample/browserData.ts @@ -13,8 +13,6 @@ import { test('correctly read data from browser', {meta: {testId: '14'}}, async () => { await navigateToPage(E2edReportExample); - await waitForInterfaceStabilization(100); - await createClientFunction(() => { console.error('error'); console.info('info'); @@ -23,10 +21,7 @@ test('correctly read data from browser', {meta: {testId: '14'}}, async () => { setTimeout(() => { throw new Error('foo'); - }, 8); - setTimeout(() => { - throw new Error('bar'); - }, 32); + }, 100); })(); const consoleMessages = getBrowserConsoleMessages(); @@ -47,5 +42,14 @@ test('correctly read data from browser', {meta: {testId: '14'}}, async () => { const jsErrors = getBrowserJsErrors(); - await expect(jsErrors.length === 0, 'getBrowserJsErrors read JS errors').eql(true); + await expect( + jsErrors.length, + 'getBrowserJsErrors read zero JS errors when there are no errors', + ).eql(0); + + await waitForInterfaceStabilization(100); + + await expect(jsErrors.length, 'getBrowserJsErrors read all JS errors').eql(1); + + await expect(String(jsErrors[0]), 'getBrowserJsErrors read all JS errors').contains('foo'); }); diff --git a/bin/addPackageJsonToBuildDocker.sh b/bin/addPackageJsonToBuildDocker.sh index d01fe95e..386abd8b 100755 --- a/bin/addPackageJsonToBuildDocker.sh +++ b/bin/addPackageJsonToBuildDocker.sh @@ -1,6 +1,6 @@ #!/usr/bin/env sh set -eu -VERSION=`./bin/getVersion.sh` +E2ED_VERSION=`./bin/getE2edVersion.sh` -echo "{\n \"dependencies\": {\n \"e2ed\": \"$VERSION\"\n }\n}" > ./build/docker/package.json +echo "{\n \"dependencies\": {\n \"e2ed\": \"$E2ED_VERSION\"\n }\n}" > ./build/docker/package.json diff --git a/bin/buildDocker.sh b/bin/buildDocker.sh index b4147018..28d62724 100755 --- a/bin/buildDocker.sh +++ b/bin/buildDocker.sh @@ -1,6 +1,10 @@ #!/usr/bin/env sh set -eu -VERSION=`./bin/getVersion.sh` +E2ED_VERSION=`./bin/getE2edVersion.sh` +PLAYWRIGHT_VERSION=`./bin/getPlaywrightVersion.sh` -docker build --tag e2edhub/e2ed:$VERSION --tag e2edhub/e2ed:latest . +docker build \ + --build-arg PLAYWRIGHT_VERSION=$PLAYWRIGHT_VERSION \ + --tag e2edhub/e2ed:$E2ED_VERSION \ + --tag e2edhub/e2ed:latest . diff --git a/bin/checkPlaywrightBrowserChromiumVersion.sh b/bin/checkPlaywrightBrowserChromiumVersion.sh new file mode 100755 index 00000000..95fc4025 --- /dev/null +++ b/bin/checkPlaywrightBrowserChromiumVersion.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env sh +set -eu + +PLAYWRIGHT_VERSION=`./bin/getPlaywrightVersion.sh` + +grep "\"@playwright/browser-chromium\": \"$PLAYWRIGHT_VERSION\"" ./package.json diff --git a/bin/getVersion.sh b/bin/getE2edVersion.sh similarity index 100% rename from bin/getVersion.sh rename to bin/getE2edVersion.sh diff --git a/bin/getPlaywrightVersion.sh b/bin/getPlaywrightVersion.sh new file mode 100755 index 00000000..a0cecee4 --- /dev/null +++ b/bin/getPlaywrightVersion.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env sh +set -eu + +grep -m1 @playwright/test ./package.json | cut -d '"' -f 4 diff --git a/package.json b/package.json index 73873c88..b69124b6 100644 --- a/package.json +++ b/package.json @@ -67,8 +67,9 @@ "scripts": { "asserts": "assert-modules-support-case-insensitive-fs ./autotests ./src && assert-package-lock-is-consistent", "precheck:all": "npm run asserts && npm run clear:lint:cache && npm run build", - "check:all": "npm audit && npm run parallel check:branch lint test", + "check:all": "npm audit && npm run parallel check:branch check:playwright-version lint test", "check:branch": "node ./build/checkBranch.js", + "check:playwright-version": "./bin/checkPlaywrightBrowserChromiumVersion.sh", "clear:lint:cache": "rm -f ./build/tsconfig.tsbuildinfo ./node_modules/.cache/lint-*", "lint": "npm run parallel lint:es lint:prettier lint:types", "lint:es": "eslint --cache --cache-location=./node_modules/.cache/lint-es --cache-strategy=content --ext=.ts --max-warnings=0 --report-unused-disable-directives .", diff --git a/src/config.ts b/src/config.ts index c0f7a386..ca23b004 100644 --- a/src/config.ts +++ b/src/config.ts @@ -25,7 +25,7 @@ import {isLocalRun} from './configurator'; import type {FullPackConfig, Mutable, UserlandPack} from './types/internal'; -import {defineConfig} from '@playwright/test'; +import {defineConfig, type PlaywrightTestConfig} from '@playwright/test'; const maxTimeoutInMs = 3600_000; @@ -91,6 +91,23 @@ if (isDebug) { setReadonlyProperty(userlandPack, 'testTimeout', maxTimeoutInMs); } +const useOptions: PlaywrightTestConfig['use'] = { + actionTimeout: userlandPack.testIdleTimeout, + browserName: userlandPack.browserName, + // eslint-disable-next-line @typescript-eslint/naming-convention + bypassCSP: true, + deviceScaleFactor: userlandPack.deviceScaleFactor, + hasTouch: userlandPack.enableTouchEventEmulation, + headless: isLocalRun ? userlandPack.enableHeadlessMode : true, + isMobile: userlandPack.enableMobileDeviceMode, + launchOptions: {args: [...userlandPack.browserFlags]}, + navigationTimeout: userlandPack.pageRequestTimeout, + trace: 'retain-on-failure', + userAgent: userlandPack.userAgent, + viewport: {height: userlandPack.viewportHeight, width: userlandPack.viewportWidth}, + ...userlandPack.overriddenConfigFields?.use, +}; + const playwrightConfig = defineConfig({ expect: {timeout: userlandPack.assertionTimeout}, @@ -100,19 +117,7 @@ const playwrightConfig = defineConfig({ outputDir: join(relativePathFromInstalledE2edToRoot, INTERNAL_REPORTS_DIRECTORY_PATH), - projects: [ - { - name: userlandPack.browserName, - use: { - browserName: userlandPack.browserName, - deviceScaleFactor: userlandPack.deviceScaleFactor, - hasTouch: userlandPack.enableTouchEventEmulation, - isMobile: userlandPack.enableMobileDeviceMode, - userAgent: userlandPack.userAgent, - viewport: {height: userlandPack.viewportHeight, width: userlandPack.viewportWidth}, - }, - }, - ], + projects: [{name: userlandPack.browserName, use: useOptions}], retries: isLocalRun ? 0 : userlandPack.maxRetriesCountInDocker - 1, @@ -126,32 +131,7 @@ const playwrightConfig = defineConfig({ ...userlandPack.overriddenConfigFields, - use: { - actionTimeout: userlandPack.testIdleTimeout, - - browserName: userlandPack.browserName, - - // eslint-disable-next-line @typescript-eslint/naming-convention - bypassCSP: true, - - deviceScaleFactor: userlandPack.deviceScaleFactor, - - hasTouch: userlandPack.enableTouchEventEmulation, - - headless: isLocalRun ? userlandPack.enableHeadlessMode : true, - - isMobile: userlandPack.enableMobileDeviceMode, - - navigationTimeout: userlandPack.pageRequestTimeout, - - trace: 'retain-on-failure', - - userAgent: userlandPack.userAgent, - - viewport: {height: userlandPack.viewportHeight, width: userlandPack.viewportWidth}, - - ...userlandPack.overriddenConfigFields?.use, - }, + use: useOptions, }); const config: FullPackConfig = Object.assign(playwrightConfig, userlandPack); diff --git a/src/index.ts b/src/index.ts index 80537c0c..92372e07 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,6 +4,7 @@ export {ApiRoute} from './ApiRoute'; export {Page} from './Page'; export {PageRoute} from './PageRoute'; +export {devices} from './playwright'; export {Route} from './Route'; export {getPlaywrightPage, useContext} from './useContext'; diff --git a/src/playwright.ts b/src/playwright.ts new file mode 100644 index 00000000..3e452ae3 --- /dev/null +++ b/src/playwright.ts @@ -0,0 +1 @@ +export {devices} from '@playwright/test'; diff --git a/src/utils/fullMocks/enableFullMocks.ts b/src/utils/fullMocks/enableFullMocks.ts index dfc85067..77567cec 100644 --- a/src/utils/fullMocks/enableFullMocks.ts +++ b/src/utils/fullMocks/enableFullMocks.ts @@ -52,6 +52,7 @@ export const enableFullMocks = async ( requestKinds: Object.fromEntries( Object.entries(testFullMocks).map(([key, value]) => [key, value.length]), ), + testId: fullMocksState.testId, }, LogEventType.InternalUtil, );