appium / java-client

Java language binding for writing Appium Tests, conforms to W3C WebDriver Protocol
Apache License 2.0
1.22k stars 760 forks source link

cannot be cast to class io.appium.java_client.android.AndroidDriver while using EventFiringDecorator #1694

Closed ChinmayPandaZee closed 2 years ago

ChinmayPandaZee commented 2 years ago

Description

I'm trying to use the decorator mechanism provided by selenium 4. But following the doc to decorate the android driver, I get the exception

java.lang.ClassCastException: class jdk.proxy2.$Proxy22 cannot be cast to class io.appium.java_client.android.AndroidDriver (jdk.proxy2.$Proxy22 is in module jdk.proxy2 of loader 'app'; io.appium.java_client.android.AndroidDriver is in unnamed module of loader 'app')

Environment

Java client build version or git revision if you use some snapshot: 8.0.0 Appium server version or git revision if you use some snapshot: 1.22.3 Desktop OS/version used to run Appium if necessary: Mac Monterey Node.js version (unless using Appium.app|exe) or Appium CLI or Appium.app|exe: Appium.exe Mobile platform/version under test: android Real device or emulator/simulator: Both

Details

Please provide more details, if necessary.

Code To Reproduce Issue [ Good To Have ]

AndroidDriver driver = new AndroidDriver(url, driverCapabilities); driver=(AndroidDriver) new EventFiringDecorator(new MyLIstner()).decorate(driver);

SImilar to Cannot decorate AndroidDriver (probably the same for IOSDriver #1643

ChinmayPandaZee commented 2 years ago

It is simillar to Cannot decorate AndroidDriver (probably the same for IOSDriver #1643 @mykola-mokhnach @SrinivasanTarget

mykola-mokhnach commented 2 years ago

this is fixed in master although not yet published

ChinmayPandaZee commented 2 years ago

Is there any workaround for the time being?

I am getting below exception which need to be handled from listeners. org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: 'POST /element' cannot be proxied to UiAutomator2 server because the instrumentation process is not running (probably crashed). Check the server log and/or the logcat output for more details @mykola-mokhnach

valfirst commented 2 years ago

Fixed and released: io.appium:java-client:8.1.0

Rabindra184 commented 2 years ago

I think the below line still not working after the fix as well. AndroidDriver driver = new AndroidDriver(url, driverCapabilities); driver=(AndroidDriver) new EventFiringDecorator(new MyLIstner()).decorate(driver); Error: ava.lang.ClassCastException: class net.bytebuddy.renamed.java.lang.Object$ByteBuddy$ulOI0ra9 cannot be cast to class io.appium.java_client.android.AndroidDriver (net.bytebuddy.renamed.java.lang.Object$ByteBuddy$ulOI0ra9 is in unnamed module of loader net.bytebuddy.dynamic.loading.ByteArrayClassLoader @42b6d0cc; io.appium.java_client.android.AndroidDriver is in unnamed module of loader 'app')

at runners.installApk.setUp(installApk.java:47)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)
at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:62)
at org.testng.internal.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:385)
at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:321)
at org.testng.internal.TestInvoker.runConfigMethods(TestInvoker.java:700)
at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:527)
at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:173)
at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:824)
at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:146)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at org.testng.TestRunner.privateRun(TestRunner.java:794)
at org.testng.TestRunner.run(TestRunner.java:596)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:377)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:371)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:332)
at org.testng.SuiteRunner.run(SuiteRunner.java:276)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1212)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1134)
at org.testng.TestNG.runSuites(TestNG.java:1063)
at org.testng.TestNG.run(TestNG.java:1031)
at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66)
at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:109)

code: WebDriver original = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities); AppiumListener listener = AppiumListener.getAppiumListener(); AndroidDriver decorated = (AndroidDriver)new EventFiringDecorator(listener).decorate(original); System.out.println(decorated);

ChinmayPandaZee commented 2 years ago

@Rabindra184 yes, I also observed the same issue after the latest fix. Please look into this.@valfirst @mykola-mokhnach

mykola-mokhnach commented 2 years ago

The decorator code is completely inherited from Selenium API. @diemol @titusfortner Do you know about any changes that happened recently and may cause the above error?

valfirst commented 2 years ago

It seems this issue is similar to https://github.com/SeleniumHQ/selenium/issues/9416

WillingSasi commented 2 years ago

Also i meet this issue in Appium:java-client:8.1.1,the following is calling code:

