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
8 changes: 4 additions & 4 deletions src/main/java/io/appium/java_client/AppiumDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package io.appium.java_client;

import io.appium.java_client.extension.CapabilityHelpers;
import io.appium.java_client.http.HttpClient;
import io.appium.java_client.http.HttpMethod;
import io.appium.java_client.internal.SessionHelpers;
Expand All @@ -29,6 +28,7 @@
import io.appium.java_client.remote.ExecuteMethod;
import io.appium.java_client.remote.Response;
import io.appium.java_client.remote.options.BaseOptions;
import io.appium.java_client.remote.options.CapabilityReader;
import io.appium.java_client.service.local.AppiumDriverLocalService;
import io.appium.java_client.service.local.AppiumServiceBuilder;
import org.jspecify.annotations.Nullable;
Expand All @@ -44,10 +44,10 @@
import java.util.Map;
import java.util.Optional;

import static io.appium.java_client.extension.CapabilityHelpers.APPIUM_PREFIX;
import static io.appium.java_client.internal.Strings.isNullOrEmpty;
import static io.appium.java_client.remote.CapabilityType.BROWSER_NAME;
import static io.appium.java_client.remote.CapabilityType.PLATFORM_NAME;
import static io.appium.java_client.remote.options.BaseOptions.APPIUM_PREFIX;
import static io.appium.java_client.remote.options.SupportsAutomationNameOption.AUTOMATION_NAME_OPTION;
import static java.util.Collections.singleton;

