Skip to content

Commit fa9e6cc

Browse files
authored
Bring back Playwright-Electron Workbench's on-failure screenshot + new PLAYWRIGHT_RECORD_VIDEO (#5464)
* Fix playwright-electron screenshots on failure and add PLAYWRIGHT_RECORD_VIDEO * yarn tsc
1 parent 77fbb68 commit fa9e6cc

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

e2e/playwright/fixtures/fixtureSetup.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,25 @@ export interface Fixtures {
5959
homePage: HomePageFixture
6060
}
6161
export class AuthenticatedTronApp {
62-
public readonly _page: Page
62+
public originalPage: Page
6363
public page: Page
64+
public browserContext: BrowserContext
6465
public context: BrowserContext
6566
public readonly testInfo: TestInfo
6667
public electronApp: ElectronApplication | undefined
6768
public readonly viewPortSize = { width: 1200, height: 500 }
6869
public dir: string = ''
6970

70-
constructor(context: BrowserContext, page: Page, testInfo: TestInfo) {
71-
this._page = page
72-
this.page = page
73-
this.context = context
71+
constructor(
72+
browserContext: BrowserContext,
73+
originalPage: Page,
74+
testInfo: TestInfo
75+
) {
76+
this.page = originalPage
77+
this.originalPage = originalPage
78+
this.browserContext = browserContext
79+
// Will be overwritten in the initializer
80+
this.context = browserContext
7481
this.testInfo = testInfo
7582
}
7683
async initialise(
@@ -86,9 +93,16 @@ export class AuthenticatedTronApp {
8693
folderSetupFn: arg.folderSetupFn,
8794
cleanProjectDir: arg.cleanProjectDir,
8895
appSettings: arg.appSettings,
96+
viewport: this.viewPortSize,
8997
})
9098
this.page = page
99+
100+
// These assignments "fix" some brokenness in the Playwright Workbench when
101+
// running against electron applications.
102+
// The timeline is still broken but failure screenshots work again.
91103
this.context = context
104+
Object.assign(this.browserContext, this.context)
105+
92106
this.electronApp = electronApp
93107
this.dir = dir
94108

e2e/playwright/test-utils.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,11 +937,16 @@ export async function setupElectron({
937937
testInfo,
938938
cleanProjectDir = true,
939939
appSettings,
940+
viewport,
940941
}: {
941942
testInfo: TestInfo
942943
folderSetupFn?: (projectDirName: string) => Promise<void>
943944
cleanProjectDir?: boolean
944945
appSettings?: Partial<SaveSettingsPayload>
946+
viewport: {
947+
width: number
948+
height: number
949+
}
945950
}): Promise<{
946951
electronApp: ElectronApplication
947952
context: BrowserContext
@@ -972,6 +977,14 @@ export async function setupElectron({
972977
...(process.env.ELECTRON_OVERRIDE_DIST_PATH
973978
? { executablePath: process.env.ELECTRON_OVERRIDE_DIST_PATH + 'electron' }
974979
: {}),
980+
...(process.env.PLAYWRIGHT_RECORD_VIDEO
981+
? {
982+
recordVideo: {
983+
dir: testInfo.snapshotPath(),
984+
size: viewport,
985+
},
986+
}
987+
: {}),
975988
}
976989

977990
// Do this once and then reuse window on subsequent calls.

e2e/playwright/zoo-test.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,6 @@ type PWFunction = (
6868

6969
let firstUrl = ''
7070

71-
// The below error is due to the extreme type spaghetti going on. playwright/
72-
// types/test.d.ts does not export 2 functions (below is one of them) but tsc
73-
// is trying to use a interface name it can't see.
74-
// e2e/playwright/zoo-test.ts:64:14 - error TS4023: Exported variable 'test' has
75-
// or is using name 'TestFunction' from external module
76-
// "/home/lee/Code/Zoo/modeling-app/dirty2/node_modules/playwright/types/test"
77-
// but cannot be named.
7871
export const test = (
7972
desc: string,
8073
objOrFn: PWFunction | TestDetails,

0 commit comments

Comments
 (0)