WebDriverListener webDriverListener = new CustomListener(); appiumDriver = (AppiumDriver) new EventFiringDecorator(webDriverListener).decorate(appiumDriver);

Caused by: java.lang.ClassCastException: class net.bytebuddy.renamed.java.lang.Object$ByteBuddy$AuHk1O9o cannot be cast to class io.appium.java_client.AppiumDriver (net.bytebuddy.renamed.java.lang.Object$ByteBuddy$AuHk1O9o is in unnamed module of loader net.bytebuddy.dynamic.loading.ByteArrayClassLoader @6af310c7; io.appium.java_client.AppiumDriver is in unnamed module of loader 'app')

kirannailwal1 commented 2 years ago

@valfirst @mykola-mokhnach @ChinmayPandaZee @WillingSasi @Rabindra184 Have this issue fixed for you. Please update i am still facing this issue. java.lang.ClassCastException: net.bytebuddy.renamed.java.lang.Object$ByteBuddy$F6Ow9062 cannot be cast to io.appium.java_client.android.AndroidDriver

org.seleniumhq.selenium :4.3.0 java-client :8.1.1 appium version : 1.22.3 node version : v16.16.0

kirannailwal1 commented 2 years ago

@mykola-mokhnach @valfirst Can you please check the code implementation i have done, as i am still getting error.

My exception listener class :

  1. public class ExceptionListener implements WebDriverListener {
  2. @Override
  3. public void onError(Object target, Method method, Object[] args, InvocationTargetException e) {
  4. System.out.println("------------------------- Inside Exception -----------------------------");
  5. ...
  6. }
  7. }

Driver creation class:

  1. public AndroidDriver startDriver(String deviceID, String platformVersion, URL url, int systemPort) {
  2. AndroidDriver driver = new AndroidDriver(url, capabilities, systemPort));
  3. System.out.println("Android driver successful");
  4. driver= (AndroidDriver) new EventFiringDecorator(new ExceptionListener()).decorate(driver);
  5. return driver;
  6. }

it working fine till line 3, android driver is creating successfully, but at line 4 getting error. java.lang.ClassCastException: net.bytebuddy.renamed.java.lang.Object$ByteBuddy$6AyRD6Er cannot be cast to io.appium.java_client.android.AndroidDriver at com.one97.paytm.appautomation.android.GenericFunctionsAndroid.startDriver(GenericFunctionsAndroid.java:492)

org.seleniumhq.selenium :4.4.0 java-client :8.1.1 appium version : 1.22.3 node version : v16.16.0

mykola-mokhnach commented 2 years ago

driver= (AndroidDriver) new EventFiringDecorator(new ExceptionListener()).decorate(driver);

This won't work. You can only cast the decorator to a particular interface rather than a class

kirannailwal1 commented 2 years ago

@mykola-mokhnach Can you please share how i can do this casting.

Skumar489 commented 2 years ago

@mykola-mokhnach @valfirst Could you please help me with this. Am I doing it wrong? I am also getting the same java.lang.ClassCastException.

Environment org.seleniumhq.selenium :4.4.0 java-client :8.1.1 node version : v18.4.0 java: 11

TestListener is listener class which implements ITestListener,WebDriverListener.

Implementation : AndroidDriver driver = new AndroidDriver(url, capabilities); WebDriverListener listener = new TestListener(); AppiumDriver driver1 = (AppiumDriver) new EventFiringDecorator(listener).decorate(driver);

got below exception for "AppiumDriver driver1 = (AppiumDriver) new EventFiringDecorator(listener).decorate(driver);".

java.lang.ClassCastException: class net.bytebuddy.renamed.java.lang.Object$ByteBuddy$bnI49y2m cannot be cast to class io.appium.java_client.AppiumDriver (net.bytebuddy.renamed.java.lang.Object$ByteBuddy$bnI49y2m is in unnamed module of loader net.bytebuddy.dynamic.loading.ByteArrayClassLoader @4a2e1e52; io.appium.java_client.AppiumDriver is in unnamed module of loader 'app')

davudmurtazin commented 2 years ago

@mykola-mokhnach @valfirst Are there any updates? Still facing this issue.

AppiumDriver driver = new AndroidDriver(AddressConfigurator.getService(), CapabilitiesConfigurator.getAndroidLocalOptions(udid, deviceName, platformVersion)); WebDriverListener listener = new EventLogListenerNew(); driver = (AppiumDriver) new EventFiringDecorator(listener).decorate(driver);