Expand Down Expand Up @@ -387,8 +387,8 @@ protected static Capabilities ensurePlatformName(
*/
protected static Capabilities ensureAutomationName(
Capabilities originalCapabilities, String defaultName) {
String currentAutomationName = CapabilityHelpers.getCapability(
originalCapabilities, AUTOMATION_NAME_OPTION, String.class);
String currentAutomationName = new CapabilityReader(originalCapabilities)
.get(AUTOMATION_NAME_OPTION, String.class).orElse(null);
if (isNullOrEmpty(currentAutomationName)) {
String capabilityName = originalCapabilities.getCapabilityNames()
.contains(AUTOMATION_NAME_OPTION) ? AUTOMATION_NAME_OPTION : APPIUM_PREFIX + AUTOMATION_NAME_OPTION;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/appium/java_client/HasBrowserCheck.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.appium.java_client;

import io.appium.java_client.extension.CapabilityHelpers;
import io.appium.java_client.remote.CapabilityType;
import io.appium.java_client.remote.SupportsContextSwitching;
import io.appium.java_client.remote.options.CapabilityReader;
import org.openqa.selenium.HasCapabilities;
import org.openqa.selenium.WebDriverException;

Expand All @@ -23,8 +23,8 @@ public interface HasBrowserCheck extends ExecutesMethod, HasCapabilities {
* @return true or false.
*/
default boolean isBrowser() {
String browserName = CapabilityHelpers.getCapability(getCapabilities(),
CapabilityType.BROWSER_NAME, String.class);
String browserName = new CapabilityReader(getCapabilities())
.get(CapabilityType.BROWSER_NAME, String.class).orElse(null);
if (!isNullOrEmpty(browserName)) {
try {
return requireNonNull(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@

import io.appium.java_client.remote.options.BaseOptions;
import io.appium.java_client.remote.options.CanSetCapability;
import io.appium.java_client.remote.options.CapabilityReader;
import org.openqa.selenium.Capabilities;

import java.time.Duration;
import java.util.Optional;

import static io.appium.java_client.extension.CapabilityHelpers.toDuration;

/**
* Provides getters and setters for the {@code adbExecTimeout} capability.
*
Expand Down Expand Up @@ -54,6 +53,6 @@ default T setAdbExecTimeout(Duration timeout) {
* @return Timeout value.
*/
default Optional<Duration> getAdbExecTimeout() {
return Optional.ofNullable(toDuration(getCapability(ADB_EXEC_TIMEOUT_OPTION)));
return new CapabilityReader(this).getDuration(ADB_EXEC_TIMEOUT_OPTION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@

import io.appium.java_client.remote.options.BaseOptions;
import io.appium.java_client.remote.options.CanSetCapability;
import io.appium.java_client.remote.options.CapabilityReader;
import org.openqa.selenium.Capabilities;

import java.util.Optional;

import static io.appium.java_client.extension.CapabilityHelpers.toSafeBoolean;

/**
* Provides getters and setters for the {@code adbListenAllNetwork} capability.
*
Expand Down Expand Up @@ -61,6 +60,6 @@ default T setAdbListenAllNetwork(boolean value) {
* @return True or false.
*/
default Optional<Boolean> doesAdbListenAllNetwork() {
return Optional.ofNullable(toSafeBoolean(getCapability(ADB_LISTEN_ALL_NETWORK_OPTION)));
return new CapabilityReader(this).getBoolean(ADB_LISTEN_ALL_NETWORK_OPTION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@

import io.appium.java_client.remote.options.BaseOptions;
import io.appium.java_client.remote.options.CanSetCapability;
import io.appium.java_client.remote.options.CapabilityReader;
import org.openqa.selenium.Capabilities;

import java.util.Optional;

import static io.appium.java_client.extension.CapabilityHelpers.toInteger;

/**
* Provides getters and setters for the {@code adbPort} capability.
*
Expand Down Expand Up @@ -52,6 +51,6 @@ default T setAdbPort(int port) {
* @return Adb port value
*/
default Optional<Integer> getAdbPort() {
return Optional.ofNullable(toInteger(getCapability(ADB_PORT_OPTION)));
return new CapabilityReader(this).getInteger(ADB_PORT_OPTION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@

import io.appium.java_client.remote.options.BaseOptions;
import io.appium.java_client.remote.options.CanSetCapability;
import io.appium.java_client.remote.options.CapabilityReader;
import org.openqa.selenium.Capabilities;

import java.util.Optional;

import static io.appium.java_client.extension.CapabilityHelpers.toSafeBoolean;

/**
* Provides getters and setters for the {@code allowDelayAdb} capability.
*
Expand Down Expand Up @@ -53,6 +52,6 @@ default T setAllowDelayAdb(boolean value) {
* @return True or false.
*/
default Optional<Boolean> doesAllowDelayAdb() {
return Optional.ofNullable(toSafeBoolean(getCapability(ALLOW_DELAY_ADB_OPTION)));
return new CapabilityReader(this).getBoolean(ALLOW_DELAY_ADB_OPTION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@

import io.appium.java_client.remote.options.BaseOptions;
import io.appium.java_client.remote.options.CanSetCapability;
import io.appium.java_client.remote.options.CapabilityReader;
import org.openqa.selenium.Capabilities;

import java.util.Optional;

import static io.appium.java_client.extension.CapabilityHelpers.toSafeBoolean;

/**
* Provides getters and setters for the {@code allowOfflineDevices} capability.
*
Expand Down Expand Up @@ -61,6 +60,6 @@ default T setAllowOfflineDevices(boolean value) {
* @return True or false.
*/
default Optional<Boolean> doesAllowOfflineDevices() {
return Optional.ofNullable(toSafeBoolean(getCapability(ALLOW_OFFLINE_DEVICES_OPTION)));
return new CapabilityReader(this).getBoolean(ALLOW_OFFLINE_DEVICES_OPTION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@

import io.appium.java_client.remote.options.BaseOptions;
import io.appium.java_client.remote.options.CanSetCapability;
import io.appium.java_client.remote.options.CapabilityReader;
import org.openqa.selenium.Capabilities;

import java.util.Optional;

import static io.appium.java_client.extension.CapabilityHelpers.toSafeBoolean;

/**
* Provides getters and setters for the {@code clearDeviceLogsOnStart} capability.
*
Expand Down Expand Up @@ -65,6 +64,6 @@ default T setClearDeviceLogsOnStart(boolean value) {
* @return True or false.
*/
default Optional<Boolean> doesClearDeviceLogsOnStart() {
return Optional.ofNullable(toSafeBoolean(getCapability(CLEAR_DEVICE_LOGS_ON_START_OPTION)));
return new CapabilityReader(this).getBoolean(CLEAR_DEVICE_LOGS_ON_START_OPTION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@

import io.appium.java_client.remote.options.BaseOptions;
import io.appium.java_client.remote.options.CanSetCapability;
import io.appium.java_client.remote.options.CapabilityReader;
import org.openqa.selenium.Capabilities;

import java.util.Optional;

import static io.appium.java_client.extension.CapabilityHelpers.toSafeBoolean;

/**
* Provides getters and setters for the {@code ignoreHiddenApiPolicyError} capability.
*
Expand Down Expand Up @@ -63,6 +62,6 @@ default T setIgnoreHiddenApiPolicyError(boolean value) {
* @return True or false.
*/
default Optional<Boolean> doesIgnoreHiddenApiPolicyError() {
return Optional.ofNullable(toSafeBoolean(getCapability(IGNORE_HIDDEN_API_POLICY_ERROR_OPTION)));
return new CapabilityReader(this).getBoolean(IGNORE_HIDDEN_API_POLICY_ERROR_OPTION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@

import io.appium.java_client.remote.options.BaseOptions;
import io.appium.java_client.remote.options.CanSetCapability;
import io.appium.java_client.remote.options.CapabilityReader;
import org.openqa.selenium.Capabilities;

import java.util.Optional;

import static io.appium.java_client.extension.CapabilityHelpers.toSafeBoolean;

/**
* Provides getters and setters for the {@code skipLogcatCapture} capability.
*
Expand Down Expand Up @@ -62,6 +61,6 @@ default T setSkipLogcatCapture(boolean value) {
* @return True or false.
*/
default Optional<Boolean> doesSkipLogcatCapture() {
return Optional.ofNullable(toSafeBoolean(getCapability(SKIP_LOGCAT_CAPTURE_OPTION)));
return new CapabilityReader(this).getBoolean(SKIP_LOGCAT_CAPTURE_OPTION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@

import io.appium.java_client.remote.options.BaseOptions;
import io.appium.java_client.remote.options.CanSetCapability;
import io.appium.java_client.remote.options.CapabilityReader;
import org.openqa.selenium.Capabilities;

import java.util.Optional;

import static io.appium.java_client.extension.CapabilityHelpers.toSafeBoolean;

/**
* Provides getters and setters for the {@code suppressKillServer} capability.
*
Expand Down Expand Up @@ -62,6 +61,6 @@ default T setSuppressKillServer(boolean value) {
* @return True or false.
*/
default Optional<Boolean> doesSuppressKillServer() {
return Optional.ofNullable(toSafeBoolean(getCapability(SUPPRESS_KILL_SERVER_OPTION)));
return new CapabilityReader(this).getBoolean(SUPPRESS_KILL_SERVER_OPTION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package io.appium.java_client.android.options.app;

import io.appium.java_client.extension.CapabilityHelpers;
import io.appium.java_client.remote.options.BaseMapOptionData;
import io.appium.java_client.remote.options.CapabilityReader;

import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -59,7 +59,6 @@ public ActivityOptions withLaunchDisplayId(int id) {
* @return Display identifier.
*/
public Optional<Integer> getLaunchDisplayId() {
Optional<Object> result = getOptionValue("launchDisplayId");
return result.map(CapabilityHelpers::toInteger);
return new CapabilityReader(toMap()).getInteger("launchDisplayId");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@

import io.appium.java_client.remote.options.BaseOptions;
import io.appium.java_client.remote.options.CanSetCapability;
import io.appium.java_client.remote.options.CapabilityReader;
import org.openqa.selenium.Capabilities;

import java.util.Optional;

import static io.appium.java_client.extension.CapabilityHelpers.toSafeBoolean;

/**
* Provides getters and setters for the {@code allowTestPackages} capability.
*
Expand Down Expand Up @@ -64,6 +63,6 @@ default T setAllowTestPackages(boolean value) {
* @return True or false.
*/
default Optional<Boolean> doesAllowTestPackages() {
return Optional.ofNullable(toSafeBoolean(getCapability(ALLOW_TEST_PACKAGES_OPTION)));
return new CapabilityReader(this).getBoolean(ALLOW_TEST_PACKAGES_OPTION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

package io.appium.java_client.android.options.app;

import io.appium.java_client.extension.CapabilityHelpers;
import io.appium.java_client.remote.options.BaseOptions;
import io.appium.java_client.remote.options.CanSetCapability;
import io.appium.java_client.remote.options.CapabilityReader;
import org.openqa.selenium.Capabilities;

import java.time.Duration;
Expand Down Expand Up @@ -53,8 +53,6 @@ default T setAndroidInstallTimeout(Duration installTimeout) {
* @return Timeout value.
*/
default Optional<Duration> getAndroidInstallTimeout() {
return Optional.ofNullable(
CapabilityHelpers.toDuration(getCapability(ANDROID_INSTALL_TIMEOUT_OPTION))
);
return new CapabilityReader(this).getDuration(ANDROID_INSTALL_TIMEOUT_OPTION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@

import io.appium.java_client.remote.options.BaseOptions;
import io.appium.java_client.remote.options.CanSetCapability;
import io.appium.java_client.remote.options.CapabilityReader;
import org.openqa.selenium.Capabilities;

import java.time.Duration;
import java.util.Optional;

import static io.appium.java_client.extension.CapabilityHelpers.toDuration;

/**
* Provides getters and setters for the {@code appWaitDuration} capability.
*
Expand Down Expand Up @@ -54,6 +53,6 @@ default T setAppWaitDuration(Duration appWaitDuration) {
* @return Wait duration.
*/
default Optional<Duration> getAppWaitDuration() {
return Optional.ofNullable(toDuration(getCapability(APP_WAIT_DURATION_OPTION)));
return new CapabilityReader(this).getDuration(APP_WAIT_DURATION_OPTION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@

import io.appium.java_client.remote.options.BaseOptions;
import io.appium.java_client.remote.options.CanSetCapability;
import io.appium.java_client.remote.options.CapabilityReader;
import org.openqa.selenium.Capabilities;

import java.util.Optional;

import static io.appium.java_client.extension.CapabilityHelpers.toSafeBoolean;

/**
* Provides getters and setters for the {@code appWaitForLaunch} capability.
*
Expand Down Expand Up @@ -55,6 +54,6 @@ default T setAppWaitForLaunch(boolean value) {
* @return True if the driver should block or false otherwise.
*/
default Optional<Boolean> doesAppWaitForLaunch() {
return Optional.ofNullable(toSafeBoolean(getCapability(APP_WAIT_FOR_LAUNCH_OPTION)));
return new CapabilityReader(this).getBoolean(APP_WAIT_FOR_LAUNCH_OPTION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@

import io.appium.java_client.remote.options.BaseOptions;
import io.appium.java_client.remote.options.CanSetCapability;
import io.appium.java_client.remote.options.CapabilityReader;
import org.openqa.selenium.Capabilities;

import java.util.Optional;

import static io.appium.java_client.extension.CapabilityHelpers.toSafeBoolean;

/**
* Provides getters and setters for the {@code autoGrantPermissions} capability.
*
Expand Down Expand Up @@ -65,6 +64,6 @@ default T setAutoGrantPermissions(boolean value) {
* @return True if the permissions should be granted.
*/
default Optional<Boolean> doesAutoGrantPermissions() {
return Optional.ofNullable(toSafeBoolean(getCapability(AUTO_GRANT_PERMISSIONS_OPTION)));
return new CapabilityReader(this).getBoolean(AUTO_GRANT_PERMISSIONS_OPTION);
}
}
Loading
Loading