Contact

Technology

Dec 14, 2023

How to Record Selenium Test Cases

Maruthi Ram Pushpala

Maruthi Ram Pushpala

How to Record Selenium Test Cases

Video recordings of Selenium test case execution can help debug issues more efficiently, and you can use the recorded videos to show test execution activities to clients or internal stakeholders. These recorded videos can also be added to the project management tool while creating bugs, which helps in understanding the bug more clearly.

Wouldn’t it be great if you could record videos of your Selenium test cases automatically? While Selenium WebDriver doesn’t have a built-in mechanism to record videos of the test cases that are executed, here’s how you can video record Selenium WebDriver test cases in six steps.

1. Download ATUTestRecorder.jar and ATUReporter_Selenium_testNG.jar.

These two jars are available on the internet, and you can simply Google to download them.

2.  Add these jar files into a project folder.

Create a folder called executables inside the project and save the jars in this folder.

Best Practices

Instead of creating a folder in any desired location of the local computer, create a folder inside the project.

Advantages

  • Avoid hard coding of the path of the folder when writing the script.

  • We can use System.getProperty("user.dir") to get the base folder path of the project which works irrespective of the location the project is saved.

3. Add ATUTestRecorder.jar and ATUReporter_Selenium_testNG.jar to the project build path.

Right-click on project >> Select "Properties" >> Select “Java Build Path” >> Select “Libraries” tab >> Click on “Add External Jars” button >> Select ATUTestRecorder.jar and ATUReporter_Selenium_testNG.jar  >> Apply >> OK.

img1 (1)

4. Create a folder to store recorded videos

Create a folder with the name ScriptVideos inside the project.

Best Practices

Instead of creating a folder in any desired location of the local computer, create a folder inside the project.

Advantages

  • Avoid hard coding of the path of the folder when writing the script. 

  • We can use System.getProperty ("user.dir") to get the base folder path of the project which works irrespective of the location the project is saved. 

5. Create and run the test.

  • Declare ATUTestRecorder in SetUp class 

/** The recorder. */ 

ATUTestRecorder recorder; 

  • Use the following code in @BeforeMethod:

img2 (1)

Best Practices

  • Use the reflection concept from Java to get the test case name and use the same for the video. This helps in identifying the video by seeing the name. 

  • Append the name of the video with the timestamp. This helps to create videos, which run multiple times without overriding the old videos. 

Use the following code in @AfterMethod:

img3 (1)

Additional things to set up when using Maven project and pom.xml

img4 (1)

6. Videos will be created with a .mov extension. You can play them to see recorded videos. 

Check the folder, which is used for the videos. We will find the test case videos with the .mov extension. These videos will be automatically named as [testcase name-timestamp].mov.

BONUS!

Do you want to delete old videos before starting an execution? 

Follow these steps:

img5 (1)

Create a method to delete the old video recordings in Utils class.

Call the method in @BeforeSuite

img6

The Bottom Line

At Credera, we instituted auto-video recording of test cases into the core automation framework and used these videos for defect tracking. This has proved its effectiveness in a few of the recent projects where the clients and the development team have a clear understanding of the issue by just watching the video. The clients were delighted with the implementation of this and pleased to experience an approach where they had a very clear understanding of the issue.

    Conversation Icon

    Contact Us

    Ready to achieve your vision? We're here to help.

    We'd love to start a conversation. Fill out the form and we'll connect you with the right person.

    Searching for a new career?

    View job openings