5v1988 / appium-flutter-client

Appium Flutter Client
MIT License
3 stars 2 forks source link

Can not cast AppiumDriver to AppiumFlutterDriver #2

Closed baselalali closed 1 year ago

baselalali commented 1 year ago

I want to cast Appium Driver To AppiumFlutterDriver. I implemented this methodes:

public static AppiumFlutterDriver getAppiumFlutterDriver(AppiumDriver driver) {
        return getTargetObject(driver);
    }

    @SuppressWarnings({"unchecked"})
    private static <T> T getTargetObject(Object proxy) {
        try {
            while ((AopUtils.isCglibProxy(proxy))) {
                return getTargetObject(((Advised) proxy).getTargetSource().getTarget());
            }
            return (T) proxy;
        } catch (Exception e) {
            throw new UnproxyDriverException();
        }
    }

I get the error:

Invocation of init method failed; nested exception is java.lang.ClassCastException: class io.appium.java_client.android.AndroidDriver cannot be cast to class io.qualityplus.flutter.driver.AppiumFlutterDriver (io.appium.java_client.android.AndroidDriver and io.qualityplus.flutter.driver.AppiumFlutterDriver are in unnamed module of loader 'app')

5v1988 commented 1 year ago

When you have an ability to switch between contexts within AppiumFlutterDriver, this may not be needed at all. I will update you about the implementation shortly.

baselalali commented 1 year ago

Thank you! @5v1988 We need the following feature:

- deleteSession
- setContext
- getCurrentContext
- getContexts
- activateApp('appId')/mobile:activateApp
- mobile:activateApp has skipAttachObservatoryUrl key to not try to attach to an observatory url. e.g. driver.execute_script - 'mobile:activateApp', {skipAttachObservatoryUrl: true, appId: 'com.android.chrome'}
- terminateApp('appId')/mobile:terminateApp
- installApp(appPath, options)
- getClipboard
- setClipboard  

Please let me know, when the feature has been updated/implemented

5v1988 commented 1 year ago

We can cover contexts related cases in coming days, but other stuffs may take a couple of weeks, however, feel free to create a PR if you want to contribute to this library @baselalali

baselalali commented 1 year ago

Thank you @5v1988. The important thing we need to implement is casting from FlutterAppiumDriver to AppiumDriver, as some functions are only supported in the NativeDriver. This function would be a valuable addition.

I triefed to implement getContexts methods, but that is not work with me.

5v1988 commented 1 year ago

Hi @baselalali


- setContext
- getCurrentContext
- getContexts
- activateApp('appId')/mobile:activateApp
- mobile:activateApp has skipAttachObservatoryUrl key to not try to attach to an observatory url. e.g. driver.execute_script - 'mobile:activateApp', {skipAttachObservatoryUrl: true, appId: 'com.android.chrome'}
- terminateApp('appId')/mobile:terminateApp
- installApp(appPath, options)
- getClipboard
- setClipboard  ```
most of these commands should work in NATIVE_APP context now, and if anything, doesn't work, please help to open an another issue for those separately. Thanks