Rayrun

How do I use Playwright to automate an Electron application built using Electron-Forge?

Answer

Sure, you can use Playwright to automate an Electron app built with Electron-Forge. First, initialize Playwright in your project with npm init playwright@latest. This sets up the necessary files like playwright.config.ts, package.json, and package-lock.json.

Then, you can run npx playwright install to download and install the default browsers supported by Playwright.

If you want to bundle a Chromium installation for your Electron app, you can use Playwright's ability to operate against branded Google Chrome and Microsoft Edge browsers available on your machine.

Here's how you can define configurations in your playwright.config.ts file to use Google Chrome or Microsoft Edge:

import { defineConfig } from '@playwright/test';

export default defineConfig({
  projects: [
    {
      name: 'Google Chrome',
      use: {
        browserName: 'chromium',
        channel: 'chrome'
      }
    },
    {
      name: 'Microsoft Edge',
      use: {
        browserName: 'chromium',
        channel: 'msedge'
      }
    }
  ]
});

Remember, Playwright doesn't install Google Chrome or Microsoft Edge by default. If they're not available on your machine, you can use the Playwright command line tool to install them. For instance, npx playwright install msedge installs Microsoft Edge. But be careful, as it will override your current browser installation and install them at the default global location of your operating system.

In short, you can either run npx playwright install to download and install the default browsers supported by Playwright, or leverage existing installations of Google Chrome or Microsoft Edge by configuring Playwright in your playwright.config.ts file.

References

Thank you!
Was this helpful?
Still have questions?

If you still have questions, please ask a question and I will try to answer it.

Related Discord Threads

Related Questions

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].