Skip to content

Commit 179f7f9

Browse files
committed
Merge pull request #235 from ahansen1/replaceValue
Exposed replaceValue which is available in appium and python client i…
2 parents 2e398da + d4f1b79 commit 179f7f9

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
@@ -6,7 +6,9 @@
66
import org.openqa.selenium.WebDriverException;
77
import org.openqa.selenium.WebElement;
88

9+
import com.google.common.collect.ImmutableMap;
910
import io.appium.java_client.FindsByAndroidUIAutomator;
11+
import io.appium.java_client.MobileCommand;
1012
import io.appium.java_client.MobileElement;
1113

1214

@@ -33,4 +35,10 @@ public List<MobileElement> findElementsByAndroidUIAutomator(String using) throws
3335
return result;
3436
}
3537

38+
@SuppressWarnings({ "rawtypes", "unchecked" })
39+
public void replaceValue(String value) {
40+
ImmutableMap.Builder builder = ImmutableMap.builder();
41+
builder.put("id", getId()).put("value", new String[] { value });
42+
execute(MobileCommand.REPLACE_VALUE, builder.build());
43+
}
3644
}

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)