How to use driver.currentActivity() with AppiumDriver?

I’m working on the latest java client 3.3.0 and I see that I can use driver.currentActivity() only when the main driver set to AndroidDriver. As I’m testing IOS and Android in the same project, I need to use AppiumDriver. How I can still work with driver.currentActivity()?
can I use somthing else?
please advice.

A quick way to solve this is to cast your driver reference. In your Android-specific code sections, if you know the driver object type will be an AndroidDriver, you can cast the driver reference from the AppiumDriver type to an AndroidDriver type. Be sure that you actually are working on an AndroidDriver in the Android-specific sections, however. If you’re wrong, you will run into ClassCastExceptions, which means you should really double-check your code!

1 Like

I found this solution and it worked:
String activity = ((AndroidDriver<MobileElement>) driver).currentActivity();

1 Like

@shaychosen your solution didn’t work in my case, getting error

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

can you please share sample code which uses driver across both android and iOS native apps ?

interesting discussion on this topic for reference purpose

Have you found any solution to identify current iOS screen?