question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Different behaviour in globalTear down when using PW recent versions

See original GitHub issue

Context:

  • Playwright Version: 1.20.1
  • Operating System: Mac
  • Node.js version: 14.6
  • Browser: any
  • Extra: [any specific details about your environment]

Code Snippet

async function globalSetup(config: FullConfig) {
    console.log("Report path " + config.rootDir);

    const reportPath = "./playwright-report";
    console.log("Report path: " + reportPath);
    var zip = new AdmZip();

    zip.addLocalFolder(reportPath, "./playwrightReport");
    zip.writeZip("./report.zip")

}


export default globalSetup;

Describe the bug

i have noticed that global tear down feature is working differently with the recent version >= 1.19, as with the newer version global teardown function is executed after the tests but not after the session itself, for example i need to zip the playwright-report folder after the execution, currently i can not do that since the teardown function will be executed after the test and before the report is being generated, playwright will wait for global tear down function to be executed then generate the report as shown below. v 1.20.1 Screenshot 2022-03-31 at 12 47 31 Screenshot 2022-03-31 at 12 50 18

unlike the case with the previous version such as 1.17, the tear down function was being executed after the report is being generated which make more sense, except if it could be possible to make global tear down after worker, and global tear down after session

V 1.17 Screenshot 2022-03-31 at 12 42 26

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
amrsa1commented, Mar 31, 2022

Awesome, thank you guys so much.

OnEnd event solved my issue, and thanks @vsravuri for the code snippet it helped me alot.

1reaction
vsravuricommented, Mar 31, 2022

@amrsa1 Yes, Here is the code

playwright.config

reporter: [
            ['list'],
            ['html', {outputFolder: process.env.PLAYWRIGHT_HTML_REPORT, open: "never"}],
            ['./pw_reporter.js']
        ],

custom reporter.js

// pw-reporter.js
// @ts-check

const fs = require('fs');
const path = require('path');
const {exec} = require('child_process');
const zipAFolder = require('zip-a-folder');
const waitOn = require('wait-on');

/** @implements {import('@playwright/test/reporter').Reporter} */
class CustomReporter {

   async onEnd(result) {
        console.log(`Finished the run: ${result.status}`);
        let htmlResDir = path.resolve(process.env.PLAYWRIGHT_HTML_REPORT);

       const opts = {
           resources: [
               allureResultsDir,
               htmlResDir
           ],
           delay: 1000, // initial delay in ms, default 0
           interval: 250, // poll interval in ms, default 250ms
           simultaneous: 1, // limit to 1 connection per resource at a time
           timeout: 60000, // timeout in ms, default Infinity
       };

       try {
           await waitOn(opts);
           // once here, all resources are available
       } catch (err) {
           console.log(err);
       }

       if (fs.existsSync(htmlResDir)) {
           let zip =  await this.fn_htmlResDir(htmlResDir);
           console.log("Custom Reporter : HTML Results directory exist. HTML Results directory is compressed");
       } else {
           console.log("Custom Reporter : HTML Results directory doesn't exist. HTML Results directory not compressed");
       }

    }

    async fn_htmlResDir(htmlResDir) {
        await zipAFolder.zip(htmlResDir,  process.env.htmlZip);
        return process.env.htmlZip;
    }

}

module.exports = CustomReporter;
Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced: configuration | Playwright - CukeTest
Global setup and teardown​​ To set something up once before running all tests, use globalSetup option in the configuration file. Global setup file...
Read more >
Important changes (deprecations) coming in Power Apps and ...
Microsoft Dataverse (legacy) connector (CDS 2.0 connector) for Power Automate flows will be deprecated and replaced with another connector.
Read more >
Bug descriptions — spotbugs 4.7.3 documentation
Invoking System.exit shuts down the entire Java virtual machine. ... FALSE), but it is possible to create other Boolean objects using the new...
Read more >
Bug listing with status RESOLVED with resolution FIXED as at ...
Bug listing with status RESOLVED with resolution FIXED as at 2022/12/24 19:46:07 ... Bug:1551 - "New version of util-linux including international support" ...
Read more >
Version control concepts and best practices
A low-tech solution is to revert your changes with hg revert or the analogous command for other version control systems, as described above....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found