appium / java-client

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

Hitting org.openqa.selenium.UnsupportedCommandException: getCurrentContextHandle when doing driver.getContext() with java-client 4.21.0 #2234

Open helenren opened 1 month ago

helenren commented 1 month ago

Description

After this change on Java-client: https://github.com/appium/java-client/pull/2093 and on Selenium side: https://github.com/SeleniumHQ/selenium/commit/1b66415adf2bcce266d5acdd457378c4e6d07340. Our test fail when doing getContext().

Environment

Details

Stack Trace:

at org.openqa.selenium.remote.codec.AbstractHttpCommandCodec.encode(AbstractHttpCommandCodec.java:237) at org.openqa.selenium.remote.codec.AbstractHttpCommandCodec.encode(AbstractHttpCommandCodec.java:111) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:178) at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:237) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:518) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:591) at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:307) at io.appium.java_client.remote.SupportsContextSwitching.getContext(SupportsContextSwitching.java:78)

With debug, I noticed that nameToSpec does not include any mobile-specific commands because of the change: https://github.com/SeleniumHQ/selenium/commit/1b66415adf2bcce266d5acdd457378c4e6d07340. While, change: https://github.com/appium/java-client/pull/2093 added that mobile command in the MobileCommand class, but the commands in commandRepository have not been injected. Therefore AbstractHttpCommandCodec cannot find commands, like getCurrentContextHandle.

We created a customized version of AppiumCommandExecutor and added those commands as additional commands to make it work. Since context switching commands are critical for mobile hybrid application tests, those commands would be supported by default, right? Is there anything that I missed when trying to use AppiumCommandExecutor for testing hybrid mobile application tests?

mykola-mokhnach commented 1 month ago

Please provide the full stack trace and the client code example. Are you sure you use the most recent client version?

helenren commented 1 month ago

We used java-client version 9.3.0, which depends on selenium 4.21.0.