我想运行需要设备农场与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卡/文件” –
是否有可能,如果你可以粘贴你的代码在这里? –
刚刚添加它作为编辑 –