Error: java.lang.ClassCastException: class net.bytebuddy.renamed.java.lang.Object$ByteBuddy$QE9PJjHx cannot be cast to class io.appium.java_client.android.AndroidDriver (net.bytebuddy.renamed.java.lang.Object$ByteBuddy$QE9PJjHx is in unnamed module of loader net.bytebuddy.dynamic.loading.ByteArrayClassLoader @444e6416; io.appium.java_client.android.AndroidDriver is in unnamed module of loader 'app')

org.seleniumhq.selenium :4.4.0 java-client :8.1.1 appium version : 2.0.0-beta.43 node version : v18.8.0

titusfortner commented 2 years ago

@mykola-mokhnach we've made a few changes in the past year, honestly not sure what would have caused the issue: https://github.com/SeleniumHQ/selenium/commits/trunk/java/src/org/openqa/selenium/support/decorators/WebDriverDecorator.java

@pujagani might know more.

Balasureshkumar commented 2 years ago

@mykola-mokhnach @pujagani Could you please help me with this. I am getting the same java.lang.ClassCastException.

Environment org.seleniumhq.selenium :4.4.0 java-client :8.1.1 node version : v18.4.0 java: 11

TestListener is listener class which implements ITestListener,WebDriverListener.

Implementation : AndroidDriver driver = new AndroidDriver(url, capabilities); WebDriverListener listener = new TestListener(); AppiumDriver driver1 = (AppiumDriver) new EventFiringDecorator(listener).decorate(driver);

got below exception for "AppiumDriver driver1 = (AppiumDriver) new EventFiringDecorator(listener).decorate(driver);".

java.lang.ClassCastException: class net.bytebuddy.renamed.java.lang.Object$ByteBuddy$bnI49y2m cannot be cast to class io.appium.java_client.AppiumDriver (net.bytebuddy.renamed.java.lang.Object$ByteBuddy$bnI49y2m is in unnamed module of loader net.bytebuddy.dynamic.loading.ByteArrayClassLoader @4a2e1e52; io.appium.java_client.AppiumDriver is in unnamed module of loader 'app')

pujagani commented 2 years ago

I thought I linked the commit to this issue but turns out I linked it to another issue. It was a mistake. Apologies for the same.

https://github.com/SeleniumHQ/selenium/commit/fcc549ad290d9ae13beecfd875b57178d5fcb2c5

The commit is part of the latest 4.5 Selenium release. It allows passing in the target class you want to cast to and that should no longer cause the error.

pujagani commented 2 years ago

Please refer to https://github.com/SeleniumHQ/selenium/blob/316f9738a8e2079265a0691954ca8847e68c598d/java/test/org/openqa/selenium/support/events/EventFiringDecoratorTest.java#L422 as an example.

peterf2 commented 2 years ago

Hi,

We ran into the same issue with the following environment:

Related code: (Where EventListener implements WebDriverListener.class) IOSDriver driver = new IOSDriver(url, capabilities); IOSDriver decoratedDriver = (IOSDriver) new EventFiringDecorator(new EventListener()).decorate(driver);

Error: class net.bytebuddy.renamed.java.lang.Object$ByteBuddy$x5NKFlZa cannot be cast to class io.appium.java_client.ios.IOSDriver (net.bytebuddy.renamed.java.lang.Object$ByteBuddy$x5NKFlZa is in unnamed module of loader net.bytebuddy.dynamic.loading.ByteArrayClassLoader @732b562e; io.appium.java_client.ios.IOSDriver is in unnamed module of loader 'app')

Can you please give us some help please? Thank you

pujagani commented 2 years ago

Please update your code to match the fix. Sharing an example from our test https://github.com/SeleniumHQ/selenium/blob/feed290ab31d246c2af631a0b30e4a6ff29a2cdf/java/test/org/openqa/selenium/support/events/EventFiringDecoratorTest.java#L413. Please pass in the target class you are looking to cast using the method showed above.

valfirst commented 2 years ago

@pujagani it seems the provided example won't work for IOSDriver, because it doesn't have no-arg constructor

pujagani commented 2 years ago

https://github.com/SeleniumHQ/selenium/blob/feed290ab31d246c2af631a0b30e4a6ff29a2cdf/java/test/org/openqa/selenium/support/events/EventFiringDecoratorTest.java#L414 EventFiringDecorator has the required constructor. I might be missing something here. Did you mean that IOSDriver has a constructor that Selenium does not handle? Is there a missing functionality from Selenium end? I am afraid I don't understand the issue here. IOSDriver is not a Selenium-provided driver so I am not aware of the concern. I am going to need more context around to understand this better. Please help regarding the same. Thank you!

