2017-12-02 12 views
0

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() 

답변

0

, 당신은 여기 예제 목록으로는,이 문제를 해결해야 같은데 어떤 경로를 수정할 수 있는지 언급하십시오.

fileDir = os.path.dirname(os.path.realpath('__file__')) 
print fileDir 

#For accessing the file in the same folder 
filename = "same.txt" 
readFile(filename) 

#For accessing the file in a folder contained in the current folder 
filename = os.path.join(fileDir, 'Folder1.1/same.txt') 
readFile(filename) 

#For accessing the file in the parent folder of the current folder 
filename = os.path.join(fileDir, '../same.txt') 
readFile(filename) 

#For accessing the file inside a sibling folder. 
filename = os.path.join(fileDir, '../Folder2/same.txt') 
filename = os.path.abspath(os.path.realpath(filename)) 
print filename 
0

두 가지 옵션이

1) 세트의 각 요소

known_files = {'/sdcard/WordCountTest1MB.txt', 
'/sdcard/WordCountTest5MB.txt', 
'/sdcard/WordCountTest10MB.txt'} 

2)를 사용하여 COMBIN에 .txt 인 추가 시도 할 수 있습니다 문제는 여기에

def wordcount(filename): 
    .... 
    .... 
     with open(os.path.abspath(inFile)) as file: # with can auto close the file 
    .... 
문 위의

파일의 올바른 경로를 제공하지 않는이 같은 글로브와 fileinput 함수의 ATION는

import fileinput 
from glob import glob 
#This will store all the file names 
fnames = glob('WordCountTest*') 
for line in fileinput.input(fnames): 
    pass # modify your code 
+0

테스트 실행 설정에서 'Android'인수로 무엇을해야합니까? "sdcard에서 파일을 가져오고, 폴더의 내용을 재귀 적으로 가져 오려면 슬래시를 사용하십시오. 예 :/sdcard /,/sdcard/folder /,/sdcard/file" –

+0

붙여 넣기가 가능하면 가능합니다. 여기에 코드가 있습니까? –

+0

방금 ​​ –