Rayrun
← Back to Discord Forum

How do I run Playwright tests in Github Actions with a database on Docker ?

I'm trying to setup a Github Actions CI to run my Playwright tests. The problem is that I need to use Docker to run postgres and create a database.
I currently have this CI file:

runs-on: ubuntu-22.04
    services:
      postgres:
        image: postgres
        env:
          POSTGRES_DB: postgres
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: postgres
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
        ports:
          - 5433:5432

    container:
      image: mcr.microsoft.com/playwright:v1.40.0-jammy

    steps:
      - uses: actions/checkout@v4
      - uses: pnpm/action-setup@v2
        with:
          version: 8

      - name: Set up Node
        uses: actions/setup-node@v4
        with:
          node-version: lts/*
          cache: 'pnpm'

      - name: Start Docker
        run: docker-compose -f "docker-compose.yml" up -d --build

      - name: Install dependencies
        run: pnpm install && pnpm install:playwright

      - name: Build application
        run: pnpm build:ci

      - name: Start application
        run: pnpm start &

      - name: Sleep for 30 seconds
        run: sleep 30s
        shell: bash

      - name: Migrate database
        run: pnpm push
        env:
          DATABASE_URL: postgresql://postgres:postgres@postgres:5433/postgres

      - name: Run Playwright tests
        run: pnpm test

      - uses: actions/upload-artifact@v3
        if: always()
        with:
          name: playwright-report
          path: playwright-report/
          retention-days: 30

The latest error that I got with this configuration returned an error saying: docker-compose: not found
I spent a few days / weeks trying to fix this and Idk what I need to change (it's my first time with Docker so I'm not an expert in it).

This thread is trying to answer question "How do I run Playwright tests in GitHub Actions with a database on Docker?"

2 replies

Here's my docker-compose file:

version: '3.9'

services:
  postgres:
    container_name: postgres
    image: postgres:14
    restart: always
    ports:
      - '5433:5432'
    environment:
      POSTGRES_USER: user
      POSTGRES_PASSWORD: password
      POSTGRES_DB: db
    volumes:
      - postgres:/var/lib/postgresql/data

volumes:
  postgres:
    driver: local

Hi, probably you can better ask this question on a GitHub Actions or Docker community. To answer it, it requires little knowledge of Playwright and much knowledge on those other topics.

Related Discord Threads

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].