test: take screenshots to debug visibility tests

This commit is contained in:
John Kleinschmidt
2024-12-19 10:47:42 -05:00
parent 3d6d876a1b
commit 494c6fc203
3 changed files with 25 additions and 2 deletions

View File

@@ -237,6 +237,13 @@ jobs:
$DATADOG_PATH/datadog-ci junit upload src/electron/junit/test-results-main.xml
fi
if: always() && !cancelled()
- name: Upload Test Artifacts
if: always() && !cancelled()
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882
with:
name: test_artifacts_${{ env.ARTIFACT_KEY }}_${{ matrix.shard }}
path: src/electron/spec/artifacts
if-no-files-found: ignore
- name: Wait for active SSH sessions
if: always() && !cancelled()
shell: bash

View File

@@ -4,8 +4,9 @@ import { expect } from 'chai';
import { once } from 'node:events';
import { ScreenCapture } from './lib/screen-helpers';
import { defer, ifit, waitUntil } from './lib/spec-helpers';
import { cleanupWebContents, closeAllWindows } from './lib/window-helpers';
import { closeAllWindows } from './lib/window-helpers';
describe('WebContentsView', () => {
afterEach(async () => {
@@ -181,7 +182,14 @@ describe('WebContentsView', () => {
});
describe('visibilityState', () => {
afterEach(cleanupWebContents);
before(async () => {
const screenCapture = await ScreenCapture.create();
await screenCapture.takeScreenShot();
});
afterEach(async () => {
const screenCapture = await ScreenCapture.create();
await screenCapture.takeScreenShot();
});
async function haveVisibilityState (view: WebContentsView, state: string) {
const docVisState = await view.webContents.executeJavaScript('document.visibilityState');

View File

@@ -121,6 +121,14 @@ export class ScreenCapture {
return this._expectImpl(findPoint(this.image.getSize()), hexColor, true);
}
public async takeScreenShot () {
const artifactName = await createArtifactWithRandomId(
(id) => `screen-cap-${id}.png`,
this.image.toPNG()
);
console.log(`Created artifact at: ${artifactName}`);
}
private static async _createImpl (display: Electron.Display) {
const sources = await desktopCapturer.getSources({
types: ['screen'],