From b5fbe517a49bd88815bee144d69e22770275c2c0 Mon Sep 17 00:00:00 2001 From: Srinivasan Sekar Date: Sat, 21 Aug 2021 22:46:52 +0530 Subject: [PATCH 1/7] add new commands --- .../io/appium/java_client/AppiumDriver.java | 42 +++++++++---------- .../remote/AppiumCommandExecutor.java | 5 +++ .../io/appium/java_client/ios/AppIOSTest.java | 14 +------ .../appium/java_client/ios/BaseIOSTest.java | 4 +- .../appium/java_client/ios/IOSDriverTest.java | 7 ++++ 5 files changed, 34 insertions(+), 38 deletions(-) diff --git a/src/main/java/io/appium/java_client/AppiumDriver.java b/src/main/java/io/appium/java_client/AppiumDriver.java index 32785d1eb..21bdb0d69 100644 --- a/src/main/java/io/appium/java_client/AppiumDriver.java +++ b/src/main/java/io/appium/java_client/AppiumDriver.java @@ -16,39 +16,19 @@ package io.appium.java_client; -import static com.google.common.base.Preconditions.checkNotNull; -import static io.appium.java_client.remote.MobileCapabilityType.PLATFORM_NAME; -import static org.apache.commons.lang3.StringUtils.containsIgnoreCase; -import static org.apache.commons.lang3.StringUtils.isBlank; - import com.google.common.collect.ImmutableMap; - import io.appium.java_client.internal.CapabilityHelpers; import io.appium.java_client.internal.JsonToMobileElementConverter; import io.appium.java_client.remote.AppiumCommandExecutor; 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; -import org.openqa.selenium.MutableCapabilities; -import org.openqa.selenium.ScreenOrientation; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebDriverException; -import org.openqa.selenium.WebElement; +import org.openqa.selenium.*; import org.openqa.selenium.html5.Location; - -import org.openqa.selenium.remote.CapabilityType; -import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.remote.DriverCommand; -import org.openqa.selenium.remote.ErrorHandler; -import org.openqa.selenium.remote.ExecuteMethod; -import org.openqa.selenium.remote.HttpCommandExecutor; -import org.openqa.selenium.remote.Response; +import org.openqa.selenium.remote.*; 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.LinkedHashSet; @@ -56,6 +36,11 @@ import java.util.Map; import java.util.Set; +import static com.google.common.base.Preconditions.checkNotNull; +import static io.appium.java_client.remote.MobileCapabilityType.PLATFORM_NAME; +import static org.apache.commons.lang3.StringUtils.containsIgnoreCase; +import static org.apache.commons.lang3.StringUtils.isBlank; + /** * Default Appium driver implementation. * @@ -288,6 +273,17 @@ public void rotate(ScreenOrientation orientation) { ImmutableMap.of("orientation", orientation.value().toUpperCase())); } + public void addCommand(HttpMethod method, String url, String name) { + if (method == HttpMethod.POST) { + MobileCommand.commandRepository.put(name, MobileCommand.postC(url)); + } else if (method == HttpMethod.GET) { + MobileCommand.commandRepository.put(name, MobileCommand.getC(url)); + } else if (method == HttpMethod.DELETE) { + MobileCommand.commandRepository.put(name, MobileCommand.deleteC(url)); + } + new AppiumCommandExecutor(MobileCommand.commandRepository, remoteAddress).defineCommand(name); + } + @Override public ScreenOrientation getOrientation() { Response response = execute(DriverCommand.GET_SCREEN_ORIENTATION); diff --git a/src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java b/src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java index ea0ade5f0..2f83e63a1 100644 --- a/src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java +++ b/src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java @@ -274,4 +274,9 @@ && getCommandCodec() instanceof W3CHttpCommandCodec) { return response; } + + public void defineCommand(String commandName) { + setCommandCodec(new AppiumW3CHttpCommandCodec()); + super.defineCommand(commandName, getAdditionalCommands().get(commandName)); + } } diff --git a/src/test/java/io/appium/java_client/ios/AppIOSTest.java b/src/test/java/io/appium/java_client/ios/AppIOSTest.java index 12426ebd9..6fbc4cbbc 100644 --- a/src/test/java/io/appium/java_client/ios/AppIOSTest.java +++ b/src/test/java/io/appium/java_client/ios/AppIOSTest.java @@ -3,9 +3,7 @@ import io.appium.java_client.remote.AutomationName; import io.appium.java_client.remote.IOSMobileCapabilityType; import io.appium.java_client.remote.MobileCapabilityType; -import io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException; import org.junit.BeforeClass; -import org.openqa.selenium.SessionNotCreatedException; import org.openqa.selenium.remote.DesiredCapabilities; import java.net.URL; @@ -18,11 +16,6 @@ public class AppIOSTest extends BaseIOSTest { @BeforeClass public static void beforeClass() throws Exception { - final String ip = startAppiumServer(); - - if (service == null || !service.isRunning()) { - throw new AppiumServerHasNotBeenStartedLocallyException("An appium server node is not started!"); - } DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, PLATFORM_VERSION); @@ -32,11 +25,6 @@ public static void beforeClass() throws Exception { capabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 500000); capabilities.setCapability("commandTimeouts", "120000"); capabilities.setCapability(MobileCapabilityType.APP, testAppZip().toAbsolutePath().toString()); - try { - driver = new IOSDriver<>(new URL("http://" + ip + ":" + PORT + "/wd/hub"), capabilities); - } catch (SessionNotCreatedException e) { - capabilities.setCapability("useNewWDA", true); - driver = new IOSDriver<>(new URL("http://" + ip + ":" + PORT + "/wd/hub"), capabilities); - } + driver = new IOSDriver<>(new URL("http://localhost:4723/wd/hub"), capabilities); } } diff --git a/src/test/java/io/appium/java_client/ios/BaseIOSTest.java b/src/test/java/io/appium/java_client/ios/BaseIOSTest.java index 45e7a8e2e..9275dd10b 100644 --- a/src/test/java/io/appium/java_client/ios/BaseIOSTest.java +++ b/src/test/java/io/appium/java_client/ios/BaseIOSTest.java @@ -31,9 +31,9 @@ public class BaseIOSTest { protected static IOSDriver 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"; /** diff --git a/src/test/java/io/appium/java_client/ios/IOSDriverTest.java b/src/test/java/io/appium/java_client/ios/IOSDriverTest.java index 40ecb5a9b..16e729de1 100644 --- a/src/test/java/io/appium/java_client/ios/IOSDriverTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSDriverTest.java @@ -34,6 +34,7 @@ import org.openqa.selenium.By; import org.openqa.selenium.ScreenOrientation; import org.openqa.selenium.html5.Location; +import org.openqa.selenium.remote.http.HttpMethod; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; @@ -41,6 +42,12 @@ public class IOSDriverTest extends AppIOSTest { + @Test + public void addCommandTest() { + driver.addCommand(HttpMethod.GET, "/sessions", "getSessions"); + driver.execute("getSessions"); + } + @Test public void getDeviceTimeTest() { String time = driver.getDeviceTime(); From b0de4e4e7b680cffacb25d978ff27ba1a8f21e31 Mon Sep 17 00:00:00 2001 From: Srinivasan Sekar Date: Sat, 21 Aug 2021 23:43:54 +0530 Subject: [PATCH 2/7] fix commandCodec issue --- .../io/appium/java_client/AppiumDriver.java | 1 - .../remote/AppiumCommandExecutor.java | 26 ++++++++----------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/main/java/io/appium/java_client/AppiumDriver.java b/src/main/java/io/appium/java_client/AppiumDriver.java index 21bdb0d69..b697b8a68 100644 --- a/src/main/java/io/appium/java_client/AppiumDriver.java +++ b/src/main/java/io/appium/java_client/AppiumDriver.java @@ -281,7 +281,6 @@ public void addCommand(HttpMethod method, String url, String name) { } else if (method == HttpMethod.DELETE) { MobileCommand.commandRepository.put(name, MobileCommand.deleteC(url)); } - new AppiumCommandExecutor(MobileCommand.commandRepository, remoteAddress).defineCommand(name); } @Override diff --git a/src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java b/src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java index 2f83e63a1..c447d3d26 100644 --- a/src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java +++ b/src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java @@ -16,20 +16,10 @@ package io.appium.java_client.remote; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Throwables.throwIfUnchecked; -import static java.lang.String.format; -import static java.nio.charset.StandardCharsets.UTF_8; -import static java.util.Optional.ofNullable; -import static java.util.logging.Logger.getLogger; -import static org.openqa.selenium.remote.DriverCommand.NEW_SESSION; - import com.google.common.base.Supplier; import com.google.common.base.Throwables; - import com.google.common.io.CountingOutputStream; import com.google.common.io.FileBackedOutputStream; - import io.appium.java_client.internal.Config; import org.openqa.selenium.Capabilities; import org.openqa.selenium.ImmutableCapabilities; @@ -64,6 +54,14 @@ import java.util.Optional; import java.util.UUID; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Throwables.throwIfUnchecked; +import static java.lang.String.format; +import static java.nio.charset.StandardCharsets.UTF_8; +import static java.util.Optional.ofNullable; +import static java.util.logging.Logger.getLogger; +import static org.openqa.selenium.remote.DriverCommand.NEW_SESSION; + public class AppiumCommandExecutor extends HttpCommandExecutor { // https://github.com/appium/appium-base-driver/pull/400 private static final String IDEMPOTENCY_KEY_HEADER = "X-Idempotency-Key"; @@ -241,6 +239,9 @@ public Response execute(Command command) throws WebDriverException { } }); } + if (getAdditionalCommands().containsKey(command.getName())) { + super.defineCommand(command.getName(), getAdditionalCommands().get(command.getName())); + } Response response; try { @@ -274,9 +275,4 @@ && getCommandCodec() instanceof W3CHttpCommandCodec) { return response; } - - public void defineCommand(String commandName) { - setCommandCodec(new AppiumW3CHttpCommandCodec()); - super.defineCommand(commandName, getAdditionalCommands().get(commandName)); - } } From 075cc170c471086b9e44c319f9a66a6092d33ecc Mon Sep 17 00:00:00 2001 From: Srinivasan Sekar Date: Sat, 21 Aug 2021 23:48:55 +0530 Subject: [PATCH 3/7] switch appIOSTest --- .../io/appium/java_client/ios/AppIOSTest.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/test/java/io/appium/java_client/ios/AppIOSTest.java b/src/test/java/io/appium/java_client/ios/AppIOSTest.java index 6fbc4cbbc..bdc75a01b 100644 --- a/src/test/java/io/appium/java_client/ios/AppIOSTest.java +++ b/src/test/java/io/appium/java_client/ios/AppIOSTest.java @@ -3,7 +3,9 @@ import io.appium.java_client.remote.AutomationName; import io.appium.java_client.remote.IOSMobileCapabilityType; import io.appium.java_client.remote.MobileCapabilityType; +import io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException; import org.junit.BeforeClass; +import org.openqa.selenium.SessionNotCreatedException; import org.openqa.selenium.remote.DesiredCapabilities; import java.net.URL; @@ -16,6 +18,11 @@ public class AppIOSTest extends BaseIOSTest { @BeforeClass public static void beforeClass() throws Exception { + final String ip = startAppiumServer(); + + if (service == null || !service.isRunning()) { + throw new AppiumServerHasNotBeenStartedLocallyException("An appium server node is not started!"); + } DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, PLATFORM_VERSION); @@ -25,6 +32,11 @@ public static void beforeClass() throws Exception { capabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 500000); capabilities.setCapability("commandTimeouts", "120000"); capabilities.setCapability(MobileCapabilityType.APP, testAppZip().toAbsolutePath().toString()); - driver = new IOSDriver<>(new URL("http://localhost:4723/wd/hub"), capabilities); + try { + driver = new IOSDriver<>(new URL("http://" + ip + ":" + PORT + "/wd/hub"), capabilities); + } catch (SessionNotCreatedException e) { + capabilities.setCapability("useNewWDA", true); + driver = new IOSDriver<>(new URL("http://" + ip + ":" + PORT + "/wd/hub"), capabilities); + } } -} +} \ No newline at end of file From 0165dc0bbb4816e6551b06a3a8e0dd06296050ad Mon Sep 17 00:00:00 2001 From: Srinivasan Sekar Date: Sat, 21 Aug 2021 23:58:12 +0530 Subject: [PATCH 4/7] fix checkstyle issues --- .../io/appium/java_client/AppiumDriver.java | 35 +++++++++++++++---- .../remote/AppiumCommandExecutor.java | 18 +++++----- 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/src/main/java/io/appium/java_client/AppiumDriver.java b/src/main/java/io/appium/java_client/AppiumDriver.java index b697b8a68..c1b687a41 100644 --- a/src/main/java/io/appium/java_client/AppiumDriver.java +++ b/src/main/java/io/appium/java_client/AppiumDriver.java @@ -16,16 +16,35 @@ package io.appium.java_client; +import static com.google.common.base.Preconditions.checkNotNull; +import static io.appium.java_client.remote.MobileCapabilityType.PLATFORM_NAME; +import static org.apache.commons.lang3.StringUtils.containsIgnoreCase; +import static org.apache.commons.lang3.StringUtils.isBlank; + import com.google.common.collect.ImmutableMap; + import io.appium.java_client.internal.CapabilityHelpers; import io.appium.java_client.internal.JsonToMobileElementConverter; import io.appium.java_client.remote.AppiumCommandExecutor; 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.*; +import org.openqa.selenium.By; +import org.openqa.selenium.Capabilities; +import org.openqa.selenium.DeviceRotation; +import org.openqa.selenium.MutableCapabilities; +import org.openqa.selenium.ScreenOrientation; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebDriverException; +import org.openqa.selenium.WebElement; import org.openqa.selenium.html5.Location; -import org.openqa.selenium.remote.*; +import org.openqa.selenium.remote.CapabilityType; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.remote.DriverCommand; +import org.openqa.selenium.remote.ErrorHandler; +import org.openqa.selenium.remote.ExecuteMethod; +import org.openqa.selenium.remote.HttpCommandExecutor; +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; @@ -36,11 +55,6 @@ import java.util.Map; import java.util.Set; -import static com.google.common.base.Preconditions.checkNotNull; -import static io.appium.java_client.remote.MobileCapabilityType.PLATFORM_NAME; -import static org.apache.commons.lang3.StringUtils.containsIgnoreCase; -import static org.apache.commons.lang3.StringUtils.isBlank; - /** * Default Appium driver implementation. * @@ -273,6 +287,13 @@ 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 method the available {@link HttpMethod}. + * @param url The url to URL template as https://www.w3.org/TR/webdriver/#endpoints. + * @param name The name of custom appium command. + */ public void addCommand(HttpMethod method, String url, String name) { if (method == HttpMethod.POST) { MobileCommand.commandRepository.put(name, MobileCommand.postC(url)); diff --git a/src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java b/src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java index c447d3d26..2b0f77f7e 100644 --- a/src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java +++ b/src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java @@ -16,10 +16,20 @@ package io.appium.java_client.remote; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Throwables.throwIfUnchecked; +import static java.lang.String.format; +import static java.nio.charset.StandardCharsets.UTF_8; +import static java.util.Optional.ofNullable; +import static java.util.logging.Logger.getLogger; +import static org.openqa.selenium.remote.DriverCommand.NEW_SESSION; + import com.google.common.base.Supplier; import com.google.common.base.Throwables; + import com.google.common.io.CountingOutputStream; import com.google.common.io.FileBackedOutputStream; + import io.appium.java_client.internal.Config; import org.openqa.selenium.Capabilities; import org.openqa.selenium.ImmutableCapabilities; @@ -54,14 +64,6 @@ import java.util.Optional; import java.util.UUID; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Throwables.throwIfUnchecked; -import static java.lang.String.format; -import static java.nio.charset.StandardCharsets.UTF_8; -import static java.util.Optional.ofNullable; -import static java.util.logging.Logger.getLogger; -import static org.openqa.selenium.remote.DriverCommand.NEW_SESSION; - public class AppiumCommandExecutor extends HttpCommandExecutor { // https://github.com/appium/appium-base-driver/pull/400 private static final String IDEMPOTENCY_KEY_HEADER = "X-Idempotency-Key"; From 2ad38e11f7041e97b1bbbd4c2b2727996a09cb96 Mon Sep 17 00:00:00 2001 From: Srinivasan Sekar Date: Sun, 22 Aug 2021 00:03:41 +0530 Subject: [PATCH 5/7] improve assertions in tests --- src/test/java/io/appium/java_client/ios/IOSDriverTest.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/test/java/io/appium/java_client/ios/IOSDriverTest.java b/src/test/java/io/appium/java_client/ios/IOSDriverTest.java index 16e729de1..516605901 100644 --- a/src/test/java/io/appium/java_client/ios/IOSDriverTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSDriverTest.java @@ -22,6 +22,7 @@ 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; @@ -34,6 +35,7 @@ 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; @@ -43,9 +45,10 @@ public class IOSDriverTest extends AppIOSTest { @Test - public void addCommandTest() { + public void addCustomCommandTest() { driver.addCommand(HttpMethod.GET, "/sessions", "getSessions"); - driver.execute("getSessions"); + final Response getSessions = driver.execute("getSessions"); + assertNotNull(getSessions.getSessionId()); } @Test From 062a26133b6a09810197fa259023d063d177ec29 Mon Sep 17 00:00:00 2001 From: Srinivasan Sekar Date: Sat, 28 Aug 2021 13:12:46 +0530 Subject: [PATCH 6/7] address review comments --- .../io/appium/java_client/AppiumDriver.java | 24 ++++++++++++------- .../appium/java_client/ios/IOSDriverTest.java | 21 ++++++++++++++++ 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/main/java/io/appium/java_client/AppiumDriver.java b/src/main/java/io/appium/java_client/AppiumDriver.java index c1b687a41..f23bbae7f 100644 --- a/src/main/java/io/appium/java_client/AppiumDriver.java +++ b/src/main/java/io/appium/java_client/AppiumDriver.java @@ -290,17 +290,23 @@ public void rotate(ScreenOrientation orientation) { /** * This method is used to add custom appium commands in Appium 2.0. * - * @param method the available {@link HttpMethod}. + * @param httpMethod the available {@link HttpMethod}. * @param url The url to URL template as https://www.w3.org/TR/webdriver/#endpoints. - * @param name The name of custom appium command. + * @param methodName The name of custom appium command. */ - public void addCommand(HttpMethod method, String url, String name) { - if (method == HttpMethod.POST) { - MobileCommand.commandRepository.put(name, MobileCommand.postC(url)); - } else if (method == HttpMethod.GET) { - MobileCommand.commandRepository.put(name, MobileCommand.getC(url)); - } else if (method == HttpMethod.DELETE) { - MobileCommand.commandRepository.put(name, MobileCommand.deleteC(url)); + 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("Unsupported HTTP Method: " + httpMethod); } } diff --git a/src/test/java/io/appium/java_client/ios/IOSDriverTest.java b/src/test/java/io/appium/java_client/ios/IOSDriverTest.java index 516605901..1f5b75b11 100644 --- a/src/test/java/io/appium/java_client/ios/IOSDriverTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSDriverTest.java @@ -41,6 +41,8 @@ import org.openqa.selenium.support.ui.WebDriverWait; import java.time.Duration; +import java.util.HashMap; +import java.util.Map; public class IOSDriverTest extends AppIOSTest { @@ -51,6 +53,25 @@ public void addCustomCommandTest() { 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, "/session/" + driver.getSessionId() + "/appium/element/" + intA.getId() + "/value", "setNewValue"); + Map parameters = new HashMap<>(); + parameters.put("id", intA.getId()); + parameters.put("value", "8"); + final Response launchApplication = driver.execute("setNewValue", parameters); + assertNotNull(launchApplication.getSessionId()); + } + @Test public void getDeviceTimeTest() { String time = driver.getDeviceTime(); From f46e1f627d3509333f7ecfcb013fc33a9e1521d2 Mon Sep 17 00:00:00 2001 From: Srinivasan Sekar Date: Mon, 30 Aug 2021 10:21:08 +0530 Subject: [PATCH 7/7] address review comments --- .../java/io/appium/java_client/AppiumDriver.java | 5 ++++- .../io/appium/java_client/ios/IOSDriverTest.java | 14 +++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/java/io/appium/java_client/AppiumDriver.java b/src/main/java/io/appium/java_client/AppiumDriver.java index f23bbae7f..fd512197a 100644 --- a/src/main/java/io/appium/java_client/AppiumDriver.java +++ b/src/main/java/io/appium/java_client/AppiumDriver.java @@ -50,6 +50,7 @@ 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; @@ -306,7 +307,9 @@ public void addCommand(HttpMethod httpMethod, String url, String methodName) { MobileCommand.commandRepository.put(methodName, MobileCommand.deleteC(url)); break; default: - throw new WebDriverException("Unsupported HTTP Method: " + httpMethod); + throw new WebDriverException(String.format("Unsupported HTTP Method: %s. Only %s methods are supported", + httpMethod, + Arrays.toString(HttpMethod.values()))); } } diff --git a/src/test/java/io/appium/java_client/ios/IOSDriverTest.java b/src/test/java/io/appium/java_client/ios/IOSDriverTest.java index 1f5b75b11..a1d7a0fb3 100644 --- a/src/test/java/io/appium/java_client/ios/IOSDriverTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSDriverTest.java @@ -26,12 +26,12 @@ 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; @@ -41,8 +41,6 @@ import org.openqa.selenium.support.ui.WebDriverWait; import java.time.Duration; -import java.util.HashMap; -import java.util.Map; public class IOSDriverTest extends AppIOSTest { @@ -64,12 +62,10 @@ public void addCustomCommandWithSessionIdTest() { public void addCustomCommandWithElementIdTest() { IOSElement intA = driver.findElementById("IntegerA"); intA.clear(); - driver.addCommand(HttpMethod.POST, "/session/" + driver.getSessionId() + "/appium/element/" + intA.getId() + "/value", "setNewValue"); - Map parameters = new HashMap<>(); - parameters.put("id", intA.getId()); - parameters.put("value", "8"); - final Response launchApplication = driver.execute("setNewValue", parameters); - assertNotNull(launchApplication.getSessionId()); + 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