Skip to content

Commit e98bf2d

Browse files
authored
fix: Fix Selenium 4.34.0+ compatibility (#2298)
1 parent 29843c1 commit e98bf2d

File tree

5 files changed

+13
-26
lines changed

5 files changed

+13
-26
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ dependencies {
9595
### Compatibility Matrix
9696
Appium Java Client | Selenium client
9797
----------------------------------------------------------------------------------------------------|-----------------------------
98-
`9.4.0` | `4.26.0`, `4.27.0`, `4.28.0`
98+
- | `4.34.0`
99+
`9.4.0` | `4.26.0`, `4.27.0`, `4.28.0`, `4.28.1`, `4.29.0`, `4.30.0`, `4.31.0`, `4.32.0`, `4.33.0`
99100
`9.2.1`(known issues: appium/java-client#2145, appium/java-client#2146), `9.2.2`, `9.2.3`, `9.3.0` | `4.19.0`, `4.19.1`, `4.20.0`, `4.21.0`, `4.22.0`, `4.23.0`, `4.23.1`, `4.24.0`, `4.25.0`, `4.26.0`, `4.27.0`
100101
`9.1.0`, `9.2.0` | `4.17.0`, `4.18.0`, `4.18.1`
101102
`9.0.0` | `4.14.1`, `4.15.0`, `4.16.0` (partially [corrupted](https://github.com/SeleniumHQ/selenium/issues/13256)), `4.16.1`

src/main/java/io/appium/java_client/HasBrowserCheck.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.appium.java_client;
22

33
import io.appium.java_client.internal.CapabilityHelpers;
4-
import org.openqa.selenium.ContextAware;
4+
import io.appium.java_client.remote.SupportsContextSwitching;
55
import org.openqa.selenium.HasCapabilities;
66
import org.openqa.selenium.WebDriverException;
77
import org.openqa.selenium.remote.CapabilityType;
@@ -29,11 +29,11 @@ default boolean isBrowser() {
2929
// ignore
3030
}
3131
}
32-
if (!(this instanceof ContextAware)) {
32+
if (!(this instanceof SupportsContextSwitching)) {
3333
return false;
3434
}
3535
try {
36-
var context = ((ContextAware) this).getContext();
36+
var context = ((SupportsContextSwitching) this).getContext();
3737
return context != null && !context.toUpperCase().contains(NATIVE_CONTEXT);
3838
} catch (WebDriverException e) {
3939
return false;

src/main/java/io/appium/java_client/pagefactory/utils/WebDriverUnpackUtility.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
import io.appium.java_client.HasBrowserCheck;
2020
import io.appium.java_client.pagefactory.bys.ContentType;
21+
import io.appium.java_client.remote.SupportsContextSwitching;
2122
import org.jspecify.annotations.Nullable;
22-
import org.openqa.selenium.ContextAware;
2323
import org.openqa.selenium.SearchContext;
2424
import org.openqa.selenium.WebDriver;
2525
import org.openqa.selenium.WrapsDriver;
@@ -92,21 +92,22 @@ public static WebDriver unpackWebDriverFromSearchContext(@Nullable SearchContext
9292
* {@link WebDriver} or {@link org.openqa.selenium.WebElement} or some other
9393
* user's extension/implementation.
9494
* Note: if you want to use your own implementation then it should
95-
* implement {@link ContextAware} or {@link WrapsDriver} or {@link HasBrowserCheck}
95+
* implement {@link SupportsContextSwitching} or {@link WrapsDriver} or {@link HasBrowserCheck}
9696
* @return current content type. It depends on current context. If current context is
9797
* NATIVE_APP it will return {@link ContentType#NATIVE_MOBILE_SPECIFIC}.
9898
* {@link ContentType#HTML_OR_DEFAULT} will be returned if the current context is WEB_VIEW.
9999
* {@link ContentType#HTML_OR_DEFAULT} also will be returned if the given
100-
* {@link SearchContext} instance doesn't implement {@link ContextAware} and {@link WrapsDriver}
100+
* {@link SearchContext} instance doesn't implement {@link SupportsContextSwitching} and
101+
* {@link WrapsDriver}
101102
*/
102103
public static ContentType getCurrentContentType(SearchContext context) {
103104
var browserCheckHolder = unpackObjectFromSearchContext(context, HasBrowserCheck.class);
104105
if (browserCheckHolder.filter(hbc -> !hbc.isBrowser()).isPresent()) {
105106
return NATIVE_MOBILE_SPECIFIC;
106107
}
107108

108-
var contextAware = unpackObjectFromSearchContext(context, ContextAware.class);
109-
if (contextAware.map(ContextAware::getContext)
109+
var contextAware = unpackObjectFromSearchContext(context, SupportsContextSwitching.class);
110+
if (contextAware.map(SupportsContextSwitching::getContext)
110111
.filter(c -> c.toUpperCase().contains(NATIVE_CONTEXT)).isPresent()) {
111112
return NATIVE_MOBILE_SPECIFIC;
112113
}

src/main/java/io/appium/java_client/remote/SupportsContextSwitching.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import io.appium.java_client.MobileCommand;
2121
import io.appium.java_client.NoSuchContextException;
2222
import org.jspecify.annotations.Nullable;
23-
import org.openqa.selenium.ContextAware;
2423
import org.openqa.selenium.WebDriver;
2524
import org.openqa.selenium.WebDriverException;
2625
import org.openqa.selenium.remote.Response;
@@ -32,7 +31,7 @@
3231

3332
import static java.util.Objects.requireNonNull;
3433

35-
public interface SupportsContextSwitching extends WebDriver, ContextAware, ExecutesMethod {
34+
public interface SupportsContextSwitching extends WebDriver, ExecutesMethod {
3635
/**
3736
* Switches to the given context.
3837
*

src/test/java/io/appium/java_client/events/stubs/EmptyWebDriver.java

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import org.openqa.selenium.Alert;
2020
import org.openqa.selenium.By;
2121
import org.openqa.selenium.Capabilities;
22-
import org.openqa.selenium.ContextAware;
2322
import org.openqa.selenium.Cookie;
2423
import org.openqa.selenium.HasCapabilities;
2524
import org.openqa.selenium.JavascriptExecutor;
@@ -39,27 +38,14 @@
3938
import java.util.Map;
4039
import java.util.Set;
4140

42-
public class EmptyWebDriver implements WebDriver, ContextAware,
43-
JavascriptExecutor, HasCapabilities, TakesScreenshot {
41+
public class EmptyWebDriver implements WebDriver, JavascriptExecutor, HasCapabilities, TakesScreenshot {
4442
public EmptyWebDriver() {
4543
}
4644

4745
private static List<StubWebElement> createStubList() {
4846
return List.of(new StubWebElement(), new StubWebElement());
4947
}
5048

51-
public WebDriver context(String name) {
52-
return null;
53-
}
54-
55-
public Set<String> getContextHandles() {
56-
return null;
57-
}
58-
59-
public String getContext() {
60-
return "";
61-
}
62-
6349
public void get(String url) {
6450
}
6551

0 commit comments

Comments
 (0)