webdriverio-community / wdio-video-reporter

Reporter for WebdriverIO that makes videos of failed tests and has optional allure integration
https://webdriver.io/docs/wdio-video-reporter
MIT License
58 stars 46 forks source link

[🐛Bug]: Error in console `ENOENT: no such file or directory, open Video-reporter.log` after run tests #145

Open Oleksii-QA opened 7 months ago

Oleksii-QA commented 7 months ago

https://github.com/webdriverio/webdriverio/issues/12097#issuecomment-1912357798

WebdriverIO Version

8.20.5

Node.js Version

18.17.1

Mode

WDIO Testrunner

Which capabilities are you using?

Main config in package.json
"devDependencies": {
    "@moroo/wdio-slack-reporter": "^8.0.1",
    "@wdio/cli": "^8.16.4",
    "@wdio/local-runner": "^8.16.4",
    "@wdio/mocha-framework": "^8.16.3",
    "@wdio/spec-reporter": "^8.16.3",
    "chromedriver": "^119.0.0",
    "geckodriver": "^4.3.0",
    "wdio-chromedriver-service": "^8.1.1",
    "wdio-geckodriver-service": "^5.0.2",
    "wdio-intercept-service": "^4.4.0",
    "wdio-video-reporter": "^4.0.5"
  },
"dependencies": {
    "axios": "^1.5.1",
    "moment": "^2.29.4",
    "ws": "^8.15.0"
  }

main config in wdio.conf.js

import SlackReporter from '@moroo/wdio-slack-reporter';
import { join } from 'path';
import moment from 'moment';
import video from 'wdio-video-reporter';

export const config = {
    runner: 'local',
    maxInstances: 3,
    capabilities: [
        {
            maxInstances: 2,
            acceptInsecureCerts: true,
            specs: ['./test/specs/**.js'],
            browserName: "chrome",
            "goog:loggingPrefs": { 
                browser: "ALL",
              },
            "goog:chromeOptions": {
                args: [
                // "--start-maximized",
                "--enable-logging",
                "--headless",
                "--no-sandbox",
                "--disable-dev-shm-usage",
                "--disable-gpu",
                "--window-size=1920,1080"
              ],
              prefs: {
                download: {
                  default_directory: join(process.cwd(), "./download") 
                }
              }
            },
          }, {
                maxInstances: 1,
                //
                browserName: 'firefox',
                acceptInsecureCerts: true,
                specs: ['./test/specs/test.js'],
                "moz:firefoxOptions": {
                  args: [
                  '--width=1920', 
                  '--height=1080',
                  '-headless'
                ],
              }
    }],
    logLevel: 'info',
    bail: 0,
    outputDir: `./logs/${moment().format('YYYY-MM-DD_HH-mm')}`,
    baseUrl: 'http://localhost',
    waitforTimeout: 10000,
    connectionRetryTimeout: 120000,
    connectionRetryCount: 3,
    services: ['chromedriver', 'geckodriver', 'intercept'],
    framework: 'mocha',
    reporters: ['spec',
        [ video, {
          saveAllVideos: false,    
          videoSlowdownMultiplier: 10, 
        }],
    ],
    mochaOpts: {
        ui: 'bdd',
        timeout: 100000000
    },

What happened?

Sometimes I get this error in console and and my tests are failing. This error does not always occur. I use moment library for generate logs folder for each tests run. This is convenient when each folder has the format YYYY-MM-DD_HH-mm. Same issue in Ubuntu LTS 22.04 and Windows 10x64 for me. Currently I use 4.0.5 Wdio video reporter version. But same issue in latest version 5.1.1

Are there ways to solve this problem? Or is there an option to disable wdio-0-0-Video-reporter.log file log creation?

What is your expected behavior?

No error in console.

How to reproduce the bug.

I think need to use same configuration and run tests. Sometimes it reproduces

Relevant log output

[0-0] node:events:495
[0-0]       throw er; // Unhandled 'error' event
[0-0]       ^
[0-0] 
[0-0] Error: ENOENT: no such file or directory, open 'logs/2024-01-26_09-11/wdio-0-0-Video-reporter.log'
[0-0] Emitted 'error' event on WriteStream instance at:
[0-0]     at emitErrorNT (node:internal/streams/destroy:151:8)
[0-0]     at emitErrorCloseNT (node:internal/streams/destroy:116:3)
[0-0]     at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
[0-0]   errno: -2,
[0-0]   code: 'ENOENT',
[0-0]   syscall: 'open',
[0-0]   path: 'logs/2024-01-26_09-11/wdio-0-0-Video-reporter.log'
[0-0] }
[0-0] 
[0-0] Node.js v18.18.2
[0-0] FAILED
christian-bromann commented 7 months ago

Thanks for reporting!

We greatly appreciate any contributions that help resolve the bug. While we understand that active contributors have their own priorities, we kindly request your assistance if you rely on this bug being fixed. We encourage you to take a look at our contribution guidelines or join our friendly Discord development server, where you can ask any questions you may have. Thank you for your support, and cheers!

Oleksii-QA commented 7 months ago

@christian-bromann I investigated this issue many times. And I think I found the reason.

First, logs are created: wdio.log, wdio,browser.log, drivers log(chromedriver, geckodriver) after 2 second logs are created: Video-reporter.log and rawSeleniumVideoGrabs folder

That's why I think there were cases with bug; Test run in 58-59 second of some minute, and wdio-0-0-Video-reporter.log could not be created, since the next minute had already arrived

I have added a temporary solution in wdio.conf.js, like:

import fs from 'fs'

const logsPath = './logs';
const folderName = moment().format('YYYY-MM-DD_HH-mm');
const folderPath = `${logsPath}/${folderName}`;
fs.mkdirSync(folderPath, { recursive: true });
const allFolders = fs.readdirSync(logsPath);
const sortedFolders = allFolders.sort((a, b) => {
    return fs.statSync(`${logsPath}/${b}`).ctime.getTime() - fs.statSync(`${logsPath}/${a}`).ctime.getTime();
});
const latestFolder = sortedFolders[0];
console.log('Latest test folder', latestFolder);

export const config = {

outputDir: `${logsPath}/${latestFolder}`,

In this case, the log folder will be created before each test run.

I think the permanent solution would be to create logs at the same time. Or need to look for other options.

christian-bromann commented 7 months ago

Test run in 58-59 second of some minute, and wdio-0-0-Video-reporter.log could not be created, since the next minute had already arrived

So the reports are being overwritten by another test?

Oleksii-QA commented 7 months ago

So the reports are being overwritten by another test?

In this case, the file is not created and the test fails

christian-bromann commented 7 months ago

How does the test fail due to a non existing log file?

Oleksii-QA commented 7 months ago

How does the test fail due to a non existing log file?

In this case, I think the error was not that the file does not exist. The problem is that it tried to create a log file in a non-existent folder.

christian-bromann commented 7 months ago

Ah, I think this can be fixed. All contributions would be appreciated!