设备农场 - 如何通过appium python访问额外的数据

我想运行需要设备农场与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()

回答:

貌似这里还有一个问题

def wordcount(filename): 

....

....

with open(os.path.abspath(inFile)) as file: # with can auto close the file

....

上述说法没有给文件的正确路径,就需要解决这个问题,在这里是通过一系列例子指的是你可以改正你的路径

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

回答:

两个选项,你可以尝试

1)在集合中的每个元素

known_files = {'/sdcard/WordCountTest1MB.txt', 

'/sdcard/WordCountTest5MB.txt',

'/sdcard/WordCountTest10MB.txt'}

2)使用COMBIN添加.TXT水珠和的FileInput的通货膨胀

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

以上是 设备农场 - 如何通过appium python访问额外的数据 的全部内容, 来源链接: utcz.com/qa/258463.html

回到顶部