Video Reporting Through API

Class library usage, coding and language questions.
thenutter
Certified Professional
Certified Professional
Posts: 7
Joined: Wed Jun 05, 2013 11:40 am

Video Reporting Through API

Post by thenutter » Wed Aug 18, 2021 2:27 pm

Hi All,

I can't find a post on this so thought I'd ask!

I'm currently using Ranorex through the API, and I'd like to use the Video Reporting functionality but can't see where to activate/setup.

I've used the Video Reporting within the studio and it was fantastic and saved us lots of time when investigating!

https://www.ranorex.com/blog/video-reporting/

I'd like to trigger the recording, and upon a failure save the screen recording.

I've looked In Ranorex.Host.Local but can't see anything obvious.

Any help would be much appreciated!

Thanks :D

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Video Reporting Through API

Post by odklizec » Wed Aug 18, 2021 2:37 pm

Hi,

Have you checked Ranorex.Core.Reporting in Ranorex API doc? There are mentioned some methods, related to video recordings:
https://www.ranorex.com/Documentation/R ... orting.htm
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

thenutter
Certified Professional
Certified Professional
Posts: 7
Joined: Wed Jun 05, 2013 11:40 am

Re: Video Reporting Through API

Post by thenutter » Fri Aug 20, 2021 3:25 pm

Thanks for the reply!

I've looked at the API usage for this and there doesn't seem to be a way to use this API without the studio and it seems bound to the Studio activity stack.

It could be I'm missing something, would be good for Ranorex to comment on this.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Video Reporting Through API

Post by odklizec » Mon Aug 23, 2021 12:49 pm

Hi,

According to support, with proper references, it should be possible to use video reporting via API even without the Studio. If you are unable to make it working, please create a support query and eventually send them a sample project with your Video Reporting implementation.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

jon318
Posts: 2
Joined: Tue Aug 31, 2021 8:27 pm

Re: Video Reporting Through API

Post by jon318 » Tue Oct 19, 2021 8:00 pm

Hi,

our test team is trying to use Video Report via API in C# without Ranorex Studio. but I can't find any examples with this API. I knew that there is public online API docs available at https://www.ranorex.com/Documentation/R ... orting.htm. By the way, my company bought a few of floating licenses in recent months.

Could you please provide this support to me ASAP, such as an example usage with this API in C#?

Thanks a lot in advance.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Video Reporting Through API

Post by odklizec » Thu Oct 21, 2021 7:42 am

Hi,

I'm afraid, I'm not using Ranorex API outside Ranorex and this particular part of API is completely unknown to me. So your best chance is to create a support ticket here:
https://www.ranorex.com/support-query/
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

User avatar
Aracknid
Posts: 388
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

Re: Video Reporting Through API

Post by Aracknid » Tue Dec 13, 2022 5:50 pm

