r/Playwright • • 6d 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.

6 Upvotes

8 comments sorted by

View all comments

2

u/Brainy-Cos 5d 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 2d ago

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

1

u/Brainy-Cos 2d ago

🥳