valfirst commented 2 years ago

@pujagani please see the example below

import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.Capabilities;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.events.EventFiringDecorator;
import org.openqa.selenium.support.events.WebDriverListener;

import io.appium.java_client.ios.IOSDriver;

public class Main
{
    public static void main(String[] args) throws MalformedURLException
    {
        IOSDriver driver = new IOSDriver(new URL("http://doesnot.matter/"), new DesiredCapabilities())
        {
            @Override
            protected void startSession(Capabilities capabilities)
            {
                // Override in a sake of simplicity to avoid the actual session start
            }
        };
        WebDriverListener webDriverListener = new WebDriverListener()
        {
        };
        IOSDriver decoratedDriver = (IOSDriver) new EventFiringDecorator(IOSDriver.class, webDriverListener).decorate(
                driver);
    }
}

The result is an exception:

Exception in thread "main" java.lang.IllegalStateException: Unable to create new proxy
    at org.openqa.selenium.support.decorators.WebDriverDecorator.createProxy(WebDriverDecorator.java:342)
    at org.openqa.selenium.support.decorators.WebDriverDecorator.decorate(WebDriverDecorator.java:201)
    at Main.main(Main.java:28)
Caused by: java.lang.InstantiationException: io.appium.java_client.ios.IOSDriver$ByteBuddy$5w74hreT
    at java.base/java.lang.Class.newInstance(Class.java:636)
    at org.openqa.selenium.support.decorators.WebDriverDecorator.createProxy(WebDriverDecorator.java:340)
    ... 2 more
Caused by: java.lang.NoSuchMethodException: io.appium.java_client.ios.IOSDriver$ByteBuddy$5w74hreT.<init>()
    at java.base/java.lang.Class.getConstructor0(Class.java:3517)
    at java.base/java.lang.Class.newInstance(Class.java:623)
    ... 3 more

The reason is IOSDriver does not have no-arg constructor, which is required by:

https://github.com/SeleniumHQ/selenium/blob/ce1b3b180ec21c6d8938ef1c4b98022d128c00f7/java/src/org/openqa/selenium/support/decorators/WebDriverDecorator.java#L340

pujagani commented 2 years ago

Thank you for the details. I understand now. Appreciate @mykola-mokhnach's contribution and @valfirst's help around this issue.

peterf2 commented 2 years ago

Thank you for the quick responses & jumping on this issue! 🙏😊

mykola-mokhnach commented 2 years ago

I have prepared https://github.com/appium/java-client/pull/1790. I hope the PR could solve this issue without touching selenium deps

isitrunning commented 1 year ago