A long time ago I wrote some code to record a video using similar code Ranoerx was using, and I wrote this and it worked for me... There might be an easier way now, but I don't really use this much. It mostly worked as far as I could remember. It's VB code, but I'm sure easy enough to convert to C#. Note that Autoweb is my own logging object, so you can ignore that.
    Private oVideoRecordingProcess As New Process()

    Private Function StartRecordingVideo(ByRef sVideoFile As String) As Boolean

        Dim lFootprint As String = "Module: " & mcs_ModuleName & ", Function: " & (New StackFrame()).GetMethod.Name & " :: "

        Dim sPathToFFMpeg As String = "C:\Program Files (x86)\Ranorex\Studio\Bin\ffmpeg.exe"
        Dim iFrameRate As Integer = 30
        Dim iBitRate As Integer = 1000
        Dim iX As Integer = My.Computer.Screen.Bounds.X
        Dim iY As Integer = My.Computer.Screen.Bounds.Y
        Dim iWidth As Integer = My.Computer.Screen.Bounds.Width
        Dim iHeight As Integer = My.Computer.Screen.Bounds.Height
        Dim sPathToVideoFolder As String = "\\qa\automation\Ranorex Videos\"
        Dim sFileName As String

        Dim str As String

        'gsScriptName is a global string that stores my scripts name
        'JobNumber is created at the time I run my script, and is a unique long number for this script
        sFileName = String.Format("{0}_{1}.mkv", gsScriptName, JobNumber.ToString)
        sVideoFile = sPathToVideoFolder & sFileName

        'Validate that the location to find ffmpeg is valid
        If Not My.Computer.FileSystem.DirectoryExists(sPathToVideoFolder) Then
            Autoweb.logError(lFootprint & String.Format("Path to video folder cannot be accessed: '{0}'", sPathToVideoFolder))
            Return False
        End If

        'Validate that the location to save videos is valid
        If Not My.Computer.FileSystem.FileExists(sPathToFFMpeg) Then
            Autoweb.logError(lFootprint & String.Format("ffmpeg cannot be found in '{0}'.", sPathToFFMpeg))
            Return False
        End If

        'Ripped from Ranorex (I don't remember how I got this exactly, but I think I decompiled a DLL):
        'ffmpeg.exe -y -framerate 15 -offset_x 0 -offset_y 0 -video_size 1152x864 -f gdigrab -i desktop -profile:v main -level 4.0 -pix_fmt yuv420p -preset:v superfast -b:v 1000k -c:v libx264 -tune animation ""fileName""

        str = String.Format("-y -framerate {0} -offset_x {1} -offset_y {2} -video_size {3}x{4} -f gdigrab -i desktop -profile:v main -level 4.0 -pix_fmt yuv420p -preset:v superfast -b:v {5}k -c:v libx264 -tune animation ""{6}{7}""", iFrameRate.ToString, iX.ToString, iY.ToString, iWidth.ToString, iHeight.ToString, iBitRate.ToString, sPathToVideoFolder, sFileName)

        Dim oStartInfo As New ProcessStartInfo(sPathToFFMpeg, str)
        oStartInfo.UseShellExecute = True

        oVideoRecordingProcess.StartInfo = oStartInfo
        oVideoRecordingProcess.Start()

        Return True

    End Function
	
    Private Sub StopRecordingVideo(sVideoFile As String, bDeleteVideo As Boolean)

        Dim lFootprint As String = "Module: " & mcs_ModuleName & ", Function: " & (New StackFrame()).GetMethod.Name & " :: "

        Ranorex.Delay.Seconds(3)

        Try
            oVideoRecordingProcess.StandardInput.Write("q")
            oVideoRecordingProcess.StandardInput.Flush()
        Catch ex As Exception
            oVideoRecordingProcess.Kill()
        End Try

        Try
            If Not oVideoRecordingProcess.WaitForExit(3000) Then
                oVideoRecordingProcess.Kill()
            End If
        Catch ex As Exception
        End Try

        'Need to wait after killing ffmpeg for file handle to be released
        Ranorex.Delay.Seconds(5)

        If bDeleteVideo Then
            Try
                My.Computer.FileSystem.DeleteFile(sVideoFile)
            Catch ex As Exception
                Ranorex.Delay.Seconds(10)
                Try
                    My.Computer.FileSystem.DeleteFile(sVideoFile)
                Catch ex2 As Exception
                    Autoweb.logError(lFootprint & "Failed to delete the video. Will continue.")
                End Try
            End Try
        End If

    End Sub

	
	
	'In my code/script startup... I have a global boolean to decide if I want to record the video or not (it gets set during some other process at startup...)
	'cSI is a class of 'Script Info' I created that tracks info about running the script. You can ignore it, but I also track if I want to delete the video here
	'I also have a global string 'gs_VideoFile' for the name of the video file.
	
	If gb_RecordVideo Then
		Autoweb.logInfo(lFootprint & "Recording a video.")
		bDeleteVideoOnPass = cSI.bDeleteVideoOnPass
		Autoweb.logInfo(lFootprint & String.Format("Delete video on pass = '{0}'", bDeleteVideoOnPass.ToString))
		If Not StartRecordingVideo(gs_VideoFile) Then
			'Since we will continue anyway, we need to reset var so that when we complete the script it doesn't try to stop and delete the video file that isn't created
			gb_RecordVideo = False
			Console.WriteLine("Failed to start video recording! We will continue without recording.")
			Autoweb.logInfo(lFootprint & "Failed to start video recording! We will continue without recording.")
		Else
			Autoweb.logInfo(lFootprint & String.Format("Video recording has been started (note only failed scripts have a video file). File saved to: {0}", gs_VideoFile))
		End If
	Else
		Autoweb.logInfo(lFootprint & "Not recording a video.")
	End If


Baxter
Posts: 11
Joined: Wed Jun 29, 2022 10:03 pm

Re: Video Reporting Through API

Post by Baxter » Mon Jul 03, 2023 5:38 am

thanks Aracknid, i kept looking online on how to use ffmpeg from the command line, but none of the suggestions worked. thank you for extracting the command from the DLL :) btw, i found not specifying the video_size was best practise to avoid issues with different VM's

ffmpeg.exe -y -framerate 15 -offset_x 0 -offset_y 0 -f gdigrab -i desktop -profile:v main -level 4.0 -pix_fmt yuv420p -preset:v superfast -b:v 1000k -c:v libx264 -tune animation c:\temp\output.mkv