You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cannot be cast to class io.appium.java_client.android.AndroidDriver while using EventFiringDecorator #1694
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
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
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);
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?
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')
@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
public AndroidDriver startDriver(String deviceID, String platformVersion, URL url, int systemPort) {
AndroidDriver driver = new AndroidDriver(url, capabilities, systemPort));
System.out.println("Android driver successful");
driver= (AndroidDriver) new EventFiringDecorator(new ExceptionListener()).decorate(driver);
return driver;
}
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
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());
@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 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 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);`
`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`
@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?
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.
@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.
@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
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
Activity
ChinmayPandaZee commentedon May 27, 2022
It is simillar to Cannot decorate AndroidDriver (probably the same for IOSDriver #1643 @mykola-mokhnach @SrinivasanTarget
mykola-mokhnach commentedon May 27, 2022
this is fixed in master although not yet published
ChinmayPandaZee commentedon May 27, 2022
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 commentedon May 31, 2022
Fixed and released:
io.appium:java-client:8.1.0Rabindra184 commentedon Jun 4, 2022
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')
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 commentedon Jun 6, 2022
@Rabindra184 yes, I also observed the same issue after the latest fix. Please look into this.@valfirst @mykola-mokhnach
mykola-mokhnach commentedon Jun 6, 2022
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 commentedon Jun 6, 2022
It seems this issue is similar to SeleniumHQ/selenium#9416
WillingSasi commentedon Jul 5, 2022
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 commentedon Jul 19, 2022
@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 commentedon Aug 11, 2022
@mykola-mokhnach @valfirst
Can you please check the code implementation i have done, as i am still getting error.
My exception listener class :
Driver creation class:
org.seleniumhq.selenium :4.4.0
java-client :8.1.1
appium version : 1.22.3
node version : v16.16.0
mykola-mokhnach commentedon Aug 11, 2022
This won't work. You can only cast the decorator to a particular interface rather than a class
20 remaining items
Issue fixes (#803)
sudo-naim commentedon Jan 25, 2024
Hi,
What is the update on this ticket, cause I am facing the same issue::
Exception message:
Code:
Dependencies:
bapszy commentedon Feb 28, 2024
@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 commentedon Feb 28, 2024
@bapszy https://github.com/appium/java-client/blob/master/docs/The-event_firing.md
bapszy commentedon Feb 28, 2024
@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 commentedon Feb 28, 2024
@bapszy you can address this question to Selenium
bapszy commentedon Feb 28, 2024
@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
valfirst commentedon Feb 29, 2024
@bapszy please provide full error stack trace
bapszy commentedon Feb 29, 2024
@valfirst
bapszy commentedon Feb 29, 2024
@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 commentedon Feb 29, 2024
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
executemethod matching the above payload for the given element identifier.bapszy commentedon Feb 29, 2024
@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 commentedon Mar 4, 2024
@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 commentedon Mar 18, 2024
@bapszy I am facing same issue , have you figured out the solution ?
ZhongGuan commentedon Oct 25, 2024
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