question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

afterTest hook does not execute for tests that fail with timeOut errors

See original GitHub issue

Environment (please complete the following information):

  • WebdriverIO version: 6.1.20
  • Mode: WDIO Testrunner
  • If WDIO Testrunner, running sync/async: sync
  • Node.js version: 12.18.1
  • NPM version: 6.14.5
  • Browser name and version: Chrome 83
  • Platform name and version: Ubuntu 18.04.4
  • Additional wdio packages used (if applicable): @wdio/spec reporter, @wdio/devtools-service, @wdio/mocha-framework,

Config of WebdriverIO

const debug = process.env.DEBUG
const defaultTimeout = 60000
const defaultCapabilities = [{ maxInstances: 5, browserName: 'chrome' }]
var slack = require('wdio-slack-service')
const video = require('wdio-video-reporter');
let tests = 0;

exports.config = {
    runner: 'local',
    specs: [
        './test/specs/**/*.js'
    ],
    maxInstances: debug ? 1 : 10,
    capabilities: debug ? [{ browserName: 'chrome' }] : defaultCapabilities,
    execArgv: debug ? ['--inspect'] : [],
    logLevel: 'trace',
    logLevels: {
        webdriver: 'info',
        '@wdio/applitools-service': 'silent',
        '@wdio/devtools-service': 'silent'
    },
    bail: 5,
    baseUrl: process.env.baseUrl,
    waitforTimeout: 60000,
    connectionRetryTimeout: 120000,
    connectionRetryCount: 3,
    specFileRetriesDeferred: false,
    services: ['chromedriver', 'devtools'],
    framework: 'mocha',
    reporters: [
        'spec', 
        ['allure', {
            outputDir: 'allure-results',
            disableWebdriverStepsReporting: true,
            disableWebdriverScreenshotsReporting: false,
        }]
    ],
    mochaOpts: {
        ui: 'bdd',
        timeout: debug ? (24 * 60 * 60 * 1000) : defaultTimeout
    },
    beforeTest: function (test, context) {
        browser.maximizeWindow()
    },
    afterTest: function(test, context, { error, result, duration, passed, retries }) {
        if (!passed) {
            browser.takeScreenshot();
        }
        tests++;
        console.log('----------------------------------------------')
        console.log(`No of tests: ${tests}`)
        console.log(`error is:\n${error}`)
    }
}

Describe the bug When any test fails with a timeOut error, code inside afterTest does not execute after that test. The hook does execute for tests that pass or fail with assertion errors.

To Reproduce

  1. Implement some code inside afterTest hook
tests++;
console.log('----------------------------------------------')
console.log(`No of tests: ${tests}`)
  1. Fail a test with timeOut error

Expected behavior The code inside afterTest hook should be executed after the test fails with timeOut error

Log https://gist.github.com/Harshad3009/fb0e465211ea5f48de92a483a157b315#file-logs-text

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:9
  • Comments:19 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
mhardincommented, Mar 29, 2022

Just curious if there are any updates on this? We are seeing the same issue in our test framework (‘afterTest’ hook gets skipped whenever a test times out). This is causing issues for us because we set a lot of important metadata in our afterTest hook, such as the video recording, etc.

1reaction
christian-bromanncommented, Aug 15, 2022

Aren’t the hooks async by default?

Sure, but if you do an async operation in there like saveScreenshot you have to define it as async function.

Read more comments on GitHub >

github_iconTop Results From Across the Web

webdriverio/webdriverio - Gitter
Good morning, I have 2 questions. Some of the tests failed with error: Timeout of 300000ms exceeded. For async tests and hooks, ensure...
Read more >
Getting "service failed in the on prepare hook error:appium ...
I am able to run successfully webdriverio appium project on sauce labs but when I am trying to run it locally on my...
Read more >
Configuration File | API | Docs - TestCafe
If neither file exists, TestCafe does not load any configuration files. ... TestCafe tests fail when a page yields a JavaScript error.
Read more >
afterTest hook does not execute for tests that fail with timeOut errors
afterTest hook does not execute for tests that fail with timeOut errors. webdriverio. 25 June 2020 Posted by Harshad3009. Environment (please complete the ......
Read more >
Debug BrowserStack Automate idle timeout error
If a test session does not receive the next test command after running the earlier command, it waits for a maximum of 90...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found