我正在使用Maven进行Appium Java testng工作,并且我在设备农场上运行脚本。DeviceFarm以日志,视频和屏幕截图的形式生成3 O/P。我的目标是使视频URL成为最实用的。这是我的测试管理工具。所以我的问题是如何获得视频URL链接的设备农场测试视频?
这是一个简短的python脚本,可以获取所有视频,在当前的工作目录中创建一个目录,然后将所有视频放入该目录中。我在使用绕线器时做到了这一点,因此您需要更改Mac的文件路径。
首先使用它来获取该项目:
aws devicefarm list-projects --region us-west-2
然后,一旦我们有一个项目打开一个cmn窗口,CD到目录中,该代码就在并输入:
:python somefilename.py --project-arn arn:aws:devicefarm:us-west-2:accountNUm:project:11111111-2222-3333-4444-555555555555
它应该开始下载每个视频
import boto3
import json
import requests
import time
import argparse
import sys
import os
import errno
#Device Farm is only available in us-west-2
client = boto3.client('devicefarm',region_name='us-west-2')
# Read in command-line parameters
parser = argparse.ArgumentParser()
#get the project, test, and run types
parser.add_argument("--project-arn", action="store", required=True, dest="projectarn", help="aws devicefarm list-projects --region us-west-2")
args = parser.parse_args()
#list the runs
#https://boto3.readthedocs.io/en/latest/reference/services/devicefarm.html#DeviceFarm.Client.list_runs
runs = client.list_runs(arn=args.projectarn)
for run in runs['runs']:
index = 0
#list the artifacts and get the videos
#https://boto3.readthedocs.io/en/latest/reference/services/devicefarm.html#DeviceFarm.Client.list_artifacts
artifacts = client.list_artifacts(
arn=run['arn'],
type='FILE'
)
#print(json.dumps(artifacts))
for artifact in artifacts['artifacts']:
#get videos
video_url = ''
if artifact['type'] == "VIDEO":
print (str(artifact) + "n")
video_url = artifact['url']
response = requests.request("GET", video_url)
cwd = os.getcwd()
filename = cwd + "\videos\" + "video" + str(index) + ".mp4"
print (filename + "n")
if not os.path.exists(os.path.dirname(filename)):
try:
print("trying to create directory")
os.makedirs(os.path.dirname(filename))
except OSError as exc: # Guard against race condition
if exc.errno != errno.EEXIST:
raise
with open(filename, "wb") as f:
print("writing response to file")
f.write(response.content)
f.close()
index = index + 1
aws设备农场的API称为ListArtifacts。http://docs.aws.amazon.com/devicefarm/latest/apireference/api_listartifacts.html
此API将返回工件(文件,屏幕截图和日志)的列表。每个工件都有一个URL,因此您可以下载文件。每个文物还包含一种类型,因此您可以迭代文物列表,并找到类型为"视频"的人。
警告:ListArtifacts请求中的"类型"参数与伪影对象中返回的"类型"属性之间存在差异。ListArtifacts请求中的类型仅允许三个值:文件,日志,屏幕截图。但是,伪影对象中的类型属性具有几个可能的值,这些值已记录在此处:http://docs.aws.amazon.com/devicefarm/latest/apireference/api_artifact.html