我想運行需要設備農場與Appium Python的外部數據的unittests。我將數據以zip文件的形式上傳到'額外數據'參數中,並將「/sdcard/
」輸入到'android'參數中。我試圖在這裏使用「/WordCountTest1MB
」來調用python腳本中的文件。請注意,文件沒有擴展名,它們只是文本。然而,我所有的測試都沒有說:設備農場 - 如何通過appium python訪問額外的數據
test_paramec_0__sdcard_WordCountTest1MB failed: IOError: No such file or directory: '/sdcard/WordCountTest1MB'
我還需要做些什麼來訪問這些文件嗎?
任何幫助非常感謝!
編輯:這裏是下面發佈的代碼,請注意,我們正試圖在額外的數據參數中查找數據的位置,但是這些目錄的名稱會隨着每個目錄而改變,所以我們需要最初查找需要的文件中的至少一個:
import unittest2
from appium import webdriver
from parameterized import parameterized
import os
for dirpath, dirnames, filenames in os.walk("."):
for filename in [f for f in filenames if f.startswith("WordCountTest10MB.txt")]:
dir_name = os.path.join(dirpath, filename)
print os.path.dirname(dir_name)
def Test1(rootDir):
list_dirs = os.walk(rootDir)
for root, dirs, files in list_dirs:
for d in dirs:
print os.path.join(root, d)
for f in files:
print os.path.join(root, f)
# Returns abs path relative to this file and not cwd
PATH = lambda p: os.path.abspath(
os.path.join(os.path.dirname(__file__), p)
)
def wordcount(filename):
for j in range(1, 10):
wordcount = {}
inFile = filename
with open(os.path.abspath(inFile)) as file: # with can auto close the file
for word in file.read().split():
if word not in wordcount:
wordcount[word] = 1
else:
wordcount[word] += 1
wordcount = sorted(wordcount.items(), key=lambda x: x[1], reverse=True)
for k, v in wordcount:
print(k, v)
class WordCountTest(unittest2.TestCase):
known_files = {'/WordCountTest1MB.txt',
'/WordCountTest5MB.txt',
'/WordCountTest10MB.txt'}
def SetUpClass(self):
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '5.0'
desired_caps['deviceName'] = 'Android Emulator'
desired_caps['app'] = PATH('../../../apps/Nothing_v0_apkpure.com.apk')
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
@parameterized.expand(known_files)
def test_paramec(self, filename):
os.chdir(dir_name)
print os.getcwd(), Test1(os.getcwd())
wordcount(filename)
def TearDown(self):
self.driver.quit()
if __name__ == '__main__':
unittest2.main()
我是否需要在測試運行設置中對'Android'參數進行任何操作。它說:「從SD卡拉文件,如果你想遞歸地拉一個文件夾的內容,使用尾部斜槓。例如/ sdcard /,/ SD卡/文件夾/,/ SD卡/文件」 –
是否有可能,如果你可以粘貼你的代碼在這裏? –
剛剛添加它作爲編輯 –