codeceptjs / CodeceptJS

Supercharged End 2 End Testing Framework for NodeJS
http://codecept.io
MIT License
4.11k stars 723 forks source link

Selenoid plugin does not attach video to Allure report in v3 #2473

Closed jancorvus closed 12 months ago

jancorvus commented 4 years ago

What are you trying to achieve?

Run tests with Selenoid and Allure plugins enabled in the version 3.0.0-beta.4

What do you get instead?

Error

Error processing test.passed event:
Error: ENOENT: no such file or directory, open '/Users/user/e2e/output/video/scenario_name@tag1_@tag2.mp4'
    at Object.openSync (fs.js:462:3)
    at Object.readFileSync (fs.js:364:35)
    at videoSaved (/Users/user/e2e/node_modules/codeceptjs/lib/plugin/selenoid.js:263:46)
    at EventEmitter.<anonymous> (/Users/user/e2e/node_modules/codeceptjs/lib/plugin/selenoid.js:245:32)
    at EventEmitter.emit (events.js:327:22)
    at EventEmitter.emit (domain.js:485:12)
    at Object.emit (/Users/user/e2e/node_modules/codeceptjs/lib/event.js:143:28)
    at /Users/user/e2e/node_modules/codeceptjs/lib/scenario.js:59:17

Details

codeceptVersion:  "3.0.0-beta.4"
nodeInfo:  13.11.0
osInfo:  macOS 10.15.4
cpuInfo:  (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
chromeInfo:  83.0.4103.116
edgeInfo:  Not Found
firefoxInfo:  Not Found
safariInfo:  13.1
helpers:  {
 "ChaiWrapper": {
  "require": "codeceptjs-chai"
 },
 "FileSystem": {},
 "REST": {
  "timeout": 40000
 },
 "WebDriver": {
  "host": "localhost",
  "url": "http://localhost",
  "path": "/wd/hub",
  "browser": "chrome",
  "port": 4444,
  "restart": true,
  "keepBrowserState": false,
  "keepCookies": false,
  "windowSize": "1440x900",
  "timeouts": {
   "script": 30000,
   "page load": 30000
  },
  "desiredCapabilities": {
   "chromeOptions": {
    "prefs": {
     "profile": {
      "default_content_settings": {
       "popups": 0
      },
      "default_content_setting_values": {
       "automatic_downloads": true
      }
     },
     "download": {
      "default_directory": "/Users/user/e2e/output",
      "prompt_for_download": false
     }
    },
    "extensions": [],
    "args": [
     "--disable-gpu",
     "--no-sandbox",
     "--disable-background-mode",
     "--disable-infobars",
     "--ignore-certificate-errors"
    ]
   }
  },
  "coloredLogs": true
 }
}
plugins:  {
 "screenshotOnFail": {
  "enabled": true
 },
 "retryFailedStep": {
  "enabled": true
 },
 "pauseOnFail": {
  "enabled": false
 },
 "stepByStepReport": {
  "enabled": false,
  "screenshotsForAllureReport": true,
  "ignoreSteps": [
   "wait*"
  ]
 },
 "allure": {
  "enabled": true,
  "outputDir": "allureResults"
 },
 "selenoid": {
  "enabled": false,
  "deletePassed": false,
  "autoCreate": true,
  "autoStart": true,
  "sessionTimeout": "10m",
  "enableVideo": true,
  "enableLog": true,
  "enableVnc": true,
  "videoScreenSize": "1460x920"
 },
 "autoDelay": {
  "enabled": true
 },
 "wdio": {
  "enabled": true,
  "services": [
   "selenium-standalone"
  ],
  "seleniumArgs": {
   "drivers": {
    "chrome": {
     "version": "83.0.4103.39"
    },
    "firefox": {
     "version": "0.24.0"
    }
   }
  },
  "seleniumInstallArgs": {
   "baseURL": "https://selenium-release.storage.googleapis.com",
   "drivers": {
    "chrome": {
     "version": "83.0.4103.39"
    },
    "firefox": {
     "version": "0.24.0"
    }
   }
  }
 }
}
jancorvus commented 4 years ago

@Vorobeyko The video file turned out to be not yet renamed by the time of reading. Its name is <browser_session>.mp4. And this bug does not display on all environments. It was on CI agents only for me. It may be too fast or too slow for the relation between the framework and Selenoid. Some waiter should be added before

allureReporter.addAttachment('Video', fs.readFileSync(path.join(global.output_dir, 'video', fileName)), 'video/mp4');
GSasu commented 4 years ago

the file never gets renamed if restart: false is used in the config. Instead what happens is that the video gets overwritten by each new test starting so it is only renamed when the tests finish so if you ran 10 tests you will have only one video for the last test that ran

jancorvus commented 4 years ago

@GSasu yes, it's a known behavior. My config has restart set to true. So, no issues with that, each video file is created per test.

jancorvus commented 4 years ago

So, adding a waiter does not help. The renaming itself happens when the next test has started. Even if I call allureReporter.addAttachment by then, the video gets attached to the running test but not to the previous one the video belongs to. And if I use a blocking sleep/delay, the renaming does not happen at all until the waiter is over time. I wonder when the renaming by Selenoid happens? on what event? how can we bind to it in the framework?

jancorvus commented 4 years ago

ok. I circumvented the issue by creating a script that attaches selenoid videos to the Allure XML when the whole suite is over. And I had to put waits in the script since by the end of a suite, last videos are still being renamed by Selenoid. The last video can be renamed in 5-10 secs after the suite is finished.

andrerleao commented 3 years ago

ok. I circumvented the issue by creating a script that attaches selenoid videos to the Allure XML when the whole suite is over. And I had to put waits in the script since by the end of a suite, last videos are still being renamed by Selenoid. The last video can be renamed in 5-10 secs after the suite is finished.

Hi @jancorvus I have the same problem, the video never adds to the Allure Report. And all test videos that have passed are never deleted.

Can you send to me, your solution to circumvent the issue.

andrerleao commented 3 years ago

Hi, I think I understand what happens, but I have no idea how to fix it.

Initially, we have a docker container running only Selenium on port 4444, I will named this container “selenoid”.

When Codeceptjs creates a new Selenium session, in Docker will happen:

1 - The Container “selenoid”, will create a new container, for example the chromedriver, I will named this container “selenoid/vnc_chrome”.

2 - If the video is active, the container “selenoid/vnc_chrome”, will create a new container for recording the video, I will named this container “video recorder”, this last container is responsible for recording and renaming the video. It is active while the “selenoid/vnc_chrome” container is running.

So, when codeceptjs deletes the Selenium session, in Docker will happen:

1 - The “video recorder” container will finish recording the video and rename, finishing up the container at last. 2 - Container “selenoid/vnc_chrome” is finished.

Then, the problem is that, we will only have the video, after the session in the selenium is deleted, and this occurs when everything is over, consequently, we have no more test running and allure will fail to add the attachments.

The same problem occurs with the deletion of videos from the tests that passed.

I hope I helped in analyzing the problem

best regards.

kobenguyent commented 12 months ago

allure plugin is now maintained by allure team https://github.com/allure-framework/allure-js/tree/master/packages/allure-codeceptjs