QualityOps / wdio-timeline-reporter

34 stars 19 forks source link

Screenshot taken when test passes, while config is set to "on:error" #59

Open OlllllllO opened 2 years ago

OlllllllO commented 2 years ago

A screenshot is taken when the test passes.

// wdio.conf.js

  reporters: [
    'spec',
    [
      'timeline',
      {
        outputDir: './report',
        fileName: 'results.html',
        embededImages: true,
        screenshotStrategy: 'on:error',
      },
    ],
  ],

// wdio-0-0-timeline-reporter.log

"suites": [
    {
      "title": "About Information",
      "duration": 32540,
      "start": "2022-03-10T05:23:32.894Z",
      "end": "2022-03-10T05:24:05.434Z",
      "tests": [
        {
          "title": "loads successfully terms and conditions and privacy policy",
          "start": "2022-03-10T05:23:32.894Z",
          "end": "2022-03-10T05:24:05.433Z",
          "duration": 32539,
          "state": "passed",
          "screenshots": [
            "/Users/$USER/Projects/report/file-1646889846638.jpeg"
          ]
        }
      ],
      "hooks": []
    }
  ],
alexbradford3 commented 2 years ago

Hey @OlllllllO I just ran into this problem today and well and have figured out the fix. A PR exists for this fix (https://github.com/QualityOps/wdio-timeline-reporter/pull/51) but has not been reviewed or merged

Update ./node_modules/wdio-timeline-reporter/build/timeline-service.js at line 82

afterTest(test, context, { error, result, duration, passed, retries }) {
    const { screenshotStrategy } = this.reporterOptions;
    if (screenshotStrategy === BEFORE_CLICK) {
        browser.takeScreenshot();
    }
    if (screenshotStrategy === ON_ERROR && !passed) {
        browser.takeScreenshot();
    }
}

The issue is that the current code only passes the test object into afterTest(). This does not contain any information on if the test passed or failed. That is contained in the 3rd parameter object. So by adding those parameters to the method and updating the if statement we can correctly determine if the test was successful or not.

ansarise commented 1 year ago

@alexbradford3 Did you get any update on the above situation. I did the change you have mentioned above, but still it is not working as expected. I am facing the similar situation where it takes screenshot after the test even though I had set the screenshotStrategy to on:error

alexbradford3 commented 1 year ago

@ansarise I never received an update but I did fork this repo, make the change, and published it on NPM. I'm using this version and able to set up my automation to use the "on:error: screenshot strategy. You can find it on my profile. Feel free to try using it and see if it resolves your issues.