Screenshots and Recordings in Katalon Studio

Yes, you can automate the process of recording your Katalon Studio test executions by combining Katalon Studio with a screen recording tool that supports command-line options. Here’s a general approach to achieve this:

Note: this was created and tested using Windows 11 and Katalon 8.6.

1. Use OBS Studio with Katalon Studio:

OBS Studio is a popular open-source screen recording software that can be automated using scripts and command-line arguments. You can integrate this with Katalon Studio so that OBS starts recording automatically when you run your automation test.

Steps to Automate Recording with OBS Studio:

  1. Install OBS Studio:
  2. Set Up OBS Studio:
    • Open OBS and configure your scene for screen recording (e.g., select Display Capture).
    • Save your settings.
  3. Use Command-Line Options in OBS: OBS can be controlled via the command line. To start and stop recording automatically, use the following commands:
    • To start recording: bash Copy code obs64.exe --startrecording --minimize-to-tray
    • To stop recording: bash Copy code obs64.exe --stoprecording
  4. Create Custom Katalon Test Listener: In Katalon Studio, you can use a Test Listener to execute commands before and after test execution. This way, you can automatically start and stop OBS recording when a test starts and ends.
    • Go to the Test Listeners section in Katalon Studio and create a new listener.
    • Add the following code to start recording before the test:

      import com.kms.katalon.core.annotation.BeforeTestCase
      import com.kms.katalon.core.context.TestCaseContext

      class TestListener {
      @BeforeTestCase
      def startRecording(TestCaseContext testCaseContext) {
      def command = "cmd /c start obs64.exe --startrecording --minimize-to-tray"
      Runtime.getRuntime().exec(command)
      }
      }

    • Add the following code to stop recording after the test:

      import com.kms.katalon.core.annotation.AfterTestCase
      import com.kms.katalon.core.context.TestCaseContext

      class TestListener {
      @AfterTestCase
      def stopRecording(TestCaseContext testCaseContext) {
      def command = "cmd /c start obs64.exe --stoprecording"
      Runtime.getRuntime().exec(command)
      }
      }

  5. Run the Test:
    • When you run your Katalon Studio test, the custom test listener will trigger the start and stop commands for OBS, automatically recording your test execution.

2. Use ffmpeg for Automated Screen Recording:

You can also use ffmpeg, a powerful command-line tool for video recording, to automate the process. Like OBS, ffmpeg can be triggered with Katalon’s Test Listeners.

  1. Install ffmpeg:
  2. Set Up ffmpeg Command:
    • To start recording using ffmpeg, use a command like this: bash Copy code ffmpeg -y -f gdigrab -framerate 30 -i desktop output.mp4
    • To stop recording, you need to kill the process. This can be automated via Test Listeners, similar to OBS.
  3. Integrate ffmpeg with Katalon Studio:
    • In the Test Listeners in Katalon, you can execute the ffmpeg command to start and stop the recording as part of the test lifecycle.
      Example Test Listener implementation:

      import com.kms.katalon.core.annotation.BeforeTestCase
      import com.kms.katalon.core.annotation.AfterTestCase
      import com.kms.katalon.core.context.TestCaseContext

      class TestListener {
      Process ffmpegProcess

      @BeforeTestCase
      def startRecording(TestCaseContext testCaseContext) {
      def command = ["ffmpeg", "-y", "-f", "gdigrab", "-framerate", "30", "-i", "desktop", "output.mp4"]
      ProcessBuilder pb = new ProcessBuilder(command)
      pb.redirectErrorStream(true)
      ffmpegProcess = pb.start()
      println "FFmpeg started for recording..."
      }

      @AfterTestCase
      def stopRecording(TestCaseContext testCaseContext) {
      if (ffmpegProcess != null && ffmpegProcess.isAlive()) {
      ffmpegProcess.destroy()
      ffmpegProcess.destroyForcibly()
      println "FFmpeg stopped recording."
      }
      }
    • You can make recordings unique for each test case by saving them with the test case name:

      @BeforeTestCase
      def startRecording(TestCaseContext testCaseContext) {
      def testName = testCaseContext.getTestCaseId().replaceAll("[^a-zA-Z0-9-_]", "_")
      def outputFile = "recordings/${testName}.mp4"
      new File("recordings").mkdirs()

      def command = ["ffmpeg", "-y", "-f", "gdigrab", "-framerate", "30", "-i", "desktop", outputFile]
      ProcessBuilder pb = new ProcessBuilder(command)
      pb.redirectErrorStream(true)
      ffmpegProcess = pb.start()
      }

With either OBS Studio or ffmpeg, you can automatically record your test execution in Katalon Studio, making debugging and sharing test runs much easier.