Updating for future use.
In order to use mobile: startXCTestScreenRecording I needed to upgrade my tests to use iOS 17+ Personally I used 17.2 and 17.4 versions.
After I finished developing this feature and everything was ready for merging, I noticed something weird. My tests became slower. My tests used to take approximately 30 minutes, after upgrading to iOS 17+ the same tests(exactly same repo just the platform version was different) took over 50 minutes…
I tried to track the issue and eventually I understood that the reason is iOS 17.
As well, I saw the following on appium logs(FYI @mykola-mokhnach):
You can see that the execution of a
/click took 20 seconds. It happened too many times during the test execution and this is the reason that my tests became slower…
I could not accept this so I had to use the previous version, I used(iOS 15.5) and now I had to find a new way to make my iOS videos in the same length as they take in real life.
My solution: IOSStartScreenRecordingOptions has the ability to pass ffmpeg some filters. After doing my research I encountered the following in ffmpeg docs: setpts I used the following filter(as shown in theirs examples as well):
.withVideoFilters("setpts=(RTCTIME - RTCSTART) / (TB * 1000000)")
Where RTCTIME is the current time in milliseconds of the current frame and RTCSTART is the time in milliseconds of the first frame of the video - the rest is just to fix the ratio to match ffmpeg’s timestamp.
After doing so I managed to solve my issue and the videos were as expected but, I had a new problem. My video files became too big that I got a buffer overflow error. I solved it as well by doing the following:
- Instead of recording my whole test in one video, I recorded it in “chunks”, I used ITestListener’s onStart and onFinish methods so for each test I created a separate video.
- The above approach did not solve the problem completely so I had to scale down my videos, I used the following method of IOSStartScreenRecordingOptions:
.withVideoScale("320:-2")
It helped to reduce the video file tremendously! (see the docs for more: Scaling)
If it still would not work so I would probably try to stream my videos in real time to an S3 bucket or alternatively try to find a github project(ffmpeg wrapper or other) that allows me to record my own tests.
My current IOSStartScreenRecordingOptions instance looks like so:
BaseStartScreenRecordingOptions<?> recordingOptions = new IOSStartScreenRecordingOptions()
.withTimeLimit(Duration.ofMinutes(25))
.withFps(10)
.withVideoFilters("setpts=(RTCTIME - RTCSTART) / (TB * 1000000)")
.withVideoScale("320:-2")
.withVideoType("h264");
((CanRecordScreen) driver).startRecordingScreen(recordingOptions);
@mykola-mokhnach @Aleksei Thanks for your help!