Skip to content

Commit f69e095

Browse files
Exposed replaceValue which is available in appium and python client in the java-client.
1 parent d70f3b4 commit f69e095

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

src/main/java/io/appium/java_client/AppiumDriver.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import static io.appium.java_client.MobileCommand.PULL_FOLDER;
3939
import static io.appium.java_client.MobileCommand.PUSH_FILE;
4040
import static io.appium.java_client.MobileCommand.REMOVE_APP;
41+
import static io.appium.java_client.MobileCommand.REPLACE_VALUE;
4142
import static io.appium.java_client.MobileCommand.RESET;
4243
import static io.appium.java_client.MobileCommand.RUN_APP_IN_BACKGROUND;
4344
import static io.appium.java_client.MobileCommand.SET_NETWORK_CONNECTION;
@@ -216,6 +217,8 @@ public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities) {
216217
getC("/session/:sessionId/appium/device/current_activity"))
217218
.put(SET_VALUE,
218219
postC("/session/:sessionId/appium/element/:id/value"))
220+
.put(REPLACE_VALUE,
221+
postC("/session/:sessionId/appium/element/:id/replace_value"))
219222
.put(PULL_FILE,
220223
postC("/session/:sessionId/appium/device/pull_file"))
221224
.put(PULL_FOLDER,

src/main/java/io/appium/java_client/MobileCommand.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public interface MobileCommand {
2929
String KEY_EVENT = "keyEvent";
3030
String CURRENT_ACTIVITY = "currentActivity";
3131
String SET_VALUE = "setValue";
32+
String REPLACE_VALUE = "replaceValue";
3233
String PULL_FILE = "pullFile";
3334
String PUSH_FILE = "pushFile";
3435
String PULL_FOLDER = "pullFolder";

src/main/java/io/appium/java_client/android/AndroidElement.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66
import org.openqa.selenium.WebElement;
77

8+
import com.google.common.collect.ImmutableMap;
89
import io.appium.java_client.FindsByAndroidUIAutomator;
10+
import io.appium.java_client.MobileCommand;
911
import io.appium.java_client.MobileElement;
1012

1113

@@ -26,4 +28,10 @@ public List<MobileElement> findElementsByAndroidUIAutomator(String using) {
2628
return result;
2729
}
2830

31+
@SuppressWarnings({ "rawtypes", "unchecked" })
32+
public void replaceValue(String value) {
33+
ImmutableMap.Builder builder = ImmutableMap.builder();
34+
builder.put("id", getId()).put("value", new String[] { value });
35+
execute(MobileCommand.REPLACE_VALUE, builder.build());
36+
}
2937
}

src/test/java/io/appium/java_client/android/AndroidUIAutomatorTest.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,27 @@ public void findChainedElementsTest() {
7474
assertTrue(el3.isDisplayed());
7575
}
7676

77-
@Test(expected = IllegalArgumentException.class)
77+
@Test
78+
public void replaceValue() {
79+
String originalValue = "original value";
80+
String replacedValue = "replaced value";
81+
82+
driver.scrollToExact("Views").click();
83+
driver.findElementByAndroidUIAutomator("text(\"Controls\")").click();
84+
driver.findElementByAndroidUIAutomator("text(\"1. Light Theme\")").click();
85+
86+
AndroidElement editElement = driver.findElementByAndroidUIAutomator("resourceId(\"com.example.android.apis:id/edit\")");
87+
88+
editElement.sendKeys(originalValue);
89+
90+
assertEquals(originalValue, editElement.getText());
91+
92+
editElement.replaceValue(replacedValue);
93+
94+
assertEquals(replacedValue, editElement.getText());
95+
}
96+
97+
@Test(expected = IllegalArgumentException.class)
7898
public void ErrorTest() {
7999
driver.findElementByAndroidUIAutomator(null);
80100
}

0 commit comments

Comments
 (0)