Hi, I updated to Appium java-client 8.2.1 this Friday (which contains #1790 PR), but unfortunately I'm still getting error while creating a decorated IOSDriver.

Did anyone had success in resolving this issue? Any suggestion what am I doing wrong?

Error message:

Unable to create new proxy
java.lang.IllegalStateException: Unable to create new proxy

Related code:

IOSDriver driver = new IOSDriver(remoteUrl, getDesiredCapabilities());
WebDriverListener eventListener = new WebDriverListener();
IOSDriver decorated = (IOSDriver) new EventFiringDecorator(IOSDriver.class, eventListener).decorate(driver);
mykola-mokhnach commented 1 year ago

@isitrunning this is expected. Follow https://github.com/appium/java-client/blob/master/docs/The-event_firing.md#createproxy-api-since-java-client-830 if you want to create a transparent driver proxy

isitrunning commented 1 year ago

Thank you @mykola-mokhnach, I was able to decorate the IOSDriver with your help! ☺️

Currently the beforeCall, afterCall, call, onError (from MethodCallListener) events are received. 🎉 Do you know any way to receive the beforeClick(WebElement element) event as well? Thanks!

mykola-mokhnach commented 1 year ago

WebElement is just a convenience wrapper. Eventually all commands are anyway get sent to the driver. For example, the click call gets translated into parent driver's execute call: https://github.com/SeleniumHQ/selenium/blob/b878a9911e6a38b31ebfa517d809ea3c896c4e86/java/src/org/openqa/selenium/remote/RemoteWebElement.java#L78

This means you could intercept calls to execute API and then check for the matching element id and name in the CommandPayload argument

sudo-naim commented 10 months ago

Hi, What is the update on this ticket, cause I am facing the same issue:: Exception message:

Exception message: java.lang.ClassCastException: class net.bytebuddy.renamed.java.lang.Object$ByteBuddy$pMV59rfO cannot be cast to class io.appium.java_client.android.AndroidDriver (net.bytebuddy.renamed.java.lang.Object$ByteBuddy$pMV59rfO is in unnamed module of loader net.bytebuddy.dynamic.loading.ByteArrayClassLoader @33899f7a; io.appium.java_client.android.AndroidDriver is in unnamed module of loader 'app')

Code:

AndroidDriver driver = (AndroidDriver) new EventFiringDecorator(new Listener()).decorate(webDriverBuilder.getAndroidDriver());

Dependencies:

implementation 'org.seleniumhq.selenium:selenium-java:4.17.0'
implementation 'io.appium:java-client:9.0.0'
bapszy commented 8 months ago

@isitrunning can you give me a working example for eg how to implement the beforeClick(WebElement element) listener with this MethodCallListeren? I cannot figure it out. I tried to implement this proxy, the code compiles but I'm not sure it does anything, and I didn't find any other implementation example then the one in the doc here.

valfirst commented 8 months ago

@bapszy https://github.com/appium/java-client/blob/master/docs/The-event_firing.md

bapszy commented 8 months ago

@valfirst Yes I read it and put his in my code. But how can I wire in an onClick event on a Webelement to for eg create a screenshot on every click? It was in our Eventlistener which implemented the WebDriverListener, but that does not work now

valfirst commented 8 months ago

@bapszy you can address this question to Selenium

bapszy commented 8 months ago

@valfirst I don't know how should I implement it to get it work. The MethodCallListener don't do anythink, and i cannot decorate my AndroidDriver with my Eventlistener, I get "Unable to create new proxy" error


`MethodCallListener listener = new MethodCallListener() {
            @Override
            public void beforeCall(Object target, Method method, Object[] args) {
                if (!method.getName().equals("get")) {
                    throw new NotImplementedException();
                }
                LOGGER.info("beforeCall: {}", method.getName());
            }

            @Override
            public void afterCall(Object target, Method method, Object[] args, Object result) {
                if (!method.getName().equals("get")) {
                    throw new NotImplementedException();
                }
                LOGGER.info("afterCall: {}", method.getName());
            }
        };

        AndroidDriver decoratedDriver = createProxy(
                AndroidDriver.class,
                new Object[] {new URL(remoteUrl.toString()), getDesiredCapabilities()},
                new Class[] {URL.class, Capabilities.class},
                listener
        );
//        AppiumDriver originalAppiumDriver = new AndroidDriver(remoteUrl, getDesiredCapabilities());
//        AndroidDriver driver = new AndroidDriver(remoteUrl, getDesiredCapabilities());
        WebDriverListener webDriverListener = new EventListener();
        AndroidDriver decoratedAppiumDriver = new EventFiringDecorator<>(AndroidDriver.class, webDriverListener).decorate(decoratedDriver);`
valfirst commented 8 months ago

@bapszy please provide full error stack trace

bapszy commented 8 months ago

@valfirst

`java.lang.IllegalStateException: Unable to create new proxy
                at org.openqa.selenium.support.decorators.WebDriverDecorator.createProxy(WebDriverDecorator.java:365)
                at org.openqa.selenium.support.decorators.WebDriverDecorator.decorate(WebDriverDecorator.java:203)
                at com.****.****.android.tests.AndroidBaseTest.setupEnvironment(AndroidBaseTest.java:95)
                at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
                at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.base/java.lang.reflect.Method.invoke(Method.java:566)
                at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:139)
                at org.testng.internal.invokers.MethodInvocationHelper$2.runConfigurationMethod(MethodInvocationHelper.java:453)
                at com.****.utils.BaseTest.run(BaseTest.java:48)
                at org.testng.internal.invokers.MethodInvocationHelper.invokeConfigurable(MethodInvocationHelper.java:467)
                at org.testng.internal.invokers.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:358)
                at org.testng.internal.invokers.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:296)
                at org.testng.internal.invokers.TestInvoker.runConfigMethods(TestInvoker.java:823)
                at org.testng.internal.invokers.TestInvoker.invokeMethod(TestInvoker.java:590)
                at org.testng.internal.invokers.TestInvoker.invokeTestMethod(TestInvoker.java:221)
                at org.testng.internal.invokers.MethodRunner.runInSequence(MethodRunner.java:50)
                at org.testng.internal.invokers.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:969)
                at org.testng.internal.invokers.TestInvoker.invokeTestMethods(TestInvoker.java:194)
                at org.testng.internal.invokers.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:148)
                at org.testng.internal.invokers.TestMethodWorker.run(TestMethodWorker.java:128)
                at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
                at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
                at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.InstantiationException: io.appium.java_client.android.AndroidDriver$ByteBuddy$zuLRSRXN
                at java.base/java.lang.Class.newInstance(Class.java:571)
                at org.openqa.selenium.support.decorators.WebDriverDecorator.createProxy(WebDriverDecorator.java:363)
                ... 23 more
Caused by: java.lang.NoSuchMethodException: io.appium.java_client.android.AndroidDriver$ByteBuddy$zuLRSRXN.<init>()
                at java.base/java.lang.Class.getConstructor0(Class.java:3349)
                at java.base/java.lang.Class.newInstance(Class.java:556)
                ... 24 more

io.appium.java_client.android.AndroidDriver$ByteBuddy$zuLRSRXN
java.lang.InstantiationException: io.appium.java_client.android.AndroidDriver$ByteBuddy$zuLRSRXN
                at java.base/java.lang.Class.newInstance(Class.java:571)
                at org.openqa.selenium.support.decorators.WebDriverDecorator.createProxy(WebDriverDecorator.java:363)
                at org.openqa.selenium.support.decorators.WebDriverDecorator.decorate(WebDriverDecorator.java:203)
                at com.****.****.android.tests.AndroidBaseTest.setupEnvironment(AndroidBaseTest.java:95)
                at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
                at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.base/java.lang.reflect.Method.invoke(Method.java:566)
                at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:139)
                at org.testng.internal.invokers.MethodInvocationHelper$2.runConfigurationMethod(MethodInvocationHelper.java:453)
                at com.****.utils.BaseTest.run(BaseTest.java:48)
                at org.testng.internal.invokers.MethodInvocationHelper.invokeConfigurable(MethodInvocationHelper.java:467)
                at org.testng.internal.invokers.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:358)
                at org.testng.internal.invokers.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:296)
                at org.testng.internal.invokers.TestInvoker.runConfigMethods(TestInvoker.java:823)
                at org.testng.internal.invokers.TestInvoker.invokeMethod(TestInvoker.java:590)
                at org.testng.internal.invokers.TestInvoker.invokeTestMethod(TestInvoker.java:221)
                at org.testng.internal.invokers.MethodRunner.runInSequence(MethodRunner.java:50)
                at org.testng.internal.invokers.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:969)
                at org.testng.internal.invokers.TestInvoker.invokeTestMethods(TestInvoker.java:194)
                at org.testng.internal.invokers.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:148)
                at org.testng.internal.invokers.TestMethodWorker.run(TestMethodWorker.java:128)
                at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
                at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
                at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.NoSuchMethodException: io.appium.java_client.android.AndroidDriver$ByteBuddy$zuLRSRXN.<init>()
                at java.base/java.lang.Class.getConstructor0(Class.java:3349)
                at java.base/java.lang.Class.newInstance(Class.java:556)
                ... 24 more`
bapszy commented 8 months ago

@valfirst I really want to understand how this whole thing works, maybe that would help me make it work. So exactly, what happens during test run. There is an element on the UI which I want to click, and I want to make a screenshot. When will be the MethodCallListener activated and what will it do? When is the beforeClick from Webdriver happen?

mykola-mokhnach commented 8 months ago

Read the source to understand how it works.

For example: This is the click method of a WebElement. It calls the execute method of the parent webdriver with the DriverCommand.CLICK_ELEMENT(id) payload.

This means your driver proxy must intercept invocations of the execute method matching the above payload for the given element identifier.

bapszy commented 8 months ago

@mykola-mokhnach Can you give me an exapmle code how should I implement it? I tried to understand the unit tests for this MethodCallListener proxy but something is missing, I really don't see how should I implement what you say :( I even don't get the log I put in the MethodCallListener you see above anywhere.

bapszy commented 8 months ago

@valfirst @mykola-mokhnach Please, can you give an implementation example? I still couldn't make it work, I don't understand what do you mean by "your driver proxy must intercept invocations of the execute method matching the above payload for the given element identifier" ? I need an example

viduuuur commented 8 months ago

@bapszy I am facing same issue , have you figured out the solution ?

ZhongGuan commented 4 weeks ago

Since the execute method in driver marks as protected, so I have to create a custom Driver that extends the origin one. and make the execute method public. Now I can use if (((CommandPayload)args[0]).getName().equals(DriverCommand.CLICK_ELEMENT)) in beforecall to do the same of beforeClick in WebDriverListener