Skip to content

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

@Harshad3009

Description

@Harshad3009

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug 🐛first-timers-onlyIssues that are well described and directed for people that start contributing to the projectgood first picka reasonable task to start getting familiar with the code basehelp wantedIssues that are free to take by anyone interested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions