Skip to content

The addition to #522 #524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Nov 25, 2016
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,16 @@ 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".equalsIgnoreCase(argName) || "-p".equalsIgnoreCase(argName)) {
usingPort(Integer.valueOf(value));
} else if ("--address".equalsIgnoreCase(argName) || "-a".equalsIgnoreCase(argName)) {
withIPAddress(value);
} else if ("--log".equalsIgnoreCase(argName) || "-g".equalsIgnoreCase(argName)) {
withLogFile(new File(value));
} else {
serverArguments.put(argName, value);
}
return this;
}

Expand Down Expand Up @@ -434,6 +443,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 @@ -445,6 +455,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 @@ -454,6 +465,7 @@ public AppiumServiceBuilder usingPort(int port) {
*
* @return A self reference.
*/
@Override
public AppiumServiceBuilder usingAnyFreePort() {
return super.usingAnyFreePort();
}
Expand All @@ -475,6 +487,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
@@ -1,5 +1,7 @@
package io.appium.java_client.android;

import static org.junit.Assert.assertEquals;

import io.appium.java_client.remote.AutomationName;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.service.local.AppiumDriverLocalService;
Expand All @@ -13,8 +15,6 @@

import java.io.File;

import static org.junit.Assert.assertEquals;

public class UIAutomator2Test {
private static AppiumDriverLocalService service;
protected static AndroidDriver<AndroidElement> driver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ private static File findCustomNode() {
}

@Test public void checkAbilityToChangeOutputStream() throws Exception {
File file = new File("target/test");
File file = new File("test");
file.createNewFile();
OutputStream stream = new FileOutputStream(file);
AppiumDriverLocalService service = AppiumDriverLocalService.buildDefaultService();
Expand All @@ -243,7 +243,7 @@ private static File findCustomNode() {
}

@Test public void checkAbilityToChangeOutputStreamAfterTheServiceIsStarted() throws Exception {
File file = new File("target/test");
File file = new File("test");
file.createNewFile();
OutputStream stream = new FileOutputStream(file);
AppiumDriverLocalService service = AppiumDriverLocalService.buildDefaultService();
Expand Down Expand Up @@ -295,8 +295,7 @@ private static File findCustomNode() {

@Test public void checkAbilityToStartServiceWithLogFile() throws Exception {
AppiumDriverLocalService service = null;
File rootLogDir = new File("target/");
File log = new File(rootLogDir, "Log.txt");
File log = new File("Log.txt");
log.createNewFile();
try {
service = new AppiumServiceBuilder().withLogFile(log).build();
Expand All @@ -312,4 +311,124 @@ 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 = null;

try {
service = new AppiumServiceBuilder()
.withArgument(() -> "--port", port)
.build();
service.start();
String actualUrl = service.getUrl().toString();
assertEquals(expectedUrl, actualUrl);
} finally {
if (service != null) {
service.stop();
}
}
}

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

AppiumDriverLocalService service = null;

try {
service = new AppiumServiceBuilder()
.withArgument(() -> "-p", port)
.build();
service.start();
String actualUrl = service.getUrl().toString();
assertEquals(expectedUrl, actualUrl);
} finally {
if (service != null) {
service.stop();
}
}
}

@Test public void checkAbilityToBuildServiceWithIpUsingFlag() throws Exception {
String expectedUrl = String.format("http://%s:%s/wd/hub", testIP, 4723);

AppiumDriverLocalService service = null;

try {
service = new AppiumServiceBuilder()
.withArgument(() -> "--address", testIP)
.build();
service.start();
String actualUrl = service.getUrl().toString();
assertEquals(expectedUrl, actualUrl);
} finally {
if (service != null) {
service.stop();
}
}
}

@Test public void checkAbilityToBuildServiceWithIpUsingShortFlag() throws Exception {
String expectedUrl = String.format("http://%s:%s/wd/hub", testIP, 4723);

AppiumDriverLocalService service = null;

try {
service = new AppiumServiceBuilder()
.withArgument(() -> "-a", testIP)
.build();
service.start();
String actualUrl = service.getUrl().toString();
assertEquals(expectedUrl, actualUrl);
} finally {
if (service != null) {
service.stop();
}
}
}

@Test public void checkAbilityToBuildServiceWithLogFileUsingFlag() throws Exception {
AppiumDriverLocalService service = null;

File log = new File("Log2.txt");

try {
service = new AppiumServiceBuilder()
.withArgument(() -> "--log", log.getAbsolutePath())
.build();
service.start();
assertTrue(log.exists());
} finally {
if (service != null) {
service.stop();
}
if (log.exists()) {
log.delete();
}
}
}

@Test public void checkAbilityToBuildServiceWithLogFileUsingShortFlag() throws Exception {
AppiumDriverLocalService service = null;

File log = new File("Log3.txt");

try {
service = new AppiumServiceBuilder()
.withArgument(() -> "-g", log.getAbsolutePath())
.build();
service.start();
assertTrue(log.exists());
} finally {
if (service != null) {
service.stop();
}
if (log.exists()) {
log.delete();
}
}
}
}