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

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

Open
OlllllllO opened this issue Mar 10, 2022 · 3 comments
Open

Comments

@OlllllllO
Copy link

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

alexbradford3 commented Jul 8, 2022

Hey @OlllllllO I just ran into this problem today and well and have figured out the fix. A PR exists for this fix (#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
Copy link

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

@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.

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

No branches or pull requests

3 participants