当前位置: 首页 > 知识库问答 >
问题:

如何将上载/应用程序安装到设备场远程会话

吴子昂
2023-03-14

我在devicefarm中面临这个问题。安装远程访问会话。

我能够成功地从lambda函数使用aws sdk创建远程会话。接下来,我尝试将已经存在的上载安装到创建的远程会话中。

code

 let remoteSession = await devicefarm.createRemoteAccessSession(params).promise()
.then(res => {
      console.log(res);
      let installParm = {
        appArn: uploadArn,
        remoteAccessSessionArn: res.remoteAccessSession.arn
      };
      devicefarm.installToRemoteAccessSession(installParm).promise()
      .then(res => console.log(res))
      .catch(err => console.log(err));
      return res;
    })
    .catch(err => err);

我得到下面的错误。[我将id替换为*]

message: 'Invalid parameters RemoteAccessSession or Upload with identifiers: arn:aws:devicefarm:us-west-2:*:session:**/**/00000 or arn:aws:devicefarm:us-west-2:*:upload:***/**.',
code: 'ArgumentException',

我是否可以为Appran提供上传ARN。这两者有什么区别?如果不同,我在哪里可以买到?

共有1个答案

袁鸿畅
2023-03-14

所以在我的例子中,在我复制了这个之后,原因是因为远程访问会话还没有开始。我已经请求了一个,但是设备农场服务没有同时获得预期的设备。

在我通过观看web控制台等待会话开始后,上传成功。因此,代码需要进行一些检查,以便使用get remote access调用和返回的status属性查看远程访问会话的状态。

使现代化

我编写这个javascript代码是为了等待远程会话进入运行状态。

// 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' });

let params = {
    name: "test of remote access"
};
devicefarm.createProject(params).promise().then(
    function (data) {
        /* process the data */
        console.log("created project", "Result: ", data.project.arn);
        let project = data.project;
        let params = {
            name: "app-debug.apk",
            type: "ANDROID_APP",
            projectArn: project.arn
        };
        devicefarm.createUpload(params).promise().then(
            function (data) {
                console.log("Created upload object successfully", "upload arn: ", data.upload.arn);
                console.log("uploading file...");

                var options = {
                    method: 'PUT',
                    url: data.upload.url,
                    headers: {},
                    body: fs.readFileSync("./aws-device-farm-sample-app-for-android/app/build/outputs/apk/app-debug.apk")
                };

                new Promise(function (resolve, reject) {
                    request(options, function (error, response, body) {
                        if (error) {
                            reject(error);
                        }
                        resolve(data);
                    });
                }).then(function (data) {
                    console.log("successfully uploaded file");
                    console.log("waiting for the sdk to finish processing");

                    getUploadStatusAndCreateRemoteSession(data.upload.arn,project).then(function (status) {
                        if (status == "SUCCEEDED") {

                        }

                    });
                }).catch(function (err) {
                    console.error("Error uploading file", "Error: ", err);
                });
            },
            function (error) {
                console.error("Error creating upload object", "Error: ", error);
            }
        );
    },
    function (error) {
        console.error("Error creating project", "Error: ", error);
    }
)

async function getUploadStatusAndCreateRemoteSession(uploadarn,project) {
    await devicefarm.getUpload({ arn: uploadarn }).promise().then(
        function (data) {
            console.log("getting upload status is successful", "Status: ", data.upload.status);
            if (data.upload.status != "SUCCEEDED") {
                sleep(5000).then(() => {
                    getUploadStatusAndCreateRemoteSession(data.upload.arn,project);
                });
            } else {
                // return data.upload.status;
                devicefarm.createRemoteAccessSession({
                    projectArn: project.arn,
                    deviceArn: 'arn:aws:devicefarm:us-west-2::device:CF6DC11E4C99430BA9A1BABAE5B45364'
                }).promise().then(
                    function (session) {
                        //get session status
                        getSessionStatus(session.remoteAccessSession.arn,uploadarn);
                    },
                    function (error) {
                        console.error("Error creating remote access sesssion", "Error", error);
                    }
                );
            }
        },
        function (error) {
            console.error("Failure getting upload", "Error: ", error);
            return error;
        }
    );
}

async function getSessionStatus(sessionArn,upload) {
    await devicefarm.getRemoteAccessSession({ arn: sessionArn }).promise().then(
        function (data) {
            console.log("getting session status is successful", "Status: ", data.remoteAccessSession.status);
            if (data.remoteAccessSession.status != "RUNNING") {
                sleep(5000).then(() => {
                    getSessionStatus(sessionArn,upload);
                });
            } else {

                console.log("Remote access session started!", "Installing app...");
                let installParm = {
                    appArn: upload,
                    remoteAccessSessionArn: sessionArn
                };
                devicefarm.installToRemoteAccessSession(installParm, function (err, data) {
                    if (err) console.error(err);
                    else console.log(data);
                });

            }
        },
        function (error) {
            console.error("Failure getting session", "Error: ", error);
            return error;
        }
    );
}

输出:

created project Result:  arn:aws:devicefarm:us-west-2:111122223333:project:42ca0449-2714-4dd8-848f-ae9ef6655efb
Created upload object successfully upload arn:  arn:aws:devicefarm:us-west-2:111122223333:upload:42ca0449-2714-4dd8-848f-ae9ef6655efb/cd200f8e-e7f7-4d18-a4ee-32ad959a0786
uploading file...
successfully uploaded file
waiting for the sdk to finish processing
getting upload status is successful Status:  PROCESSING
getting upload status is successful Status:  SUCCEEDED
getting session status is successful Status:  PENDING
getting session status is successful Status:  PENDING
getting session status is successful Status:  PREPARING
getting session status is successful Status:  PREPARING
getting session status is successful Status:  PREPARING
getting session status is successful Status:  PREPARING
getting session status is successful Status:  PREPARING
getting session status is successful Status:  PREPARING
getting session status is successful Status:  PREPARING
getting session status is successful Status:  PREPARING
getting session status is successful Status:  PREPARING
getting session status is successful Status:  PREPARING
getting session status is successful Status:  PREPARING
getting session status is successful Status:  PREPARING
getting session status is successful Status:  RUNNING
Remote access session started! Installing app...
{ appUpload:
   { arn: 'arn:aws:aatp:us-west-2:111122223333:upload:42ca0449-2714-4dd8-848f-ae9ef6655efb/cd200f8e-e7f7-4d18-a4ee-32ad959a0786',
     name: 'app-debug.apk',
     created: 2019-05-04T00:24:32.871Z,
     type: 'ANDROID_APP',
     status: 'SUCCEEDED',
     url: 'https://prod-us-west-2-uploads.s3-us-west-2.amazonaws.com/arn%3Aaws%3Adevicefarm%3Aus-west-2%3A111122223333%3Aproject%3A42ca0449-2714-4dd8-848f-ae9ef6655efb/uploads/arn%3Aaws%3Adevicefarm%3Aus-west-2%3A111122223333%3Aupload%3A42ca0449-2714-4dd8-848f-ae9ef6655efb/cd200f8e-e7f7-4d18-a4ee-32ad959a0786/app-debug.apk?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20190504T002655Z&X-Amz-SignedHeaders=host&X-Amz-Expires=86400&X-Amz-Credential=AKIAJSORV74ENYFBITRQ%2F20190504%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Signature=4630cef6030405b6997281c2477722d3da24eb04ed6aab8e91735d936e532807',
     metadata: '{"device_admin":false,"activity_name":"com.amazonaws.devicefarm.android.referenceapp.Activities.MainActivity","version_name":"1.0","screens":["small","normal","large","xlarge"],"error_type":null,"sdk_version":"10","package_name":"com.amazonaws.devicefarm.android.referenceapp","version_code":"1","native_code":[],"target_sdk_version":"22"}',
     category: 'PRIVATE' } }

詹姆斯

 类似资料:
  • 我使用新的Android应用程序包格式构建了我的项目。有了APK文件,我可以把APK下载到我的设备上,打开它,然后立即安装应用程序。我下载的应用程序是一个捆绑包(.aab格式),我的Nexus 5x运行Android8.1无法打开文件。有没有什么方法可以像APKs一样方便地在设备上安装AABs?

  • 我有一个android的设备,我在上面调试应用程序。在我生成签名apk后,我卸载了现有的调试应用程序,尝试安装签名apk,但我得到了应用程序未安装的错误。我安装在一个没有调试应用程序安装的新设备上,看起来还可以。我尝试清除应用程序数据并卸载,但没有工作。 图像错误

  • 请看下图:在此处输入图像描述 06/14 05:56:50:在Pixel 3 API 29 3上启动“应用程序”。安装没有成功。无法安装该应用程序。 apks列表:[0]'C:\用户\Ahmed\AFAQTravelTurismMobileApplication\app\build\输出\apk\debug\app-debug.apk'安装失败,原因是:'设备脱机'重试

  • 出于安全原因,我想隐藏我们的Android应用程序,不让远程设备访问,如TeamViewer,anyDesk。 例如:-在中有我的应用程序,假设,现在可以远程访问。现在,当打开时,必须看到黑屏,而不是。

  • XCode: 11.3 附录1.15 我正在尝试在ios real设备上运行,当应用程序尝试在设备上安装应用程序时,我收到以下错误: 在Xcode中,我将Signin团队设置为我们拥有的开发团队,并且配置文件是Xcode托管的配置文件。在Xcode中编译WebDriverAgent项目时,一切看起来都很好,只是在尝试初始化appium驱动程序时出现了错误。

  • 我正在使用Windows8。我正在尝试在设备上运行应用程序。找不到我的设备,设备USB调试已启用。此外,我已经安装了相同的驱动程序使用管理我也安装了谷歌USB驱动程序包。但仍然找不到该设备。 拜托,有人能帮忙吗

  • 有没有人知道通过Google Play发布的设备拥有者应用程序在发生更新时的生产行为? 正如我们所知,安装一个设备拥有者应用程序需要一些动机,而且并不容易:重置为出厂默认,然后为设备提供NFC--第二个设备等等……所以,即使我们认为这一步已经完成,任何进一步的更新是否每次都需要如此多的痛苦? 出现此问题是因为在我的开发设备上,如果之前安装了设备所有者应用程序,我无法重新启动该应用程序的更改…除非我

  • 或者如果他们在远程位置,则: 我怎样才能让我的osgi控制台在机器A上运行,并从它开始在机器B上运行一个包?