mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-02-15 07:28:59 +00:00
Add .screenshot() method to mock tests
This commit is contained in:
@@ -221,6 +221,7 @@ export class Bootstrap {
|
||||
#storagePath?: string;
|
||||
#timestamp: number = Date.now() - WEEK;
|
||||
#lastApp?: App;
|
||||
#screenshotId = 0;
|
||||
readonly #randomId = crypto.randomBytes(8).toString('hex');
|
||||
|
||||
constructor(options: BootstrapOptions = {}) {
|
||||
@@ -545,6 +546,28 @@ export class Bootstrap {
|
||||
}
|
||||
}
|
||||
|
||||
public async screenshot(
|
||||
app: App | undefined = this.#lastApp,
|
||||
testName?: string
|
||||
): Promise<void> {
|
||||
if (!app) {
|
||||
return;
|
||||
}
|
||||
|
||||
const outDir = await this.#getArtifactsDir(testName);
|
||||
if (outDir == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const window = await app.getWindow();
|
||||
const screenshot = await window.screenshot();
|
||||
|
||||
const id = this.#screenshotId;
|
||||
this.#screenshotId += 1;
|
||||
|
||||
await fs.writeFile(path.join(outDir, `screenshot-${id}.png`), screenshot);
|
||||
}
|
||||
|
||||
public async saveLogs(
|
||||
app: App | undefined = this.#lastApp,
|
||||
testName?: string
|
||||
@@ -566,11 +589,7 @@ export class Bootstrap {
|
||||
?.context()
|
||||
.tracing.stop({ path: path.join(outDir, 'trace.zip') });
|
||||
}
|
||||
if (app) {
|
||||
const window = await app.getWindow();
|
||||
const screenshot = await window.screenshot();
|
||||
await fs.writeFile(path.join(outDir, 'screenshot.png'), screenshot);
|
||||
}
|
||||
await this.screenshot(app, testName);
|
||||
}
|
||||
|
||||
public async createScreenshotComparator(
|
||||
|
||||
Reference in New Issue
Block a user