接入教程
1. 注册AWS账户并开通Device Farm服务
2. 上传待测试的应用程序文件
3. 选择测试设备类型和操作系统版本
4. 配置测试脚本或使用内置测试框架
5. 启动测试并查看实时测试报告
6. 分析测试结果并下载详细报告
使用Python发起设备测试
import requests
url = 'https://api.example.com/v1/testRuns'
headers = {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
}
payload = {
'projectArn': 'arn:aws:devicefarm:us-west-2:123456789012:project:example-project',
'devicePoolArn': 'arn:aws:devicefarm:us-west-2::devicepool:example-pool',
'testSpecArn': 'arn:aws:devicefarm:us-west-2::upload:example-test-spec'
}
response = requests.post(url, headers=headers, json=payload)
print(response.status_code)
print(response.json())
使用PHP获取测试结果
<?php
$url = 'https://api.example.com/v1/testRuns/example-run-id/results';
$headers = [
'Authorization: Bearer YOUR_API_KEY',
'Content-Type: application/json'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
print_r($data);
?>
使用JavaScript上传测试文件
const fetch = require('node-fetch');
const url = 'https://api.example.com/v1/uploads';
const headers = {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
};
const body = JSON.stringify({
'projectArn': 'arn:aws:devicefarm:us-west-2:123456789012:project:example-project',
'name': 'test-specification.json',
'type': 'APPIUM_PYTHON_TEST_SPEC'
});
fetch(url, {
method: 'POST',
headers: headers,
body: body
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
常见问题
AWS Device Farm支持哪些类型的测试?
AWS Device Farm支持移动设备应用测试(包括iOS和Android)以及桌面浏览器测试。它兼容多种测试框架,如Appium、Calabash、Espresso等,并支持自动化测试和手动测试。
如何获取API访问密钥?
您需要先在AWS管理控制台中创建IAM用户,并为该用户分配适当的Device Farm访问权限。然后在IAM用户的安全凭证部分生成访问密钥(Access Key)和秘密密钥(Secret Key)。
测试结果包含哪些信息?
测试结果包括详细的测试执行日志、设备截图、性能指标(如CPU使用率、内存消耗)、网络状况以及测试通过/失败的状态报告。所有结果都可通过API或AWS控制台查看和下载。
Aitishiku.com