reportportal / agent-js-mocha

Agent to integrate Mocha with ReportPortal.
https://www.npmjs.com/package/@reportportal/agent-js-mocha
Apache License 2.0
15 stars 14 forks source link

Not able to log screenshots #44

Open radekBednarik opened 4 years ago

radekBednarik commented 4 years ago

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

AmsterGet commented 4 years ago

Hi @radekBednarik ! Try to completely reinstall all dependencies related to @reportportal/agent-js-mocha. We have already fixed the same issue in the @reportportal/client-javascript v5.0.2 (https://github.com/reportportal/client-javascript/releases/tag/v5.0.2).

radekBednarik commented 4 years ago

Hi @AmsterGet , npm update and clean-install did not help. However, after completely reinstalling this plugin, error is gone.

However, after the test run finishes, I do not see the screenshot in attachments of failed test cases.

image

bbung commented 3 years ago

Hi @radekBednarik

did you find a way to get this working?

radekBednarik commented 3 years ago

Hi @bbung no, I did not. And since it was in the scope of the PoC project, I just dropped it, since I got no further reaction here. Best Radek