Skip to content
Closed
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 @@ -237,7 +237,12 @@ public AppiumServiceBuilder withArgument(ServerArgument argument) {
* @return the self-reference.
*/
public AppiumServiceBuilder withArgument(ServerArgument argument, String value) {
serverArguments.put(argument.getArgument(), value);
String argName = argument.getArgument().trim().toLowerCase();
if ("--port".equals(argName) || "-p".equals(argName)) {
usingPort(Integer.valueOf(value));
} else {
serverArguments.put(argName, value);
}
return this;
}

Expand Down Expand Up @@ -435,6 +440,7 @@ private String parseCapabilities() {
* @param nodeJSExecutable The executable Node.js to use.
* @return A self reference.
*/
@Override
public AppiumServiceBuilder usingDriverExecutable(File nodeJSExecutable) {
return super.usingDriverExecutable(nodeJSExecutable);
}
Expand All @@ -446,6 +452,7 @@ public AppiumServiceBuilder usingDriverExecutable(File nodeJSExecutable) {
* @param port The port to use; must be non-negative.
* @return A self reference.
*/
@Override
public AppiumServiceBuilder usingPort(int port) {
return super.usingPort(port);
}
Expand All @@ -455,6 +462,7 @@ public AppiumServiceBuilder usingPort(int port) {
*
* @return A self reference.
*/
@Override
public AppiumServiceBuilder usingAnyFreePort() {
return super.usingAnyFreePort();
}
Expand All @@ -476,6 +484,7 @@ public AppiumServiceBuilder usingAnyFreePort() {
* @param logFile A file to write log to.
* @return A self reference.
*/
@Override
public AppiumServiceBuilder withLogFile(File logFile) {
return super.withLogFile(logFile);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,26 @@ private static File findCustomNode() {
}
}
}

@Test public void checkAbilityToBuildServiceWithPortUsingFlag() throws Exception {
String port = "8996";
String expectedUrl = String.format("http://0.0.0.0:%s/wd/hub", port);

AppiumDriverLocalService service = new AppiumServiceBuilder()
.withArgument(() -> "--port", port)
.build();
String actualUrl = service.getUrl().toString();
assertEquals(expectedUrl, actualUrl);
}

@Test public void checkAbilityToBuildServiceWithPortUsingShortFlag() throws Exception {
String port = "8996";
String expectedUrl = String.format("http://0.0.0.0:%s/wd/hub", port);

AppiumDriverLocalService service = new AppiumServiceBuilder()
.withArgument(() -> "-p", port)
.build();
String actualUrl = service.getUrl().toString();
assertEquals(expectedUrl, actualUrl);
}
}