I am working on appium java TestNG with maven and I run the script on device farm.Device farm generates 3 o/p in the form of logs, videos, and screenshot. My target is to get videos URL into practitest. This is my test management tool. So my question is how can I get videos URL link of Device farm test videos?
2 Answers
Here is a short python script that gets all the videos, creates a directory in the current working directory, then puts all the videos in that directory. I made this when using winders so you'll need to change the file path for a mac.
To use it first get the project arn by doing:
aws devicefarm list-projects --region us-west-2
Then once we have a project arn open a cmn window, cd to the directory this code is in and type:
python somefilename.py --project-arn arn:aws:devicefarm:us-west-2:accountNUm:project:11111111-2222-3333-4444-555555555555
and it should start downloading each video
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

- 2,175
- 2
- 17
- 16
AWS Device Farm has an API called ListArtifacts. http://docs.aws.amazon.com/devicefarm/latest/APIReference/API_ListArtifacts.html
This API will return a list of artifacts(files, screenshots, and logs). Each artifact will have a URL so you can download the file. Each artifact also contains a type, so you can iterate through the list of artifacts and find the ones where type is "VIDEO".
Caveat: There is a difference between the "type" parameter in the ListArtifacts request and the "type" property returned in the Artifact object. The type in ListArtifacts request only allows three values: FILE, LOG, SCREENSHOT. However, the type property in the Artifact object has several possible values that are documented here: http://docs.aws.amazon.com/devicefarm/latest/APIReference/API_Artifact.html

- 126
- 1