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
29 changes: 27 additions & 2 deletions src/main/java/io/appium/java_client/AppiumDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.service.local.AppiumDriverLocalService;
import io.appium.java_client.service.local.AppiumServiceBuilder;

import org.openqa.selenium.By;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.DeviceRotation;
Expand All @@ -39,7 +38,6 @@
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.html5.Location;

import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.DriverCommand;
Expand All @@ -49,8 +47,10 @@
import org.openqa.selenium.remote.Response;
import org.openqa.selenium.remote.html5.RemoteLocationContext;
import org.openqa.selenium.remote.http.HttpClient;
import org.openqa.selenium.remote.http.HttpMethod;

import java.net.URL;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -288,6 +288,31 @@ public void rotate(ScreenOrientation orientation) {
ImmutableMap.of("orientation", orientation.value().toUpperCase()));
}

/**
* This method is used to add custom appium commands in Appium 2.0.
*
* @param httpMethod the available {@link HttpMethod}.
* @param url The url to URL template as https://www.w3.org/TR/webdriver/#endpoints.
* @param methodName The name of custom appium command.
*/
public void addCommand(HttpMethod httpMethod, String url, String methodName) {
switch (httpMethod) {
case GET:
MobileCommand.commandRepository.put(methodName, MobileCommand.getC(url));
break;
case POST:
MobileCommand.commandRepository.put(methodName, MobileCommand.postC(url));
break;
case DELETE:
MobileCommand.commandRepository.put(methodName, MobileCommand.deleteC(url));
break;
default:
throw new WebDriverException(String.format("Unsupported HTTP Method: %s. Only %s methods are supported",
httpMethod,
Arrays.toString(HttpMethod.values())));
}
}

@Override
public ScreenOrientation getOrientation() {
Response response = execute(DriverCommand.GET_SCREEN_ORIENTATION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ public Response execute(Command command) throws WebDriverException {
}
});
}
if (getAdditionalCommands().containsKey(command.getName())) {
super.defineCommand(command.getName(), getAdditionalCommands().get(command.getName()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we verify if the defined command does not override an existing one?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At server side of plugin, we allow to override the behaviour of an Appium command though the path of command remain same. Keep the client side in line with server, I would like to allow client plugins also to override the existing command in same path with a different behaviour.

}

Response response;
try {
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/io/appium/java_client/ios/AppIOSTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ public static void beforeClass() throws Exception {
driver = new IOSDriver<>(new URL("http://" + ip + ":" + PORT + "/wd/hub"), capabilities);
}
}
}
}
4 changes: 2 additions & 2 deletions src/test/java/io/appium/java_client/ios/BaseIOSTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public class BaseIOSTest {
protected static IOSDriver<IOSElement> driver;
protected static final int PORT = 4723;
public static final String DEVICE_NAME = System.getenv("IOS_DEVICE_NAME") != null
? System.getenv("IOS_DEVICE_NAME") : "iPhone X";
? System.getenv("IOS_DEVICE_NAME") : "iPhone 12";
public static final String PLATFORM_VERSION = System.getenv("IOS_PLATFORM_VERSION") != null
? System.getenv("IOS_PLATFORM_VERSION") : "11.4";
? System.getenv("IOS_PLATFORM_VERSION") : "14.5";


/**
Expand Down
29 changes: 28 additions & 1 deletion src/test/java/io/appium/java_client/ios/IOSDriverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,52 @@
import static org.hamcrest.Matchers.greaterThan;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import com.google.common.collect.ImmutableMap;
import io.appium.java_client.MobileElement;
import io.appium.java_client.appmanagement.ApplicationState;
import io.appium.java_client.remote.HideKeyboardStrategy;
import org.junit.Ignore;
import org.junit.Test;

import org.openqa.selenium.By;
import org.openqa.selenium.ScreenOrientation;
import org.openqa.selenium.html5.Location;
import org.openqa.selenium.remote.Response;
import org.openqa.selenium.remote.http.HttpMethod;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.time.Duration;

public class IOSDriverTest extends AppIOSTest {

@Test
public void addCustomCommandTest() {
driver.addCommand(HttpMethod.GET, "/sessions", "getSessions");
final Response getSessions = driver.execute("getSessions");
assertNotNull(getSessions.getSessionId());
}

@Test
public void addCustomCommandWithSessionIdTest() {
driver.addCommand(HttpMethod.POST, "/session/" + driver.getSessionId() + "/appium/app/launch", "launchApplication");
final Response launchApplication = driver.execute("launchApplication");
assertNotNull(launchApplication.getSessionId());
}

@Test
public void addCustomCommandWithElementIdTest() {
IOSElement intA = driver.findElementById("IntegerA");
intA.clear();
driver.addCommand(HttpMethod.POST,
String.format("/session/%s/appium/element/%s/value", driver.getSessionId(), intA.getId()), "setNewValue");
final Response setNewValue = driver.execute("setNewValue", ImmutableMap.of("id", intA.getId(), "value", "8"));
assertNotNull(setNewValue.getSessionId());
}

@Test
public void getDeviceTimeTest() {
String time = driver.getDeviceTime();
Expand Down