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

Detect test failures from test code? #1139

Closed
hurrymaplelad opened this issue Feb 26, 2014 · 4 comments
Closed

Detect test failures from test code? #1139

hurrymaplelad opened this issue Feb 26, 2014 · 4 comments

Comments

@hurrymaplelad
Copy link

Is there a way to detect if any test has failed from within test code?

describe('some tests', function () {
  /*
   * Run some tests...
   */
})

after(function () {
  failures = ? // <--- what goes here?
  console.log(failures + " tests failed!")
})

I'd use this to keep chromedriver's browser open if a test failed, and to report success or failure to sauce labs after tests run. I could see pulling saucelabs reporting out into a reporter using multiple reporters #930, but keeping chromedriver open makes most sense in test code, where we launch the browser.

Runner and Reporters have the info I'm looking for as stats but I'm not sure how to get to them from within a test file.

@hurrymaplelad
Copy link
Author

WD cleverly tracks each test's state in test land, and remembers if any failed. Trouble is, failures in before blocks won't hit the afterEach recording a failure, and will report pass to saucelabs...

@Whoaa512
Copy link

Also ran into this problem while creating an afterEach to take screenshots of failed tests. I think I have a decent workaround in this commit

@EndangeredMassa
Copy link

Failures in before will still call after, but not afterEach. I could really benefit from having it still call afterEach in this case.

Was this specific case intended by the symmetrical hooks change? #1043

@travisjeffery
Copy link
Contributor

there's no good way to do it within a test. but it could/should be done in a reporter.

@EndangeredMassa that's how it was written, if before fails then it doesn't make sense to run beforeEach and then it doesn't make sense to run afterEach imo.

i'm gonna close this. the multiple reporters way would be best.

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

4 participants