Skip to content

Commit

Permalink
E2E: Try to take a screenshot if the app fails to start
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Yen <mark.yen@suse.com>
  • Loading branch information
mook-as committed Oct 10, 2024
1 parent 9c4941f commit c539cc7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/linux-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:
timeout-minutes: 150
runs-on: ubuntu-latest
steps:
- run: |
sudo apt-get install -y graphicsmagick-imagemagick-compat
- uses: actions/checkout@v4
with:
persist-credentials: false
Expand Down
41 changes: 37 additions & 4 deletions e2e/utils/TestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,12 @@ export async function teardownApp(app: ElectronApplication) {
}
}

export async function teardown(app: ElectronApplication, testInfo: TestInfo) {
export async function teardown(app: ElectronApplication | undefined, testInfo: TestInfo) {
if (!app) {
// This can happen if we failed to start up.
return;
}

const context = app.context();
const { file: filename } = testInfo;

Expand Down Expand Up @@ -384,11 +389,17 @@ export async function startRancherDesktop(testInfo: TestInfo, options: startRanc
if (options?.timeout) {
launchOptions.timeout = options?.timeout;
}
const electronApp = await _electron.launch(launchOptions);

await electronApp.context().tracing.start({ screenshots: true, snapshots: true });
try {
const electronApp = await _electron.launch(launchOptions);

await electronApp.context().tracing.start({ screenshots: true, snapshots: true });

return electronApp;
return electronApp;
} catch (ex) {
await takeScreenShot(path.join(reportAsset(testInfo, 'log'), 'startup-failure.png'));
throw ex;
}
}

export async function startSlowerDesktop(testInfo: TestInfo, defaultSettings: RecursivePartial<Settings> = {}): Promise<[ElectronApplication, Page]> {
Expand All @@ -403,3 +414,25 @@ export async function startSlowerDesktop(testInfo: TestInfo, defaultSettings: Re

return [electronApp, page];
}

async function takeScreenShot(outPath: string) {
try {
switch (process.platform) {
case 'darwin':
await childProcess.spawnFile('screencapture', ['-m', outPath]);
break;
case 'win32': {
const script = path.resolve(__dirname, '..', '..', 'screenshots', 'screenshot.ps1');

await childProcess.spawnFile('powershell.exe', [script, '-FilePath', outPath]);
break;
}
default:
await childProcess.spawnFile('import', [outPath]);
break;
}
console.log(`Took screenshot ${ outPath }`);
} catch (ex) {
console.error(`Error taking screenshot: ${ ex }`);
}
}

0 comments on commit c539cc7

Please sign in to comment.