AWS Device Farm-缺少或未处理的资源

时间:2019-06-06 14:22:17

标签: amazon-web-services testing amazon-s3 aws-lambda aws-device-farm

我尝试通过AWS Lambda Node.JS运行android应用程序测试时遵循以下步骤

  • 创建了一个项目
  • 创建上传
  • 将APK上载到已签名的URL
  • 完成上传后,我使用以下参数创建了设备池

    var createDevicePoolParams = {                 名称:“ DAP_Device_Pool”,                 说明:“ DAP_Android_Devices”,                 projectArn:projectARN,                 规则:[{                     属性:“ PLATFORM”,                     运算子:“ EQUALS”,                     值:“ \” ANDROID \“”                 }]             };

  • 然后我用以下参数调用了schedulerun

    var scheduleRunParams = {                         appArn:uploadARN,                         名称:“ tarunRun”,                         devicePoolArn:devicePoolARN,                         projectArn:projectARN,                         测试:{                             输入:“ BUILTIN_FUZZ”,                         }                         };

但是我遇到了资源丢失或未处理的错误。

我无法理解我所缺少的。我的理解是,如果我使用内置的模糊测试类型,则无需上传任何自定义测试用例。

有人可以帮助指出缺少的步骤

然后 在设备场处理完您的上传后,请致电aws devicefarm schedule-run

1 个答案:

答案 0 :(得分:1)

[更新]

我将此代码放入了AWS Lambda函数中,并且在那里也能正常工作。这是要点: https://gist.github.com/jamesknowsbest/3ea0e385988b0098e5f9d38bf5a932b6

这是我刚编写的代码,似乎可以与Built-in Fuzz / Explorer tests

一起使用
// assume we already executed `npm install aws-sdk`
var AWS = require('aws-sdk');
// assumes `npm install https`
const request = require("request");
// assumes `npm install fs`
const fs = require('fs');
// https://stackoverflow.com/a/41641607/8016330
const sleep = (waitTimeInMs) => new Promise(resolve => setTimeout(resolve, waitTimeInMs));
// Device Farm is only available in the us-west-2 region
var devicefarm = new AWS.DeviceFarm({ region: 'us-west-2' });

(async function() {
    let project_params = {
        name: "test of fuzz tests"
    };
    let PROJECT_ARN = await devicefarm.createProject(project_params).promise().then(
        function(data){
            return data.project.arn;
        },
        function (error) {
            console.error("Error creating project", "Error: ", error);
        }
    );
    console.log("Project created ", "Project arn: ", PROJECT_ARN);

    // create the upload and upload files to the project
    let params = {
        name: "app-debug.apk",
        type: "ANDROID_APP",
        projectArn: PROJECT_ARN
    };
    let UPLOAD = await devicefarm.createUpload(params).promise().then(
        function(data){
            return data.upload;
        },
        function(error){
            console.error("Creating upload failed with error: ", error);
        }
    );
    let UPLOAD_ARN = UPLOAD.arn;
    let UPLOAD_URL = UPLOAD.url;
    console.log("upload created with arn: ", UPLOAD_ARN);
    console.log("uploading file...");

    let options = {
        method: 'PUT',
        url: UPLOAD_URL,
        headers: {},
        body: fs.readFileSync("/path/to/your/apk/file")
    };

    // wait for upload to finish
    await new Promise(function(resolve,reject){
        request(options, function (error, response, body) {
            if (error) {
                console.error("uploading file failed with error: ", error);
                reject(error);
            }
            resolve(body);
        });
    });

    //get the status of the upload and make sure if finished processing before scheduling
    let STATUS = await getStatus(UPLOAD_ARN);
    console.log("upload status is: ", STATUS);
    while(STATUS !== "SUCCEEDED"){
        await sleep(5000);
        STATUS = await getStatus(UPLOAD_ARN);
        console.log("upload status is: ", STATUS);
    }

    //create device pool
    let device_pool_params = {
        projectArn: PROJECT_ARN,
        name: "Google Pixel 2",
        rules: [{"attribute": "ARN","operator":"IN","value":"[\"arn:aws:devicefarm:us-west-2::device:5F20BBED05F74D6288D51236B0FB9895\"]"}]
    }

    let DEVICE_POOL_ARN = await devicefarm.createDevicePool(device_pool_params).promise().then(
        function(data){
            return data.devicePool.arn; 
        },function(error){
            console.error("device pool failed to create with error: ",error);
        }
    ); 

    console.log("Device pool created successfully with arn: ", DEVICE_POOL_ARN);

    //schedule the run
    let schedule_run_params = {
        name: "MyRun", 
        devicePoolArn: DEVICE_POOL_ARN, // You can get the Amazon Resource Name (ARN) of the device pool by using the list-pools CLI command.
        projectArn: PROJECT_ARN, // You can get the Amazon Resource Name (ARN) of the project by using the list-projects CLI command.
        test: {
         type: "BUILTIN_FUZZ"
        },
        appArn: UPLOAD_ARN
    };
    let schedule_run_result = await devicefarm.scheduleRun(schedule_run_params).promise().then(
        function(data){
            return data.run;
        },function(error){
            console.error("Schedule run command failed with error: ", error);
        }
    );
    console.log("run finished successfully with result: ", schedule_run_result);

})();

async function getStatus(UPLOAD_ARN){
    return await devicefarm.getUpload({arn: UPLOAD_ARN}).promise().then(
        function(data){
            return data.upload.status;
        },function(error){
            console.error("getting upload failed with error: ", error);
        }
    );
}

输出为

Project created  Project arn:  arn:aws:devicefarm:us-west-2:111122223333:project:b9233b49-967e-4b09-a51a-b5c4101340a1
upload created with arn:  arn:aws:devicefarm:us-west-2:111122223333:upload:b9233b49-967e-4b09-a51a-b5c4101340a1/48ffd115-f7d7-4df5-ae96-4a44911bff65
uploading file...
upload status is:  INITIALIZED
upload status is:  SUCCEEDED
Device pool created successfully with arn:  arn:aws:devicefarm:us-west-2:111122223333:devicepool:b9233b49-967e-4b09-a51a-b5c4101340a1/c0ce1bbc-7b40-4a0f-a419-ab024a6b1000
run finished successfully with result:  { arn:
   'arn:aws:devicefarm:us-west-2:111122223333:run:b9233b49-967e-4b09-a51a-b5c4101340a1/39369894-3829-4e14-81c9-bdfa02c7e032',
  name: 'MyRun',
  type: 'BUILTIN_FUZZ',
  platform: 'ANDROID_APP',
  created: 2019-06-06T23:51:13.529Z,
  status: 'SCHEDULING',
  result: 'PENDING',
  started: 2019-06-06T23:51:13.529Z,
  counters:
   { total: 0,
     passed: 0,
     failed: 0,
     warned: 0,
     errored: 0,
     stopped: 0,
     skipped: 0 },
  totalJobs: 1,
  completedJobs: 0,
  billingMethod: 'METERED',
  seed: 982045377,
  appUpload:
   'arn:aws:devicefarm:us-west-2:111122223333:upload:b9233b49-967e-4b09-a51a-b5c4101340a1/48ffd115-f7d7-4df5-ae96-4a44911bff65',
  eventCount: 6000,
  jobTimeoutMinutes: 150,
  devicePoolArn:
   'arn:aws:devicefarm:us-west-2:111122223333:devicepool:b9233b49-967e-4b09-a51a-b5c4101340a1/c0ce1bbc-7b40-4a0f-a419-ab024a6b1000',
  radios: { wifi: true, bluetooth: false, nfc: true, gps: true } }

HTH

-詹姆斯