Skip to content

Commit fcb9cc9

Browse files
Exposed replaceValue which is available in appium and python client in the java-client.
1 parent 86a3850 commit fcb9cc9

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

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

Lines changed: 4 additions & 1 deletion
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;
@@ -675,7 +676,9 @@ private static ImmutableMap<String, CommandInfo> getMobileCommands(){
675676
getC("/session/:sessionId/appium/device/current_activity"))
676677
.put(SET_VALUE,
677678
postC("/session/:sessionId/appium/element/:id/value"))
678-
.put(PULL_FILE,
679+
.put(REPLACE_VALUE,
680+
postC("/session/:sessionId/appium/element/:id/replace_value"))
681+
.put(PULL_FILE,
679682
postC("/session/:sessionId/appium/device/pull_file"))
680683
.put(PULL_FOLDER,
681684
postC("/session/:sessionId/appium/device/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
@@ -82,7 +82,27 @@ public void findChainedElementsTest() {
8282
assertTrue(el3.isDisplayed());
8383
}
8484

85-
@Test(expected = IllegalArgumentException.class)
85+
@Test
86+
public void replaceValue() {
87+
String originalValue = "original value";
88+
String replacedValue = "replaced value";
89+
90+
driver.scrollToExact("Views").click();
91+
driver.findElementByAndroidUIAutomator("text(\"Controls\")").click();
92+
driver.findElementByAndroidUIAutomator("text(\"1. Light Theme\")").click();
93+
94+
AndroidElement editElement = driver.findElementByAndroidUIAutomator("resourceId(\"com.example.android.apis:id/edit\")");
95+
96+
editElement.sendKeys(originalValue);
97+
98+
assertEquals(originalValue, editElement.getText());
99+
100+
editElement.replaceValue(replacedValue);
101+
102+
assertEquals(replacedValue, editElement.getText());
103+
}
104+
105+
@Test(expected = IllegalArgumentException.class)
86106
public void ErrorTest() {
87107
driver.findElementByAndroidUIAutomator(null);
88108
}

0 commit comments

Comments
 (0)