Mona101ma
Mona101ma

Reputation: 772

Running playwright tests stage stuck in running state endlessly on Jenkins

I created a Jenkins pipeline that runs dockerize the frontend app, build it and run playwrite test cases.

My problem is that, the running tests stage doesn't move to the next step after running all tests.

Jenkins file:

 #!groovy

pipeline {
    agent any

    stages {
        stage('Checkout') {
            steps {
                echo 'Clean workspace'
                cleanWs()
                echo 'Checking out the PR'
                checkout scm
            }
        }

        stage('Build') {
            steps {
                echo 'Destroy Old Build'
                echo 'Building'
                sh 'make upbuild_d'
            }
        }

         stage('Lint') {
            steps {
                echo 'Checking Lint'
                sh 'make lint'
            }
        }

        stage('Test') {
            steps {
                echo 'Running Tests ...'
                sh 'make test-e2e'
            }
        }
    }
    // [StagePost] Clean after finishing
    post {
        always {
            echo '## BEGIN ALWAYS BLOCK ##'
            echo 'Destroy Build'
            sh 'make destroy'
            cleanWs()
            echo '## END ALWAYS BLOCK ##'
        }
    }
}

Here is the make test-e2e in Makefile

test-e2e:
docker exec my-container bash -c 'npm run test:e2e'

And this is the test:e2e script npx playwright test --project=chromium

How can Jenkins detect that all tests are already run to execute the post steps? enter image description here

Upvotes: 1

Views: 2907

Answers (2)

Pavan Jadda
Pavan Jadda

Reputation: 4871

There are couple of ways you can do this

  1. Pass CI=true to playwright command.
CI=true npx playwright test
  1. Or, as Mona101ma said, update playwright.config.ts file
reporter: [['html', { open: 'never' }]],

The open option has 3 possible values

  1. always, always open the HTML report
  2. never, never open the HTML report
  3. on-failure, show the report only when the tests failed

To learn more about this, check ReporterDescription type, it has multiple options for reporter

export type ReporterDescription =
  ['dot'] |
  ['line'] |
  ['list'] |
  ['github'] |
  ['junit'] | ['junit', { outputFile?: string, stripANSIControlSequences?: boolean }] |
  ['json'] | ['json', { outputFile?: string }] |
  ['html'] | ['html', { outputFolder?: string, open?: 'always' | 'never' | 'on-failure', attachmentsBaseURL?: string }] |
  ['null'] |
  [string] | [string, any];

Upvotes: 2

Mona101ma
Mona101ma

Reputation: 772

This issue occurred because of this line in playwright.config.js reporter: 'html'.

This results in trying to open the test report in a browser that requires a GUI which isn't found inside the container, so the process hangs. It is fixed by updating the reporter config as reporter: [['html', { open: 'never' }]]

Upvotes: 4

Related Questions