Skip to content

Instantly share code, notes, and snippets.

@UberMouse
Last active October 21, 2021 00:19
Show Gist options
  • Select an option

  • Save UberMouse/facbe751c3ecb9b31e8b4f6221567b7a to your computer and use it in GitHub Desktop.

Select an option

Save UberMouse/facbe751c3ecb9b31e8b4f6221567b7a to your computer and use it in GitHub Desktop.

Revisions

  1. UberMouse revised this gist Oct 21, 2021. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions electronTest.ts
    Original file line number Diff line number Diff line change
    @@ -27,8 +27,6 @@ export const electronFixtures: Fixtures<ElectronTestFixtures> = {
    const context = electronApp.context();

    await run(context);

    await context.close();
    },
    };

  2. UberMouse created this gist Oct 20, 2021.
    37 changes: 37 additions & 0 deletions electronTest.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    import type { Fixtures } from "@playwright/test";
    import { test as base } from "@playwright/test";
    import { BrowserContext, ElectronApplication, Page } from "playwright";

    export { expect } from "@playwright/test";

    type ElectronTestFixtures = {
    electronApp: ElectronApplication;
    page: Page;
    context: BrowserContext;
    };

    export const electronFixtures: Fixtures<ElectronTestFixtures> = {
    electronApp: async ({}, run) => {
    // This env prevents 'Electron Security Policy' console message.
    process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = "true";
    const electronApp = await aFunctionThatCallsElectronLaunchProcess();
    await run(electronApp);
    await electronApp.close();
    },
    page: async ({ electronApp }, run) => {
    const page = await electronApp.firstWindow();

    await run(page);
    },
    context: async ({ electronApp }, run) => {
    const context = electronApp.context();

    await run(context);

    await context.close();
    },
    };

    // @ts-ignore some error about a string type now having `undefined` as part of it's union
    export const electronTest = base.extend<ElectronTestFixtures>(electronFixtures);

    34 changes: 34 additions & 0 deletions playwright.config.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    import type { PlaywrightTestConfig } from '@playwright/test';
    import * as path from 'path';

    const outputDir = path.join(__dirname, 'test-results');
    const config: PlaywrightTestConfig = {
    outputDir,
    timeout: 30000,
    globalTimeout: 5400000,
    workers: process.env.CI ? 1 : undefined,
    forbidOnly: !!process.env.CI,
    preserveOutput: process.env.CI ? 'failures-only' : 'always',
    retries: process.env.CI ? 3 : 1,
    reporter: process.env.CI ? [
    [ 'dot' ],
    [ 'json', { outputFile: path.join(outputDir, 'report.json') } ],
    ] : 'line',
    projects: [{
    name: 'chromium',
    use: {
    browserName: 'chromium',
    trace: process.env.CI ? 'on-first-retry' : 'on'
    },
    metadata: {
    platform: process.platform,
    headful: true,
    browserName: 'electron',
    channel: undefined,
    mode: 'default',
    video: false,
    }
    }],
    };

    export default config;