Skip to content

Commit 14d3df5

Browse files
committed
pushFile
1 parent 185dddb commit 14d3df5

4 files changed

Lines changed: 25 additions & 0 deletions

File tree

java-client.iml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<orderEntry type="library" name="flexjson-1.8" level="project" />
2020
<orderEntry type="library" name="commons-lang-2.4" level="project" />
2121
<orderEntry type="library" name="org.json-20131017" level="project" />
22+
<orderEntry type="library" name="commons-codec-1.9" level="project" />
2223
</component>
2324
</module>
2425

src/io/appium/java_client/AppiumDriver.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities){
4848
.put(SET_VALUE, postC("/session/:sessionId/appium/element/:id/value"))
4949
.put(PULL_FILE, postC("/session/:sessionId/appium/device/pull_file"))
5050
.put(HIDE_KEYBOARD, postC("/session/:sessionId/appium/device/hide_keyboard"))
51+
.put(PUSH_FILE, postC("/session/:sessionId/appium/device/push_file"))
5152
;
5253
ImmutableMap<String, CommandInfo> mobileCommands = builder.build();
5354

@@ -136,6 +137,18 @@ public byte[] pullFile(String remotePath) {
136137
return DatatypeConverter.parseBase64Binary(base64String);
137138
}
138139

140+
/**
141+
* Save base64 encoded data as a file on the remote mobile device.
142+
* This is an Android only method.
143+
* @param remotePath Path to file to write data to on remote device
144+
* @param base64Data Base64 encoded byte array of data to write to remote device
145+
*/
146+
public void pushFile(String remotePath, byte[] base64Data) {
147+
ImmutableMap.Builder builder = ImmutableMap.builder();
148+
builder.put("path", remotePath).put("data", base64Data);
149+
execute(PUSH_FILE, builder.build());
150+
}
151+
139152
/**
140153
* Hides the keyboard if it is showing.
141154
* This is an iOS only command.

src/io/appium/java_client/MobileCommand.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public interface MobileCommand {
3030
String CURRENT_ACTIVITY = "currentActivity";
3131
String SET_VALUE = "setValue";
3232
String PULL_FILE = "pullFile";
33+
String PUSH_FILE = "pushFile";
3334
String HIDE_KEYBOARD = "hideKeyboard";
3435

3536

test/io/appium/java_client/AndroidUIAutomatorTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.appium.java_client;
22

3+
import org.apache.commons.codec.binary.Base64;
34
import org.junit.After;
45
import org.junit.Before;
56
import org.junit.Test;
@@ -65,4 +66,13 @@ public void findElementsByTest() {
6566
public void ErrorTest() {
6667
driver.findElementByAndroidUIAutomator(null);
6768
}
69+
70+
@Test
71+
public void pushFileTest() {
72+
byte[] data = Base64.encodeBase64("The eventual code is no more than the deposit of your understanding. ~E. W. Dijkstra".getBytes());
73+
driver.pushFile("/data/local/tmp/remote.txt", data);
74+
byte[] returnData = driver.pullFile("/data/local/tmp/remote.txt");
75+
String returnDataDecoded = new String(Base64.decodeBase64(returnData));
76+
assertEquals("The eventual code is no more than the deposit of your understanding. ~E. W. Dijkstra", returnDataDecoded);
77+
}
6878
}

0 commit comments

Comments
 (0)