New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cannot be cast to class io.appium.java_client.android.AndroidDriver while using EventFiringDecorator #1694
Comments
It is simillar to Cannot decorate AndroidDriver (probably the same for IOSDriver #1643 @mykola-mokhnach @SrinivasanTarget |
this is fixed in master although not yet published |
Is there any workaround for the time being? I am getting below exception which need to be handled from listeners. |
Fixed and released: |
I think the below line still not working after the fix as well.
code: |
@Rabindra184 yes, I also observed the same issue after the latest fix. Please look into this.@valfirst @mykola-mokhnach |
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? |
It seems this issue is similar to SeleniumHQ/selenium#9416 |
Also i meet this issue in Appium:java-client:8.1.1,the following is calling code: WebDriverListener webDriverListener = new CustomListener(); 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 org.seleniumhq.selenium :4.3.0 |
@mykola-mokhnach @valfirst My exception listener class :
Driver creation class:
org.seleniumhq.selenium :4.4.0 |
This won't work. You can only cast the decorator to a particular interface rather than a class |
@mykola-mokhnach Can you please share how i can do this casting. |
@mykola-mokhnach @valfirst Could you please help me with this. Am I doing it wrong? Environment TestListener is listener class which implements ITestListener,WebDriverListener. Implementation : 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') |
@mykola-mokhnach @valfirst Are there any updates? Still facing this issue. AppiumDriver driver = new AndroidDriver(AddressConfigurator.getService(), 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 |
@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. |
@mykola-mokhnach @pujagani Could you please help me with this. Environment TestListener is listener class which implements ITestListener,WebDriverListener. Implementation : 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') |
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. The commit is part of the latest 4.5 Selenium release. |
Hi, We ran into the same issue with the following environment:
Related code: (Where EventListener implements WebDriverListener.class) Error: Can you please give us some help please? |
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. |
@pujagani it seems the provided example won't work for |
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! |
@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 |
Thank you for the details. I understand now. Appreciate @mykola-mokhnach's contribution and @valfirst's help around this issue. |
Thank you for the quick responses & jumping on this issue! 🙏😊 |
I have prepared #1790. I hope the PR could solve this issue without touching selenium deps |
Hi, Did anyone had success in resolving this issue? Any suggestion what am I doing wrong? Error message:
Related code:
|
@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 |
Thank you @mykola-mokhnach, I was able to decorate the Currently the |
WebElement is just a convenience wrapper. Eventually all commands are anyway get sent to the driver. For example, the This means you could intercept calls to |
* fix "screenshot not captured for failed navigation" * fix broken test * fix for appium/java-client#1694 * version bump 6.4.20221215 * fix broken tests * removing broken test
Hi,
Code:
Dependencies:
|
@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 |
@bapszy you can address this question to Selenium |
@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
|
@bapszy please provide full error stack trace |
|
@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? |
Read the source to understand how it works. For example: This means your driver proxy must intercept invocations of the |
@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 |
@bapszy I am facing same issue , have you figured out the solution ? |
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
The text was updated successfully, but these errors were encountered: