Interface ElectronApplication

Electron application representation. You can use electron.launch([options]) to obtain the application instance. This instance you can control main electron process as well as work with Electron windows:

const { _electron: electron } = require('playwright');

(async () => {
// Launch Electron app.
const electronApp = await electron.launch({ args: ['main.js'] });

// Evaluation expression in the Electron context.
const appPath = await electronApp.evaluate(async ({ app }) => {
// This runs in the main Electron process, parameter here is always
// the result of the require('electron') in the main app script.
return app.getAppPath();
});
console.log(appPath);

// Get the first window that the app opens, wait if necessary.
const window = await electronApp.firstWindow();
// Print the title.
console.log(await window.title());
// Capture a screenshot.
await window.screenshot({ path: 'intro.png' });
// Direct Electron console to Node terminal.
window.on('console', console.log);
// Click button.
await window.click('text=Click me');
// Exit app.
await electronApp.close();
})();

Hierarchy

  • ElectronApplication

Methods

  • This event is issued when the application closes.

    Parameters

    • event: "close"
    • listener: (() => void)
        • (): void
        • Returns void

    Returns ElectronApplication

  • This event is issued for every window that is created and loaded in Electron. It contains a [Page] that can be used for Playwright automation.

    Parameters

    • event: "window"
    • listener: ((page: Page) => void)
        • (page: Page): void
        • Parameters

          Returns void

    Returns ElectronApplication

  • Returns the BrowserWindow object that corresponds to the given Playwright page.

    Parameters

    • page: Page

      Page to retrieve the window for.

    Returns Promise<JSHandle<any>>

  • Closes Electron application.

    Returns Promise<void>

  • This method returns browser context that can be used for setting up context-wide routing, etc.

    Returns BrowserContext

  • Convenience method that waits for the first application window to be opened.

    Usage

      const electronApp = await electron.launch({
    args: ['main.js']
    });
    const window = await electronApp.firstWindow();
    // ...

    Returns Promise<Page>

  • Removes an event listener added by on or addListener.

    Parameters

    • event: "close"
    • listener: (() => void)
        • (): void
        • Returns void

    Returns ElectronApplication

  • Removes an event listener added by on or addListener.

    Parameters

    • event: "window"
    • listener: ((page: Page) => void)
        • (page: Page): void
        • Parameters

          Returns void

    Returns ElectronApplication

  • This event is issued when the application closes.

    Parameters

    • event: "close"
    • listener: (() => void)
        • (): void
        • Returns void

    Returns ElectronApplication

  • This event is issued for every window that is created and loaded in Electron. It contains a [Page] that can be used for Playwright automation.

    Parameters

    • event: "window"
    • listener: ((page: Page) => void)
        • (page: Page): void
        • Parameters

          Returns void

    Returns ElectronApplication

  • Adds an event listener that will be automatically removed after it is triggered once. See addListener for more information about this event.

    Parameters

    • event: "close"
    • listener: (() => void)
        • (): void
        • Returns void

    Returns ElectronApplication

  • Adds an event listener that will be automatically removed after it is triggered once. See addListener for more information about this event.

    Parameters

    • event: "window"
    • listener: ((page: Page) => void)
        • (page: Page): void
        • Parameters

          Returns void

    Returns ElectronApplication

  • This event is issued when the application closes.

    Parameters

    • event: "close"
    • listener: (() => void)
        • (): void
        • Returns void

    Returns ElectronApplication

  • This event is issued for every window that is created and loaded in Electron. It contains a [Page] that can be used for Playwright automation.

    Parameters

    • event: "window"
    • listener: ((page: Page) => void)
        • (page: Page): void
        • Parameters

          Returns void

    Returns ElectronApplication

  • Returns the main process for this Electron Application.

    Returns ChildProcess

  • Removes an event listener added by on or addListener.

    Parameters

    • event: "close"
    • listener: (() => void)
        • (): void
        • Returns void

    Returns ElectronApplication

  • Removes an event listener added by on or addListener.

    Parameters

    • event: "window"
    • listener: ((page: Page) => void)
        • (page: Page): void
        • Parameters

          Returns void

    Returns ElectronApplication

  • This event is issued when the application closes.

    Parameters

    • event: "close"
    • Optional optionsOrPredicate: {
          predicate?: (() => boolean | Promise<boolean>);
          timeout?: number;
      } | (() => boolean | Promise<boolean>)

    Returns Promise<void>

  • This event is issued for every window that is created and loaded in Electron. It contains a [Page] that can be used for Playwright automation.

    Parameters

    • event: "window"
    • Optional optionsOrPredicate: {
          predicate?: ((page: Page) => boolean | Promise<boolean>);
          timeout?: number;
      } | ((page: Page) => boolean | Promise<boolean>)

    Returns Promise<Page>

  • Convenience method that returns all the opened windows.

    Returns Page[]

Generated using TypeDoc