java-client icon indicating copy to clipboard operation
java-client copied to clipboard

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

Open ChinmayPandaZee opened this issue 4 years ago • 45 comments

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 avatar May 27 '22 12:05 ChinmayPandaZee

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.

mykola-mokhnach avatar Feb 29 '24 09:02 mykola-mokhnach

@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 avatar Feb 29 '24 10:02 bapszy

@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

bapszy avatar Mar 04 '24 08:03 bapszy

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

viduuuur avatar Mar 18 '24 08:03 viduuuur

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

ZhongGuan avatar Oct 25 '24 06:10 ZhongGuan