Skip to content

Commit cdbb692

Browse files
committed
Merge pull request appium#28 from appium/isaac-pullfile
Add pull_file method
2 parents ce6001f + d9f7174 commit cdbb692

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

appium/webdriver/mobilecommand.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class MobileCommand(object):
3030
GET_CURRENT_ACTIVITY = 'getCurrentActivity'
3131
SET_IMMEDIATE_VALUE = 'setImmediateValue'
3232
PULL_FILE = 'pullFile'
33+
PULL_FOLDER = 'pullFolder'
3334
PUSH_FILE = 'pushFile'
3435
COMPLEX_FIND = 'complexFind'
3536
BACKGROUND = 'background'

appium/webdriver/webdriver.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,18 @@ def pull_file(self, path):
421421
}
422422
return self.execute(Command.PULL_FILE, data)['value']
423423

424+
def pull_folder(self, path):
425+
"""Retrieves a folder at `path`. Returns the folder's contents zipped
426+
and encoded as Base64.
427+
428+
:Args:
429+
- path - the path to the folder on the device
430+
"""
431+
data = {
432+
'path': path,
433+
}
434+
return self.execute(Command.PULL_FOLDER, data)['value']
435+
424436
def push_file(self, path, base64data):
425437
"""Puts the data, encoded as Base64, in the file specified as `path`.
426438
@@ -574,6 +586,8 @@ def _addCommands(self):
574586
('POST', '/session/$sessionId/appium/element/$elementId/value')
575587
self.command_executor._commands[Command.PULL_FILE] = \
576588
('POST', '/session/$sessionId/appium/device/pull_file')
589+
self.command_executor._commands[Command.PULL_FOLDER] = \
590+
('POST', '/session/$sessionId/appium/device/pull_folder')
577591
self.command_executor._commands[Command.PUSH_FILE] = \
578592
('POST', '/session/$sessionId/appium/device/push_file')
579593
self.command_executor._commands[Command.COMPLEX_FIND] = \

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
setup(
1919
name='Appium-Python-Client',
20-
version='0.6',
20+
version='0.7',
2121
description='Python client for Appium 1.0',
2222
keywords=[
2323
'appium',

test/functional/android/appium_tests.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
# limitations under the License.
1515

1616
import unittest
17+
from zipfile import ZipFile
1718
import json
19+
import os
20+
import random
1821
from time import sleep
1922

2023
from selenium.common.exceptions import NoSuchElementException
@@ -35,6 +38,10 @@ def setUp(self):
3538
def tearDown(self):
3639
self.driver.quit()
3740

41+
# remove zipped file from `test_pull_folder`
42+
if os.path.isfile(self.zipfilename):
43+
os.remove(self.zipfilename)
44+
3845
def test_app_strings(self):
3946
strings = self.driver.app_strings()
4047
self.assertEqual(u'You can\'t wipe my data, you are a monkey!', strings[u'monkey_wipe_data'])
@@ -67,6 +74,25 @@ def test_push_file(self):
6774
data_ret = self.driver.pull_file('data/local/tmp/test_push_file.txt').decode('base64')
6875
self.assertEqual(data, data_ret)
6976

77+
def test_pull_folder(self):
78+
string_data = 'random string data %d' % random.randint(0, 1000)
79+
path = '/data/local/tmp'
80+
self.driver.push_file(path + '/1.txt', string_data.encode('base64'))
81+
self.driver.push_file(path + '/2.txt', string_data.encode('base64'))
82+
folder = self.driver.pull_folder(path)
83+
84+
# python doesn't have any functionality for unzipping streams
85+
# save temporary file, which will be deleted in `tearDown`
86+
self.zipfilename = 'folder_%d.zip' % random.randint(0, 1000000)
87+
file = open(self.zipfilename, "w")
88+
file.write(folder.decode('base64', 'strict'))
89+
file.close()
90+
91+
with ZipFile(self.zipfilename, 'r') as myzip:
92+
# should find these. otherwise it will raise a `KeyError`
93+
myzip.read('1.txt')
94+
myzip.read('2.txt')
95+
7096
def test_complex_find(self):
7197
# this only works with a three dimensional array like here.
7298
el = self.driver.complex_find([[[2, 'Ani']]])

0 commit comments

Comments
 (0)