Appium Python을 사용하여 장치 팜에서 외부 데이터가 필요한 unittests를 실행하려고합니다. '추가 데이터'인수에 'zip 파일 형식의 데이터를 업로드하고'android '인수에 "/sdcard/
"을 입력합니다. 파이썬 스크립트에서 "/WordCountTest1MB
"을 사용하여 파일을 호출하려고합니다. 파일에는 확장자가 없으며 단지 텍스트 일뿐입니다. 그러나 모든 테스트에서 다음과 같은 내용이 나타나지 않습니다.Device Farm - appium python으로 추가 데이터에 액세스하는 방법
test_paramec_0__sdcard_WordCountTest1MB failed: IOError: No such file or directory: '/sdcard/WordCountTest1MB'
이 파일에 액세스하려면 다른 작업이 필요합니까?
도움을 주시면 감사하겠습니다.
EDIT : 아래에 게시 된 코드는 추가 데이터 인수 내에서 데이터의 위치를 찾으려하지만이 디렉토리의 이름은 각각 변경되므로 초기에 경로를 찾아야합니다. 필요한 파일 중 하나 이상 :
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'인수로 무엇을해야합니까? "sdcard에서 파일을 가져오고, 폴더의 내용을 재귀 적으로 가져 오려면 슬래시를 사용하십시오. 예 :/sdcard /,/sdcard/folder /,/sdcard/file" –
붙여 넣기가 가능하면 가능합니다. 여기에 코드가 있습니까? –
방금 –