How to record device screen cross platform

I have my project set up to work cross platform by using AppiumDriver.
The problem is, unlike with screenshots, if I wish to implement screen recording I am unable to do so because the required method only exists in either IOSDriver or AndroidDriver.
I launch appium with default capabilities via scripts prior to running tests, and my understanding is that I can’t know which platform I’m on in the java code until the driver has already been instantiated and I can read the platformName capability.

If I try to cast it like so:

((IOSDriver) driver).startRecordingScreen();

I get an error:

java.lang.ClassCastException: io.appium.java_client.AppiumDriver cannot be cast to io.appium.java_client.ios.IOSDriver

Is there a way to record the screen without knowing the platform type until after the driver has been created?

Appium: 1.8.1
Java Client: 6.0.0-BETA5

There is CanRecordScreen interface, which is implemented by both drivers

1 Like

Thank you.
I was able to get the desired recording methods via a custom driver by extending AppiumDriver and implementing the CanRecordScreen interface. From there I was able to make a wrapper around startRecordingScreen that checked for the platform type first in case I needed platform specific recording options.

Actually getting this to record without an error is another thing I’m going to have to work through as documentation is still somewhat sparse.