Skip to content

Not able to log screenshots #44

@radekBednarik

Description

@radekBednarik

Hello,
currently I have been experimenting with ReportPortal together with Playwright library running on Mocha.js.

Out-of-the-box reports are running very nice.

One big issue, which I was not able to solve, is logging screenshots. I (hopefully) followed Readme on this repo, so my approach is as follows:

I have a afterEach() hook:

         /**
         * afterEach hook - saves screenshot, if test fail
         * @function
         * @memberof HomepageTests
         */
        afterEach(async function () {
          await Reporter.logScreenshotWhenTestStatus(
            "failed",
            this,
            Homepage.page
          );
        });

And then I have created a Reporter module, like this:

const PublicReportingAPI = require("@reportportal/agent-js-mocha/lib/publicReportingAPI");

class Reporter {
  _createScreenshotObject(screenshotBuffer) {
    return {
      name: "attachment.png",
      type: "image/png",
      content: screenshotBuffer,
    };
  }

  async logScreenshotWhenTestStatus(
    expectedTestStatus,
    mochaInstance,
    pageObject
  ) {
    if (mochaInstance.currentTest.state === expectedTestStatus) {
      const screenshotBuffer = await pageObject
        .screenshot({
          type: "png",
          fullPage: true,
        })
        .then((buffer) => {
          return buffer.toString("base64");
        });

      // console.log(screenshotBuffer);

      switch (expectedTestStatus) {
        case "failed":
          PublicReportingAPI.log(
            "ERROR",
            "Test failed, full page screenshot attached.",
            this._createScreenshotObject(screenshotBuffer)
          );
          break;

        case "passed":
          PublicReportingAPI.log(
            "INFO",
            "Test passed, full page screenshot attached.",
            this._createScreenshotObject(screenshotBuffer)
          );
          break;
      }
    }
  }
}
module.exports = new Reporter();

Now, when I run tests, I will get following error to the console, test run needs to be forcefully shutdown on my side and in the dashboard as well:

Error: Request failed with status code 415: {"timestamp":1598687329559,"status":415,"error":"Unsupported Media Type","message":"Content type 'multipart/form-data;boundary=7691940154;charset=UTF-8' not supported","path":"XXXX"}
    at D:\Software Testing\Projects\tesena\playwright-playground\node_modules\@reportportal\client-javascript\lib\rest.js:31:23
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

I am 100% sure, that I have converted the screenshot buffer to base64 string.

Can you please look into this?

Also, the experimental repo is public, in case you need/want to have detailed look, see dev branch at https://github.com/Tesena-smart-testing/playwright-js-template-project.

Cheers

RB

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions