Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to log screenshots #44

Open
radekBednarik opened this issue Aug 29, 2020 · 4 comments
Open

Not able to log screenshots #44

radekBednarik opened this issue Aug 29, 2020 · 4 comments

Comments

@radekBednarik
Copy link

radekBednarik commented Aug 29, 2020

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
Copy link
Member

AmsterGet commented Sep 11, 2020

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
Copy link
Author

radekBednarik commented Sep 12, 2020

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
Copy link

bbung commented Nov 13, 2020

Hi @radekBednarik

did you find a way to get this working?

@radekBednarik
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants