Search code examples
playwrightjira-xray

How to execute custom code after reports are generated


I am currently trying to setup some integration of my Playwright tests with Xray Cloud. I am using playwright-junit-reporter to generate JUnit reports with additional info required by Xray API and xray-automation-js to upload the JUnit.xml results to the Xray Cloud.

I need to call the xrayClient.submitResults(reportFile, reportConfig) method after the reports are being generated by Playwright framework.

I have tried to make the call in a globalTeardown file that I then call in playwright.config.ts file (as described here), but the call to gliobalTeardown seems to be done before generating the reports.

The question is: where in my Playwright project I can execute code after the tests are finished and reports generated, so that I can upload the results to Xray?


Solution

  • I don't think this is the way to handle report uploads. As you rightly alluded to, playwright reports are exactly that, a report on the run. And the run is the start to finish cycle through the test/s. As such, uploading a report couldn't and shouldn't be done within the test code.

    This is best handled in my opinion, in your CI/CD pipeline. I cant give code examples here as this is entirely dependant on your services, if you use Docker, Infrastructure etc. But, you should add a step in your pipeline to do the upload to XRay.

    How that looks is again subjective, and I am happy to help in the comments or DM, but you should not scope this to your test project, and instead push this to your CI.