2017-09-14 142 views

回答

0

AWS Device Farm有一个名为ListArtifacts的API。 http://docs.aws.amazon.com/devicefarm/latest/APIReference/API_ListArtifacts.html

此API将返回工件列表(文件,屏幕截图和日志)。每个工件都会有一个URL,因此您可以下载该文件。每个工件还包含一个类型,因此您可以遍历工件的列表并找到类型为“VIDEO”的工件。

警告:ListArtifacts请求中的“type”参数与Artifact对象中返回的“type”属性之间存在差异。 ListArtifacts请求中的类型只允许三个值:FILE,LOG,SCREENSHOT。但是,Artifact对象中的type属性有几个可能的值,这些值在此处记录:http://docs.aws.amazon.com/devicefarm/latest/APIReference/API_Artifact.html

0

这是一个简短的python脚本,它可以获取所有视频,在当前工作目录中创建一个目录,然后将所有视频放入该目录。我在使用winders时做了这个,所以你需要改变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