r/Playwright • • 5d ago

GitHub Actions browser and device testing

Hi,

I've got a suite of Playwright tests that run against multiple browsers and mobile viewports.

playwright.config.ts:

projects: [
  {
    name: 'chromium',
    use: { ...devices['Desktop Chrome'] },
  },
  {
    name: 'firefox',
    use: { ...devices['Desktop Firefox'] },
  },
  {
    name: 'webkit',
    use: { ...devices['Desktop Safari'] },
  },

  /* Test against mobile viewports. */
  {
    name: 'Mobile Chrome',
    use: { ...devices['Pixel 5'] },
  },
  {
    name: 'Mobile Safari',
    use: { ...devices['iPhone 12'] },
  },

  /* Test against branded browsers. */
  {
    name: 'Microsoft Edge',
    use: { ...devices['Desktop Edge'], channel: 'msedge' },
  },
  {
    name: 'Google Chrome',
    use: { ...devices['Desktop Chrome'], channel: 'chrome' },
  },
],playwright.config.ts:projects: [
  {
    name: 'chromium',
    use: { ...devices['Desktop Chrome'] },
  },
  {
    name: 'firefox',
    use: { ...devices['Desktop Firefox'] },
  },
  {
    name: 'webkit',
    use: { ...devices['Desktop Safari'] },
  },

  /* Test against mobile viewports. */
  {
    name: 'Mobile Chrome',
    use: { ...devices['Pixel 5'] },
  },
  {
    name: 'Mobile Safari',
    use: { ...devices['iPhone 12'] },
  },

  /* Test against branded browsers. */
  {
    name: 'Microsoft Edge',
    use: { ...devices['Desktop Edge'], channel: 'msedge' },
  },
  {
    name: 'Google Chrome',
    use: { ...devices['Desktop Chrome'], channel: 'chrome' },
  },
],

Locally, Playwright runs the tests against all the configured browsers and device viewports.

However, in my GitHub Actions workflow, I'm using a matrix strategy to run tests across multiple browsers:

strategy:
  fail-fast: false
  matrix:
    browser: [chromium, firefox, webkit]

This currently means GitHub Actions runs the tests against Chromium, Firefox and WebKit.

My question is: What's the best approach to running the full suite against all these projects in GitHub Actions, including mobile viewports and branded browsers such as Microsoft Edge and Google Chrome?

Do I need to configure additional matrix entries for mobile devices and Edge, as I assumed this would have covered the mobile browsers etc.

5 Upvotes

8 comments sorted by

2

u/Brainy-Cos 4d ago

the chromium/firefox/webkit matrix only splits those three engines, it doesn't automatically run mobile device projects or edge. mobile in playwright is usually just chromium or webkit with a device descriptor (viewport, user agent, touch), so those won't show up in ci unless you actually select those projects.

if the workflow is passing --project from the matrix, define the devices and browsers as projects in playwright.config and matrix on the project names instead. the default config already has commented examples for mobile chrome, mobile safari and edge with channel: 'msedge'. so something like project: [chromium, firefox, webkit, "Mobile Chrome", "Mobile Safari"] and then npx playwright test --project="${{ matrix.project }}". or drop the filter and just run npx playwright test so every configured project runs in one job.

edge isn't part of the default install, it's a branded chromium channel, so add that project and install it on the runner with npx playwright install msedge. not really a fourth engine like firefox or webkit.

1

u/Due_Point_615 1d ago

Cheers, I got it working in the end with all browsers

1

u/Brainy-Cos 1d ago

🥳

1

u/Xiao20 5d ago

playwright comes with viewport testing built in.

You should probably who uses your (site | app) with what devices and focus your attention there.

1

u/Due_Point_615 5d ago

I've just edited my original post to provide more context

2

u/Opposite_Sector2145 5d ago

with your matrix setup, only the browser names in the matrix get run, so mobile devices and branded browsers in playwright.config won't be picked up unless you add them to the matrix or remove the matrix and just run "npx playwright test" directly. the matrix overrides project selection.

1

u/Status_Ad8999 4d ago

`Mobile Chrome` and `Mobile Safari` reuse the bundled `chromium` and `webkit` binaries, so you can pass `--project=chromium --project="Mobile Chrome"` in the same matrix job without extra downloads. Branded projects (`channel: 'chrome'` or `'msedge'`) need `npx playwright install --with-deps chrome msedge` explicitly in CI because default `playwright install` skips branded channels.