-1

I followed following steps while trying to run android app test via AWS Lambda Node.JS

  • Created a project
  • Created an upload
  • Uploaded APK to signed url
  • Once upload was done I created device pool using following params

    var createDevicePoolParams = { name: "DAP_Device_Pool", description: "DAP_Android_Devices", projectArn: projectARN, rules: [{ attribute: "PLATFORM", operator: "EQUALS", value: "\"ANDROID\"" }] };

  • Then I called schedulerun with following params

    var scheduleRunParams = { appArn: uploadARN, name: "tarunRun", devicePoolArn: devicePoolARN, projectArn: projectARN, test: { type: "BUILTIN_FUZZ", } };

But I am getting error of missing or unprocessed resources.

I am not able to understand what I am missing. My understanding is that If I am using built in fuzz testing type then I dont need to upload any custom testcases.

Can somebody pls help pointing out what step is missing

Then After your uploads have been processed by Device Farm, call aws devicefarm schedule-run

Tarun
  • 517
  • 4
  • 9
  • 24
  • When you have the chance, can you let me know if my post helped you? – jmp Jun 08 '19 at 21:57
  • Yes it helped. However the way i fixed my issue was by passing header "ANDROID_APP" while uploading app – Tarun Jun 11 '19 at 19:34

1 Answers1

2

[update]

I put this code in a AWS Lambda function and it worked there as well. Here is a gist of it: https://gist.github.com/jamesknowsbest/3ea0e385988b0098e5f9d38bf5a932b6

Here is the code I just authored and it seems to work with the Built-inFuzz/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);
        }
    );
}

Ouput is:

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

-James

jmp
  • 2,175
  • 2
  • 17
  • 16