Dan
Dan

Reputation: 2725

How do I run playwright targeting localhost in github-actions?

I am trying to run playwright E2E tests for github-actions but have been unsuccessful so far.

    - name: Run build and start
      run: |
        yarn build:e2e
        yarn start:e2e &
    - name: Run e2e
      run: |
        yarn e2e

I don't think the server is running when playwright runs because all the e2e tests end up failing.

Run build and start

Done in 192.91s.
yarn run v1.22.19
$ env-cmd -f environments/.env.e2e next start
ready - started server on 0.0.0.0:3000, url: ***

Run e2e

Test timeout of 270000ms exceeded while running "beforeEach" hook.

I am pretty certain that playwright cannot connect to http://localhost:3000 from the previous step and that's why all the tests timeout.

Upvotes: 7

Views: 6769

Answers (1)

Mitsudani
Mitsudani

Reputation: 114

I had a similar problem and I fixed it by adding this to playwright.config.ts

const config: PlaywrightTestConfig = {
// the rest of the options
  webServer: {
    command: 'yarn start',
    url: 'http://localhost:3000/',
    timeout: 120000,
  },
  use: {
    baseURL: 'http://localhost:3000/',
  },
  // the rest of the options
};
export default config;

Also, I didn't need to yarn start in GitHub Actions workflow, just yarn build is enough.

Source: https://github.com/microsoft/playwright/issues/14814

Upvotes: 7

Related Questions