I'd like to have video recordings of the Selenium automation at work. And then delete the recording when the tests pass.
This way whenever the tests fail we can quickly replay the video to see what went wrong. Is there a free way to capture / record the screen while the automation is running?
I'm looking for something that wouldn't take up too much of disk space. And it's something that can be controlled via the program.
4 Answers 4
You can use docker image that Selenium provides for video recording. Since you use docker images in "remote driver" manner you can use those images from python code as well.
One of the simplest ways is to use the Castro library:
c = Castro(filename = "my-cool-selenium-video.swf")
c.start()
# Run your Selenium scenario
c.stop()
Videos are saved on /tmp, so you can simply run rm -rf /tmp/my-cool-selenium-video.swf afterwards.
EDIT:
Castro is not supported in Python 3 or later. As an alternative, you can use pyscreenrec.
import pyscreenrec
recorder = pyscreenrec.ScreenRecorder()
recorder.start_recording(video_name="output.mp4")
import time
time.sleep(10)
recorder.stop_recording()
-
This library is not compatible with Python 3 and Python 2.7 is no more supported since 2020.Benjamin Loison– Benjamin Loison2024年06月28日 22:29:14 +00:00Commented Jun 28, 2024 at 22:29
-
@BenjaminLoison Thank you for pointing out. I've edited the answer with an alternative.João Farias– João Farias2024年06月30日 12:29:43 +00:00Commented Jun 30, 2024 at 12:29
-
1Thank you for updating your answer. Note that the
recorder.start_recording
argument seems to be namedvideo_name
and notoutput
.Benjamin Loison– Benjamin Loison2024年06月30日 13:47:59 +00:00Commented Jun 30, 2024 at 13:47
You can use libraries like pyautogui and numpy to write code to record screen by taking screenshots and then adding them into a video file.
I haven't tried is myself, but with a quick search on the internet I got these links that might help you,
https://www.geeksforgeeks.org/create-a-screen-recorder-using-python/
https://python-mss.readthedocs.io/examples.html#opencv-numpy
https://www.thepythoncode.com/article/make-screen-recorder-python
https://www.section.io/engineering-education/create-a-screen-recorder-using-python-and-pycharm/
https://www.techgeekbuzz.com/how-to-make-a-screen-recorder-in-python/
Try these out and if any of it works do share the solution here so that other's may also benefit from it.
In every application, where user interface testing is performed, such scenarios of recording your automation script has become a common requirement in professional automation frameworks especially when you execute an automated nightly batch. Recording of test script is performed before start of your automation script and ends at tear down followed by saving recording at your local end. The best way to accomplish this task is to use Python with Castro which is a third party library.
Castro can be installed using below simple steps -
easy_install Castro or from pip command - pip install Castro