gauge-ts icon indicating copy to clipboard operation
gauge-ts copied to clipboard

CustomScreenshotWriter does not seem to be getting called.

Open CharlieDigital opened this issue 4 years ago • 0 comments

Describe the bug I have implemented a CustomScreenshotWriter with console.log lines in it to check whether it is being called or not.

There are no screenshots being captured and the call is not being hit based on the lack of logs.

To Reproduce

import { CustomScreenshotWriter  } from "gauge-ts";
import { join, basename } from "path";
import { scope } from "./CurrentScope";
import pw from "./PlaywrightWrapper";

/**
 * Class required to support taking screenshots on the CI/CD environment.
 * 
 * See: https://bugdiver.dev/gauge-ts/#/?id=custom-screenshots
 */
export default class ScreenshotWriter {

    /**
     * Grabs a custom screenshot using Playwright.
     * @returns A string with the name of the screenshot file.
     */
    @CustomScreenshotWriter()
    public async writeScreenShot(): Promise<string> {
        console.log("Capturing screenshot.");

        const screenshotFilePath = join(
            process.env["gauge_screenshots_dir"],
            `screenshot-${process.hrtime.bigint()}.png`);

        // Use playwright to grab the screenshot.
        await scope.page.screenshot({
            path: screenshotFilePath,
            fullPage: true
        });

        console.log(`Captured screenshot: ${screenshotFilePath}`);

        return basename(screenshotFilePath);
    }
}

I looked through the code for CustomScreenshotWriter and it seems quite straight forward so I'm not certain why no screenshot is being captured and the function is not being hit.

Playwright itself has no issues with capturing screenshots as the traces work fine.

If I uninstall the screenshots plugin, Gauge reinstalls it at runtime:

Installing required plugins.
...................
Successfully installed plugin 'screenshot' version 0.1.0

Expected behavior The console.log lines in the CustomScreenshotWriter to be hit.

Screenshots N/A

Desktop (please complete the following information):

  • OS: macOS, Linux (on CI pipeline)
  • Gauge and plugin version [run gauge -v]: 1.4.2
  • Node version [run node -v]: 16.10.0
  • Npm version [run npm -v]: 7.24.0

Full output from gauge -v:

Gauge version: 1.4.2
Commit Hash: f080fbc

Plugins
-------
dotnet (0.4.1)
html-report (4.1.2)
screenshot (0.1.0)
ts (0.1.0)
xml-report (0.2.3)

Additional context Code is not being hit when working locally due to lack of console.log. Also not being hit in the CI pipeline as the report is lacking screenshots and also lack of log messages.

CharlieDigital avatar Nov 22 '21 15:11 CharlieDigital