1

Hi I have implemented Selenoid in my project and by default it names the video records like 'selenoid + browser session id.mp4', which I want to change to timestamp with scenario name.

Here's what I've done so far:

def rename_video_files(scenario, failed = false)
  Dir.glob("/end-to-end-test/test-reports/video-logs") do
    File.rename("#{page.driver.browser.session_id}.mp4", 
    "#{Time.now.strftime('%Y-%m-%d_%H-%M-%S')}_#{scenario
      .name}#{failed ? '-FAILED' : ''}.mp4"
      .gsub(/[^0-9A-Za-z.\-]/, '_'))
  end

and after hook:

After('@ui') do |scenario|
  rename_video = rename_video_files(scenario, failed = false)
  logger.info "Recorded video name: #{rename_video}.mp4"
  page.driver.quit
end

Tests pass, but the names of the video records stay unchanged.

New edit: Apparently selenoid when creates record, first names it 'selenoidxxxx.mp4' and after the test is finished renames it with session_id.mp4 by default. Therefore I'm not able to catch file name with session_id in the after step, because it's not renamed yet.

  • What is your `logger.info` actually logging? – user229044 Apr 20 '23 at 13:42
  • This is Selenoid misconfiguration. Files like `selenoidXXXX.mp4` are temporary file names that should be by default renamed to `.mp4` or to video name you provided with capabilities. – vania-pooh Apr 21 '23 at 07:18
  • @user229044 logger info should show recorded video with the name I'm trying to give. – desislava_453 Apr 21 '23 at 07:23
  • @vania-pooh Yes, I noticed that it gives temporary name selenoidxxxx.mp4. I tried capability {videoName: "timestamp.mp4"}, but then it makes video only for the first scenario and doesn't record the rest. – desislava_453 Apr 21 '23 at 07:26
  • related https://stackoverflow.com/questions/71460513/whats-selenoid-video-filename – L.R. Jun 22 '23 at 06:16

2 Answers2

0

You have to include the extension here in Dir and try again

Dir.glob("/end-to-end-test/test-reports/video-logs/*.mp4") do |file|

end
Rajagopalan
  • 5,465
  • 2
  • 11
  • 29
0

I found working solution:

The after step:

  After('not @noui') do |scenario|
    arr = Dir.glob("../test-reports/video-logs/selenoid*.mp4")
    string1 = arr.join(",")
    string2 = "../test-reports/video-logs/#{rename_video_files(scenario, failed = false)}"
    File.rename(string1, string2)
    logger.info "Recorded video name: #{string2}.mp4"
    page.driver.quit
end

and rename_video_files method:

 def rename_video_files(scenario, failed = false)
    "#{Time.now.strftime('%Y-%m-%d_%H-%M-%S')}_#{scenario
     .name}#{failed ? '-FAILED' : ''}.mp4"
     .gsub(/[^0-9A-Za-z.\-]/, '_')
 end