2017-09-14 138 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