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 @@ -18,10 +18,7 @@

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import io.appium.java_client.android.options.context.SupportsChromedriverExecutableOption;
import io.appium.java_client.android.options.signing.SupportsKeystoreOptions;
import io.appium.java_client.internal.process.ExecutableFinder;
import io.appium.java_client.remote.options.SupportsAppOption;
import io.appium.java_client.service.local.flags.GeneralServerFlag;
import io.appium.java_client.service.local.flags.ServerArgument;
import lombok.SneakyThrows;
Expand Down Expand Up @@ -93,11 +90,6 @@ public final class AppiumServiceBuilder {
private static final Function<File, String> NODE_JS_NOT_EXIST_ERROR = fullPath ->
String.format("The main NodeJS executable does not exist at '%s'", fullPath.getAbsolutePath());

private static final List<String> PATH_CAPABILITIES = List.of(
SupportsChromedriverExecutableOption.CHROMEDRIVER_EXECUTABLE_OPTION,
SupportsKeystoreOptions.KEYSTORE_PATH_OPTION,
SupportsAppOption.APP_OPTION
);

/**
* Creates a builder using the default port and the current process environment.
Expand Down Expand Up @@ -303,7 +295,7 @@ private void loadPathToMainScript() {
this.appiumJS = findMainScript();
}

private String capabilitiesToQuotedCmdlineArg() {
String capabilitiesToQuotedCmdlineArg() {
if (capabilities == null) {
return "{}";
}
Expand All @@ -319,12 +311,8 @@ private String capabilitiesToQuotedCmdlineArg() {
}

if (value instanceof String) {
String valueString = (String) value;
if (PATH_CAPABILITIES.contains(entry.getKey())) {
value = "\\\"" + valueString.replace("\\", "/") + "\\\"";
} else {
value = "\\\"" + valueString + "\\\"";
}
// A raw backslash breaks the JSON, so Windows paths are written with forward slashes
value = "\\\"" + ((String) value).replace("\\", "/") + "\\\"";
} else {
value = String.valueOf(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.openqa.selenium.MutableCapabilities;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -104,4 +105,24 @@ void acceptsEnvironmentAndTimeout() throws IOException {

assertFalse(service.isRunning());
}

@Test
void quotesTheCapabilitiesAndNormalizesWindowsPaths() throws IOException {
var caps = new MutableCapabilities(Map.of(
"appium:app", "rel\\b.apk",
"appium:keystorePath", "C:\\keys\\a.jks",
"appium:chromedriverExecutable", "..\\bin\\chromedriver.exe",
"appium:derivedDataPath", "\\\\server\\share",
"appium:name", "C:name",
"appium:retries", 3));
var arg = newBuilder().withCapabilities(caps, true).capabilitiesToQuotedCmdlineArg();

assertTrue(arg.contains("\\\"appium:app\\\": \\\"rel/b.apk\\\""), arg);
assertTrue(arg.contains("\\\"appium:keystorePath\\\": \\\"C:/keys/a.jks\\\""), arg);
assertTrue(arg.contains("\\\"appium:chromedriverExecutable\\\": \\\"../bin/chromedriver.exe\\\""), arg);
assertTrue(arg.contains("\\\"appium:derivedDataPath\\\": \\\"//server/share\\\""), arg);
// no backslashes: kept as is
assertTrue(arg.contains("\\\"appium:name\\\": \\\"C:name\\\""), arg);
assertTrue(arg.contains("\\\"appium:retries\\\": 3"), arg);
}
}
2 changes: 0 additions & 2 deletions src/test/resources/architecture/dependency-baseline.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
# Known dependency violations: <from> -> <to>, top-level classes.
# core -> driver and driver -> other driver edges are removed in Phase 1; this file must end empty.
io.appium.java_client.service.local.AppiumServiceBuilder -> io.appium.java_client.android.options.context.SupportsChromedriverExecutableOption [core -> android]
io.appium.java_client.service.local.AppiumServiceBuilder -> io.appium.java_client.android.options.signing.SupportsKeystoreOptions [core -> android]
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ io/appium/java_client/remote/MobilePlatform.java: WINDOWS x1
io/appium/java_client/remote/MobilePlatform.java: Windows x1
io/appium/java_client/remote/MobilePlatform.java: iOS x1
io/appium/java_client/service/local/AppiumServiceBuilder.java: WINDOWS x1
io/appium/java_client/service/local/AppiumServiceBuilder.java: android x2
io/appium/java_client/service/local/AppiumServiceBuilder.java: autoQuoteCapabilitiesOnWindows x5
io/appium/java_client/service/local/flags/AndroidServerFlag.java: AndroidServerFlag x2
io/appium/java_client/service/local/flags/IOSServerFlag.java: IOSServerFlag x2
Expand Down
Loading