Skip to content
This repository has been archived by the owner on Dec 18, 2019. It is now read-only.

No way to shut off screenshots on error. #15

Open
christian-bromann opened this issue Jan 25, 2019 · 7 comments
Open

No way to shut off screenshots on error. #15

christian-bromann opened this issue Jan 25, 2019 · 7 comments
Labels
help wanted Extra attention is needed v4

Comments

@christian-bromann
Copy link
Contributor

From @pmerwin on December 30, 2017 16:55

The problem

There is no way to shut off taking a screenshot on error. We are using Try/Catch and expect errors, and do not need screenshots when that happens, as this slows down the test, and creates more possibility for something to go wrong.

Environment

  • WebdriverIO version: "webdriverio": "^4.9.9",
  • Node.js version: v6.10.3
    *testrunner
  • if wdio testrunner, running synchronous or asynchronous tests: sync
  • Additional wdio packages used (if applicable):

Details

I want to set take screenshot to false inside of try blocks, as when we get an error in a try block, wdio is still taking a screenshot. I want to turn this off/on in my function called from my tes.t

Link to Selenium/WebdriverIO logs

AVailable if needed

Code To Reproduce Issue [ Good To Have ]

available if needed, I have posted on gitter chat for any suggestions and have not received a response. Thanks in advance!

"// Saves a screenshot to a given path if a command fails.
screenshotPath: config.wdio.errors,
//

Anyone know how to shut this off at spec/function level. We use Try/Catch and don't need a screen shot when an error is expected. The only option I see to change is the above. Tried setting this to null, did not work.

Any help? Just wondering what value to set in a local function try/catch that will shut off snapshots on error as I am expecting an error and do not need a snapshot. I thought if the error happened in the try block it should not trigger a snapshot but it does."

Copied from original issue: webdriverio/webdriverio#2529

@christian-bromann christian-bromann added help wanted Extra attention is needed v4 labels Jan 25, 2019
@christian-bromann
Copy link
Contributor Author

From @pmerwin on December 30, 2017 17:4

I tried setting browser.takesScreenshot = false; but a screenshot is still taken

when I set this in the fucntion that uses the try block, the 'setting' is not rejected, but it just does not do anything :

const shouldTakeScreenshot = options.screenshotOnReject || typeof options.screenshotPath === 'string'
if (!shouldTakeScreenshot || err.shotTaken || insideCommand('screenshot', this)) {
return fail(err, onRejected)
}

I would think that should set:!shouldTakeScreenshot and it should just return with no screenshot?

Here is an example function I am trying:

I am expecting the reportTO to most likely NOT be there, so I run it in a Try and catch (err).

Why does the error bubble up out of the try block and cause a screenshot anyway?

Page.prototype.checkForReportTO = function (selector) {
browser.waitForVisible(HOME_USER.loadingBubbles.selector, 30000, true);
console.log('looking for TO');
browser.takesScreenshot = false;
let TIME_OUT_REPORT = false;
try {
// browser.takesScreenshot = false;
if (browser.waitForVisible(HOME_USER.reportTO.selector, 6000)) {
console.log('report timed out');
TIME_OUT_REPORT = true;
console.log(TIME_OUT_REPORT);
}
} catch (err) {
console.log(err);
}
if (!(TIME_OUT_REPORT)) {
browser.waitForExist(selector);
console.log(TIME_OUT_REPORT);
}
browser.takesScreenshot = true;
return TIME_OUT_REPORT;
};

@christian-bromann
Copy link
Contributor Author

From @vbyjsue on January 12, 2018 9:28

This is the workaround I'm using in v.4.8. Disables screenshot if first attempt failes, enables it for second attempt.

const currentScreenshotPath = browser.options.screenshotPath;
    try {
      browser.options.screenshotPath = null;
      browser.click(selector);
      browser.options.screenshotPath = currentScreenshotPath;
    } catch(e) {
      browser.options.screenshotPath = currentScreenshotPath;
      browser.execute(`scrollBy(0, ${yOffset})`);
      browser.click(selector);
    }

@christian-bromann
Copy link
Contributor Author

From @pmerwin on February 5, 2018 17:51

Awesome thanks, I will give this a try ^^^

@christian-bromann
Copy link
Contributor Author

From @pmerwin on February 5, 2018 18:3

That is working for me! Thanks @vbyjsue !

@christian-bromann
Copy link
Contributor Author

From @daposy on February 7, 2018 0:31

@vbyjsue thanks for sharing your solution. Its a usable workaround for now.

This issue is particularly annoying when interacting with iOS system messages. Using the documentation recommended solution for browser.alertText(), we get an error whenever an alert isn't open.

if (browser.alertText()) {
  browser.alertDismiss();
}

@christian-bromann
Copy link
Contributor Author

From @mherodev on February 14, 2018 0:9

Thanks @vbyjsue! This was also a workable solution for me.

@christian-bromann
Copy link
Contributor Author

From @worc on May 24, 2018 22:8

this issue has a wider impact when the tests are unable to create screenshots, like in this issue the screenshot failure blocks logging of the failed test case. so now i have dozens of browser instances running, no screenshots, and no way to tell which tests failed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
help wanted Extra attention is needed v4
Projects
None yet
Development

No branches or pull requests

1 participant