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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.time.Duration;

import static java.util.Locale.ROOT;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.emptyString;
import static org.hamcrest.Matchers.is;
Expand All @@ -26,7 +27,7 @@ public void verifyBasicScreenRecordingWorks() throws InterruptedException {
.withTimeLimit(Duration.ofSeconds(5))
);
} catch (WebDriverException e) {
if (e.getMessage().toLowerCase().contains("emulator")) {
if (e.getMessage() != null && e.getMessage().toLowerCase(ROOT).contains("emulator")) {
// screen recording only works on real devices
return;
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/io/appium/java_client/HasBrowserCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.openqa.selenium.remote.CapabilityType;

import static com.google.common.base.Strings.isNullOrEmpty;
import static java.util.Locale.ROOT;
import static java.util.Objects.requireNonNull;

public interface HasBrowserCheck extends ExecutesMethod, HasCapabilities {
Expand Down Expand Up @@ -34,7 +35,7 @@ default boolean isBrowser() {
}
try {
var context = ((SupportsContextSwitching) this).getContext();
return context != null && !context.toUpperCase().contains(NATIVE_CONTEXT);
return context != null && !context.toUpperCase(ROOT).contains(NATIVE_CONTEXT);
} catch (WebDriverException e) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import java.util.Map;

import static java.util.Locale.ROOT;

/**
* This util class helps to prepare parameters of Android-specific JSONWP
* commands.
Expand Down Expand Up @@ -241,7 +243,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
String phoneNumber, GsmCallActions gsmCallActions) {
return Map.entry(GSM_CALL, Map.of(
"phoneNumber", phoneNumber,
"action", gsmCallActions.name().toLowerCase()
"action", gsmCallActions.name().toLowerCase(ROOT)
));
}

Expand Down Expand Up @@ -275,7 +277,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
@Deprecated
public static Map.Entry<String, Map<String, ?>> gsmVoiceCommand(
GsmVoiceState gsmVoiceState) {
return Map.entry(GSM_VOICE, Map.of("state", gsmVoiceState.name().toLowerCase()));
return Map.entry(GSM_VOICE, Map.of("state", gsmVoiceState.name().toLowerCase(ROOT)));
}

/**
Expand All @@ -289,7 +291,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
@Deprecated
public static Map.Entry<String, Map<String, ?>> networkSpeedCommand(
NetworkSpeed networkSpeed) {
return Map.entry(NETWORK_SPEED, Map.of("netspeed", networkSpeed.name().toLowerCase()));
return Map.entry(NETWORK_SPEED, Map.of("netspeed", networkSpeed.name().toLowerCase(ROOT)));
}

/**
Expand Down Expand Up @@ -317,7 +319,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
@Deprecated
public static Map.Entry<String, Map<String, ?>> powerACCommand(
PowerACState powerACState) {
return Map.entry(POWER_AC_STATE, Map.of("state", powerACState.name().toLowerCase()));
return Map.entry(POWER_AC_STATE, Map.of("state", powerACState.name().toLowerCase(ROOT)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.Map;

import static io.appium.java_client.MobileCommand.SET_CLIPBOARD;
import static java.util.Locale.ROOT;
import static java.util.Objects.requireNonNull;

public interface HasAndroidClipboard extends HasClipboard {
Expand All @@ -39,7 +40,7 @@ default void setClipboard(String label, ClipboardContentType contentType, byte[]
CommandExecutionHelper.execute(this, Map.entry(SET_CLIPBOARD,
Map.of(
"content", new String(requireNonNull(base64Content), StandardCharsets.UTF_8),
"contentType", contentType.name().toLowerCase(),
"contentType", contentType.name().toLowerCase(ROOT),
"label", requireNonNull(label)
)
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import static io.appium.java_client.MobileCommand.POWER_AC_STATE;
import static io.appium.java_client.MobileCommand.POWER_CAPACITY;
import static io.appium.java_client.MobileCommand.SEND_SMS;
import static java.util.Locale.ROOT;

public interface SupportsSpecialEmulatorCommands extends ExecutesMethod, CanRememberExtensionPresence {

Expand Down Expand Up @@ -53,15 +54,15 @@ default void makeGsmCall(String phoneNumber, GsmCallActions gsmCallAction) {
try {
CommandExecutionHelper.executeScript(assertExtensionExists(extName), extName, Map.of(
"phoneNumber", phoneNumber,
"action", gsmCallAction.toString().toLowerCase()
"action", gsmCallAction.toString().toLowerCase(ROOT)
));
} catch (UnsupportedCommandException e) {
// TODO: Remove the fallback
CommandExecutionHelper.execute(
markExtensionAbsence(extName),
Map.entry(GSM_CALL, Map.of(
"phoneNumber", phoneNumber,
"action", gsmCallAction.toString().toLowerCase()
"action", gsmCallAction.toString().toLowerCase(ROOT)
))
);
}
Expand Down Expand Up @@ -99,14 +100,14 @@ default void setGsmVoice(GsmVoiceState gsmVoiceState) {
final String extName = "mobile: gsmVoice";
try {
CommandExecutionHelper.executeScript(assertExtensionExists(extName), extName, Map.of(
"state", gsmVoiceState.toString().toLowerCase()
"state", gsmVoiceState.toString().toLowerCase(ROOT)
));
} catch (UnsupportedCommandException e) {
// TODO: Remove the fallback
CommandExecutionHelper.execute(
markExtensionAbsence(extName),
Map.entry(GSM_VOICE, Map.of(
"state", gsmVoiceState.name().toLowerCase()
"state", gsmVoiceState.name().toLowerCase(ROOT)
))
);
}
Expand All @@ -121,14 +122,14 @@ default void setNetworkSpeed(NetworkSpeed networkSpeed) {
final String extName = "mobile: networkSpeed";
try {
CommandExecutionHelper.executeScript(assertExtensionExists(extName), extName, Map.of(
"speed", networkSpeed.toString().toLowerCase()
"speed", networkSpeed.toString().toLowerCase(ROOT)
));
} catch (UnsupportedCommandException e) {
// TODO: Remove the fallback
CommandExecutionHelper.execute(
markExtensionAbsence(extName),
Map.entry(NETWORK_SPEED, Map.of(
"netspeed", networkSpeed.name().toLowerCase()
"netspeed", networkSpeed.name().toLowerCase(ROOT)
))
);
}
Expand Down Expand Up @@ -165,14 +166,14 @@ default void setPowerAC(PowerACState powerACState) {
final String extName = "mobile: powerAC";
try {
CommandExecutionHelper.executeScript(assertExtensionExists(extName), extName, Map.of(
"state", powerACState.toString().toLowerCase()
"state", powerACState.toString().toLowerCase(ROOT)
));
} catch (UnsupportedCommandException e) {
// TODO: Remove the fallback
CommandExecutionHelper.execute(
markExtensionAbsence(extName),
Map.entry(POWER_AC_STATE, Map.of(
"state", powerACState.name().toLowerCase()
"state", powerACState.name().toLowerCase(ROOT)
))
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import static io.appium.java_client.MobileCommand.GET_CLIPBOARD;
import static io.appium.java_client.MobileCommand.SET_CLIPBOARD;
import static java.util.Locale.ROOT;
import static java.util.Objects.requireNonNull;

public interface HasClipboard extends ExecutesMethod, CanRememberExtensionPresence {
Expand All @@ -40,7 +41,7 @@ default void setClipboard(ClipboardContentType contentType, byte[] base64Content
final String extName = "mobile: setClipboard";
var args = Map.of(
"content", new String(requireNonNull(base64Content), StandardCharsets.UTF_8),
"contentType", contentType.name().toLowerCase()
"contentType", contentType.name().toLowerCase(ROOT)
);
try {
CommandExecutionHelper.executeScript(assertExtensionExists(extName), extName, args);
Expand All @@ -58,7 +59,7 @@ default void setClipboard(ClipboardContentType contentType, byte[] base64Content
*/
default String getClipboard(ClipboardContentType contentType) {
final String extName = "mobile: getClipboard";
var args = Map.of("contentType", contentType.name().toLowerCase());
var args = Map.of("contentType", contentType.name().toLowerCase(ROOT));
try {
return CommandExecutionHelper.executeScript(assertExtensionExists(extName), extName, args);
} catch (UnsupportedCommandException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.HashMap;
import java.util.Map;

import static java.util.Locale.ROOT;
import static java.util.Objects.requireNonNull;
import static java.util.Optional.ofNullable;

Expand Down Expand Up @@ -59,7 +60,7 @@ public ScriptOptions withTimeout(long timeoutMs) {
*/
public Map<String, Object> build() {
var map = new HashMap<String, Object>();
ofNullable(scriptType).ifPresent(x -> map.put("type", x.name().toLowerCase()));
ofNullable(scriptType).ifPresent(x -> map.put("type", x.name().toLowerCase(ROOT)));
ofNullable(timeoutMs).ifPresent(x -> map.put("timeout", x));
return Collections.unmodifiableMap(map);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

import java.util.Optional;

import static java.util.Locale.ROOT;

public interface SupportsVerbosityOption<T extends BaseOptions<T>> extends
Capabilities, CanSetCapability<T> {
String VERBOSITY_OPTION = "verbosity";
Expand All @@ -34,7 +36,7 @@ public interface SupportsVerbosityOption<T extends BaseOptions<T>> extends
* @return self instance for chaining.
*/
default T setVerbosity(Verbosity verbosity) {
return amend(VERBOSITY_OPTION, verbosity.name().toLowerCase());
return amend(VERBOSITY_OPTION, verbosity.name().toLowerCase(ROOT));
}

/**
Expand All @@ -45,7 +47,7 @@ default T setVerbosity(Verbosity verbosity) {
default Optional<Verbosity> getVerbosity() {
return Optional.ofNullable(getCapability(VERBOSITY_OPTION))
.map(String::valueOf)
.map(String::toUpperCase)
.map(verbosity -> verbosity.toUpperCase(ROOT))
.map(Verbosity::valueOf);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
import org.openqa.selenium.remote.http.HttpHandler;
import org.openqa.selenium.remote.http.HttpMethod;

import java.util.UUID;
import static java.util.Locale.ROOT;
import static java.util.UUID.randomUUID;

public class AppiumIdempotencyFilter implements Filter {
// https://github.com/appium/appium-base-driver/pull/400
Expand All @@ -30,7 +31,7 @@ public class AppiumIdempotencyFilter implements Filter {
public HttpHandler apply(HttpHandler next) {
return req -> {
if (req.getMethod() == HttpMethod.POST && req.getUri().endsWith("/session")) {
req.setHeader(IDEMPOTENCY_KEY_HEADER, UUID.randomUUID().toString().toLowerCase());
req.setHeader(IDEMPOTENCY_KEY_HEADER, randomUUID().toString().toLowerCase(ROOT));
}
return next.execute(req);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.openqa.selenium.remote.http.HttpHandler;
import org.openqa.selenium.remote.http.HttpHeader;

import static java.util.Locale.ROOT;

/**
* Manage Appium Client configurations.
*/
Expand Down Expand Up @@ -54,7 +56,7 @@ private static String buildUserAgentHeaderValue(@NonNull String previousUA) {
* like by this filter.
*/
private static boolean containsAppiumName(@Nullable String userAgent) {
return userAgent != null && userAgent.toLowerCase().contains(USER_AGENT_PREFIX.toLowerCase());
return userAgent != null && userAgent.toLowerCase(ROOT).contains(USER_AGENT_PREFIX.toLowerCase(ROOT));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.HashMap;
import java.util.Map;

import static java.util.Locale.ROOT;
import static java.util.Objects.requireNonNull;
import static java.util.Optional.ofNullable;

Expand Down Expand Up @@ -73,7 +74,7 @@ public enum VideoQuality {
* @return self instance for chaining.
*/
public IOSStartScreenRecordingOptions withVideoQuality(VideoQuality videoQuality) {
this.videoQuality = requireNonNull(videoQuality).name().toLowerCase();
this.videoQuality = requireNonNull(videoQuality).name().toLowerCase(ROOT);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

import java.util.Optional;

import static java.util.Locale.ROOT;

public interface SupportsSimulatorPasteboardAutomaticSyncOption<T extends BaseOptions<T>> extends
Capabilities, CanSetCapability<T> {
String SIMULATOR_PASTEBOARD_AUTOMATIC_SYNC = "simulatorPasteboardAutomaticSync";
Expand All @@ -37,7 +39,7 @@ public interface SupportsSimulatorPasteboardAutomaticSyncOption<T extends BaseOp
* @return self instance for chaining.
*/
default T setSimulatorPasteboardAutomaticSync(PasteboardSyncState state) {
return amend(SIMULATOR_PASTEBOARD_AUTOMATIC_SYNC, state.toString().toLowerCase());
return amend(SIMULATOR_PASTEBOARD_AUTOMATIC_SYNC, state.toString().toLowerCase(ROOT));
}

/**
Expand All @@ -47,6 +49,6 @@ default T setSimulatorPasteboardAutomaticSync(PasteboardSyncState state) {
*/
default Optional<PasteboardSyncState> getSimulatorPasteboardAutomaticSync() {
return Optional.ofNullable(getCapability(SIMULATOR_PASTEBOARD_AUTOMATIC_SYNC))
.map(v -> PasteboardSyncState.valueOf(String.valueOf(v).toUpperCase()));
.map(v -> PasteboardSyncState.valueOf(String.valueOf(v).toUpperCase(ROOT)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static io.appium.java_client.remote.MobilePlatform.ANDROID;
import static io.appium.java_client.remote.MobilePlatform.IOS;
import static io.appium.java_client.remote.MobilePlatform.WINDOWS;
import static java.util.Locale.ROOT;

class OverrideWidgetReader {
private static final Class<? extends Widget> EMPTY = Widget.class;
Expand Down Expand Up @@ -74,7 +75,7 @@ static Class<? extends Widget> getDefaultOrHTMLWidgetClass(

static Class<? extends Widget> getMobileNativeWidgetClass(Class<? extends Widget> declaredClass,
AnnotatedElement annotatedElement, String platform) {
String transformedPlatform = String.valueOf(platform).toUpperCase().trim();
String transformedPlatform = String.valueOf(platform).toUpperCase(ROOT).trim();

if (ANDROID.equalsIgnoreCase(transformedPlatform)) {
return getConvenientClass(declaredClass, annotatedElement, ANDROID_UI_AUTOMATOR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import static io.appium.java_client.HasBrowserCheck.NATIVE_CONTEXT;
import static io.appium.java_client.pagefactory.bys.ContentType.HTML_OR_DEFAULT;
import static io.appium.java_client.pagefactory.bys.ContentType.NATIVE_MOBILE_SPECIFIC;
import static java.util.Locale.ROOT;

public final class WebDriverUnpackUtility {
private WebDriverUnpackUtility() {
Expand Down Expand Up @@ -108,7 +109,7 @@ public static ContentType getCurrentContentType(SearchContext context) {

var contextAware = unpackObjectFromSearchContext(context, SupportsContextSwitching.class);
if (contextAware.map(SupportsContextSwitching::getContext)
.filter(c -> c.toUpperCase().contains(NATIVE_CONTEXT)).isPresent()) {
.filter(c -> c.toUpperCase(ROOT).contains(NATIVE_CONTEXT)).isPresent()) {
return NATIVE_MOBILE_SPECIFIC;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

import java.util.Map;

import static java.util.Locale.ROOT;

public interface SupportsRotation extends WebDriver, ExecutesMethod {
/**
* Get device rotation.
Expand All @@ -43,7 +45,7 @@ default void rotate(DeviceRotation rotation) {

default void rotate(ScreenOrientation orientation) {
execute(MobileCommand.SET_SCREEN_ORIENTATION,
Map.of("orientation", orientation.value().toUpperCase()));
Map.of("orientation", orientation.value().toUpperCase(ROOT)));
}

/**
Expand All @@ -54,6 +56,6 @@ default void rotate(ScreenOrientation orientation) {
default ScreenOrientation getOrientation() {
Response response = execute(MobileCommand.GET_SCREEN_ORIENTATION);
String orientation = String.valueOf(response.getValue());
return ScreenOrientation.valueOf(orientation.toUpperCase());
return ScreenOrientation.valueOf(orientation.toUpperCase(ROOT));
}
}
Loading