Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ build tools. Sometimes users may want to pin used Selenium dependencies for [var
Follow the [Transitive Dependencies Management article](docs/transitive-dependencies-management.md) for more information
about establishing a fixed Selenium version for your Java test framework.

### Appium Server Compatibility

A major release of the client guarantees support only for the Appium server API of the major server version that is
current at the time of the release and of the previous major version. Endpoints and commands that were removed or
deprecated in the server earlier may not be supported anymore. For example, if Appium 4 is the current version, the API
that existed in Appium 2 and was removed or deprecated in Appium 3 is not guaranteed to work.

## Drivers Support

Appium java client has dedicated classes to support the following Appium drivers:
Expand Down
6 changes: 0 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,6 @@ testing {
}

test {
dependencies {
implementation "org.seleniumhq.selenium:selenium-chrome-driver:${seleniumVersion}"
implementation('io.github.bonigarcia:webdrivermanager:6.4.0') {
exclude group: 'org.seleniumhq.selenium'
}
}
targets.configureEach {
testTask.configure {
finalizedBy jacocoTestReport
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.appium.java_client.android;

import io.appium.java_client.functions.AppiumFunction;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -14,6 +13,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -27,7 +27,11 @@

public class AndroidFunctionTest extends BaseAndroidTest {

private final AppiumFunction<WebDriver, List<WebElement>> searchingFunction = input -> {
// Function#compose and Function#andThen pass null on, so the steps of a wait must handle it themselves
private final Function<WebDriver, List<WebElement>> searchingFunction = input -> {
Comment thread
harsha509 marked this conversation as resolved.
if (input == null) {
return null;
}
List<WebElement> result = input.findElements(By.tagName("a"));

if (result.size() > 0) {
Expand All @@ -36,7 +40,7 @@ public class AndroidFunctionTest extends BaseAndroidTest {
return null;
};

private final AppiumFunction<Pattern, WebDriver> contextFunction = input -> {
private final Function<Pattern, WebDriver> contextFunction = input -> {
Set<String> contexts = driver.getContextHandles();
String current = driver.getContext();
contexts.forEach(context -> {
Expand All @@ -51,7 +55,10 @@ public class AndroidFunctionTest extends BaseAndroidTest {
return null;
};

private final AppiumFunction<List<WebElement>, List<WebElement>> filteringFunction = input -> {
private final Function<List<WebElement>, List<WebElement>> filteringFunction = input -> {
if (input == null) {
return null;
}
final List<WebElement> result = new ArrayList<>();
input.forEach(element -> {
if (element.getText().equals("Hello World! - 1")) {
Expand Down Expand Up @@ -80,7 +87,7 @@ public void setUp() {

@Test
public void complexWaitingTestWithPreCondition() {
AppiumFunction<Pattern, List<WebElement>> compositeFunction =
Function<Pattern, List<WebElement>> compositeFunction =
searchingFunction.compose(contextFunction);

Wait<Pattern> wait = new FluentWait<>(Pattern.compile("WEBVIEW"))
Expand All @@ -94,23 +101,23 @@ public void complexWaitingTestWithPreCondition() {
@Test public void complexWaitingTestWithPostConditions() {
final List<Boolean> calls = new ArrayList<>();

AppiumFunction<Pattern, WebDriver> waitingForContext = input -> {
Function<Pattern, WebDriver> waitingForContext = input -> {
WebDriver result = contextFunction.apply(input);
if (result != null) {
calls.add(true);
}
return result;
};

AppiumFunction<Pattern, List<WebElement>> compositeFunction = waitingForContext
.andThen((AppiumFunction<WebDriver, List<WebElement>>) input -> {
Function<Pattern, List<WebElement>> compositeFunction = waitingForContext
.andThen((Function<WebDriver, List<WebElement>>) input -> {
List<WebElement> result = searchingFunction.apply(input);
if (result != null) {
calls.add(true);
}
return result;
})
.andThen((AppiumFunction<List<WebElement>, List<WebElement>>) input -> {
.andThen((Function<List<WebElement>, List<WebElement>>) input -> {
List<WebElement> result = filteringFunction.apply(input);
if (result != null) {
calls.add(true);
Expand Down
19 changes: 0 additions & 19 deletions src/main/java/io/appium/java_client/AppiumDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,13 @@
import org.openqa.selenium.ImmutableCapabilities;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.SessionNotCreatedException;
import org.openqa.selenium.UnsupportedCommandException;
import org.openqa.selenium.WebDriverException;

import java.net.URL;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

import static io.appium.java_client.internal.CapabilityHelpers.APPIUM_PREFIX;
import static io.appium.java_client.internal.Strings.isNullOrEmpty;
Expand All @@ -63,15 +60,13 @@ public class AppiumDriver extends AppiumRemoteWebDriver implements
ExecutesDriverScript,
LogsEvents,
HasBrowserCheck,
CanRememberExtensionPresence,
HasSettings {

private static final ErrorHandler ERROR_HANDLER = new ErrorHandler(new ErrorCodesMobile());
// frequently used command parameters
@Getter
private final URL remoteAddress;
private final ExecuteMethod executeMethod;
private final Set<String> absentExtensionNames = new HashSet<>();

/**
* Creates a new instance based on command {@code executor} and {@code capabilities}.
Expand Down Expand Up @@ -238,20 +233,6 @@ public X convertFromPngBytes(byte[] png) {
});
}

@Override
public AppiumDriver assertExtensionExists(String extName) {
if (absentExtensionNames.contains(extName)) {
throw new UnsupportedCommandException();
}
return this;
}

@Override
public AppiumDriver markExtensionAbsence(String extName) {
absentExtensionNames.add(extName);
return this;
}

protected HttpClient getHttpClient() {
return ((AppiumCommandExecutor) getCommandExecutor()).getClient();
}
Expand Down

This file was deleted.

37 changes: 6 additions & 31 deletions src/main/java/io/appium/java_client/HasAppStrings.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@

package io.appium.java_client;

import org.openqa.selenium.UnsupportedCommandException;

import java.util.Map;

import static io.appium.java_client.MobileCommand.GET_STRINGS;

public interface HasAppStrings extends ExecutesMethod, CanRememberExtensionPresence {
public interface HasAppStrings extends ExecutesMethod {
/**
* Get all defined Strings from an app for the default language.
* See the documentation for 'mobile: getAppStrings' extension for more details.
Expand All @@ -31,12 +27,7 @@ public interface HasAppStrings extends ExecutesMethod, CanRememberExtensionPrese
*/
default Map<String, String> getAppStringMap() {
final String extName = "mobile: getAppStrings";
try {
return CommandExecutionHelper.executeScript(assertExtensionExists(extName), extName);
} catch (UnsupportedCommandException e) {
// TODO: Remove the fallback
return CommandExecutionHelper.execute(markExtensionAbsence(extName), GET_STRINGS);
}
return CommandExecutionHelper.executeScript(this, extName);
}

/**
Expand All @@ -48,17 +39,9 @@ default Map<String, String> getAppStringMap() {
*/
default Map<String, String> getAppStringMap(String language) {
final String extName = "mobile: getAppStrings";
try {
return CommandExecutionHelper.executeScript(assertExtensionExists(extName), extName, Map.of(
"language", language
));
} catch (UnsupportedCommandException e) {
// TODO: Remove the fallback
return CommandExecutionHelper.execute(
markExtensionAbsence(extName),
Map.entry(GET_STRINGS, Map.of("language", language))
);
}
return CommandExecutionHelper.executeScript(this, extName, Map.of(
"language", language
));
}

/**
Expand All @@ -76,15 +59,7 @@ default Map<String, String> getAppStringMap(String language, String stringFile)
"language", language,
"stringFile", stringFile
);
try {
return CommandExecutionHelper.executeScript(assertExtensionExists(extName), extName, args);
} catch (UnsupportedCommandException e) {
// TODO: Remove the fallback
return CommandExecutionHelper.execute(
markExtensionAbsence(extName),
Map.entry(GET_STRINGS, args)
);
}
return CommandExecutionHelper.executeScript(this, extName, args);
}

}
14 changes: 2 additions & 12 deletions src/main/java/io/appium/java_client/HasOnScreenKeyboard.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package io.appium.java_client;

import org.openqa.selenium.UnsupportedCommandException;

import static io.appium.java_client.MobileCommand.isKeyboardShownCommand;
import static java.util.Objects.requireNonNull;

public interface HasOnScreenKeyboard extends ExecutesMethod, CanRememberExtensionPresence {
public interface HasOnScreenKeyboard extends ExecutesMethod {

/**
* Check if the on-screen keyboard is displayed.
Expand All @@ -15,13 +12,6 @@ public interface HasOnScreenKeyboard extends ExecutesMethod, CanRememberExtensio
*/
default boolean isKeyboardShown() {
final String extName = "mobile: isKeyboardShown";
try {
return requireNonNull(CommandExecutionHelper.executeScript(assertExtensionExists(extName), extName));
} catch (UnsupportedCommandException e) {
// TODO: Remove the fallback
return requireNonNull(
CommandExecutionHelper.execute(markExtensionAbsence(extName), isKeyboardShownCommand())
);
}
return requireNonNull(CommandExecutionHelper.executeScript(this, extName));
}
}
13 changes: 2 additions & 11 deletions src/main/java/io/appium/java_client/HidesKeyboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@

package io.appium.java_client;

import org.openqa.selenium.UnsupportedCommandException;

import static io.appium.java_client.MobileCommand.HIDE_KEYBOARD;

public interface HidesKeyboard extends ExecutesMethod, CanRememberExtensionPresence {
public interface HidesKeyboard extends ExecutesMethod {

/**
* Hides the keyboard if it is showing.
Expand All @@ -31,11 +27,6 @@ public interface HidesKeyboard extends ExecutesMethod, CanRememberExtensionPrese
*/
default void hideKeyboard() {
final String extName = "mobile: hideKeyboard";
try {
CommandExecutionHelper.executeScript(assertExtensionExists(extName), extName);
} catch (UnsupportedCommandException e) {
// TODO: Remove the fallback
CommandExecutionHelper.execute(markExtensionAbsence(extName), HIDE_KEYBOARD);
}
CommandExecutionHelper.executeScript(this, extName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@

package io.appium.java_client;

import org.openqa.selenium.UnsupportedCommandException;

import java.util.List;
import java.util.Map;

import static io.appium.java_client.MobileCommand.hideKeyboardCommand;

public interface HidesKeyboardWithKeyName extends HidesKeyboard {

/**
Expand All @@ -37,13 +33,8 @@ public interface HidesKeyboardWithKeyName extends HidesKeyboard {
*/
default void hideKeyboard(String keyName) {
final String extName = "mobile: hideKeyboard";
try {
CommandExecutionHelper.executeScript(assertExtensionExists(extName), extName, Map.of(
"keys", List.of(keyName)
));
} catch (UnsupportedCommandException e) {
// TODO: Remove the fallback
CommandExecutionHelper.execute(markExtensionAbsence(extName), hideKeyboardCommand(keyName));
}
CommandExecutionHelper.executeScript(this, extName, Map.of(
"keys", List.of(keyName)
));
}
}
Loading
Loading