From c5e004a38390bd5105de2745d625cbe1f3d97639 Mon Sep 17 00:00:00 2001 From: saikrishna321 Date: Sat, 23 Mar 2024 16:38:15 +0800 Subject: [PATCH] fix android actions from browser to mobile --- src/modules | 2 +- test/e2e/android/conf.spec.js | 14 +++++ web/src/api-service/index.ts | 4 ++ .../device-card/device-card/device-card.tsx | 6 ++ .../streaming/messages/click-message.ts | 40 +++++++------ .../streaming/messages/swipe-message.ts | 58 +++++++++---------- 6 files changed, 75 insertions(+), 49 deletions(-) diff --git a/src/modules b/src/modules index acba373de..e3581046a 160000 --- a/src/modules +++ b/src/modules @@ -1 +1 @@ -Subproject commit acba373de2739d36647fa3beead66b056b1a5da4 +Subproject commit e3581046a08a638b42521bf9153ac0e112945199 diff --git a/test/e2e/android/conf.spec.js b/test/e2e/android/conf.spec.js index d0e56a22d..6205880b0 100644 --- a/test/e2e/android/conf.spec.js +++ b/test/e2e/android/conf.spec.js @@ -30,6 +30,20 @@ describe('Plugin Test', () => { it('Vertical swipe test', async () => { await driver.executeScript('devicefarm: setSessionName', [{ name: 'SliderTest Example' }]); await driver.pause(3000); + await driver.performActions([ + { + type: 'pointer', + id: 'finger1', + parameters: { pointerType: 'touch' }, + actions: [ + { type: 'pointerMove', duration: 0, x: 100, y: 100 }, + { type: 'pointerDown', button: 0 }, + { type: 'pause', duration: 500 }, + { type: 'pointerMove', duration: 1000, origin: 'pointer', x: -50, y: 0 }, + { type: 'pointerUp', button: 0 }, + ], + }, + ]); await driver.$('~login').click(); await driver.$('~slider1').click(); }); diff --git a/web/src/api-service/index.ts b/web/src/api-service/index.ts index 774a651e0..ee9735bb7 100644 --- a/web/src/api-service/index.ts +++ b/web/src/api-service/index.ts @@ -9,6 +9,10 @@ export default class DeviceFarmApiService { return apiClient.makePOSTRequest('/installAndroidStreamingApp', {}, {udid, systemPort}); } + public static createSession(udid: string, systemPort: number) { + return apiClient.makePOSTRequest('/appiumSession', {}, {udid, systemPort}); + } + public static getPendingSessionsCount() { return apiClient.makeGETRequest('/queue/length', {}); } diff --git a/web/src/components/device-card/device-card/device-card.tsx b/web/src/components/device-card/device-card/device-card.tsx index 084d94dcb..56eda07d2 100644 --- a/web/src/components/device-card/device-card/device-card.tsx +++ b/web/src/components/device-card/device-card/device-card.tsx @@ -85,8 +85,14 @@ export default class DeviceCard extends React.Component { try { console.log('Live Stream'); + const sessionCreationResponse = await DeviceFarmApiService.createSession(udid, systemPort); const response = await DeviceFarmApiService.androidStreamingAppInstalled(udid, systemPort); console.log('Response:', response); + if(sessionCreationResponse.status === 200) { + console.log('Session created successfully'); + } else { + console.error('Error creating session:', sessionCreationResponse); + } if (response.status === 200) { window.location.href = `#/androidStream?port=${appiumPort}&host=${appiumHost}&udid=${udid}&width=${response.device.width}&height=${response.device.height}`; } else { diff --git a/web/src/components/streaming/messages/click-message.ts b/web/src/components/streaming/messages/click-message.ts index bb0f2092b..0916d1b29 100644 --- a/web/src/components/streaming/messages/click-message.ts +++ b/web/src/components/streaming/messages/click-message.ts @@ -9,24 +9,26 @@ export class ClickControlMessage { public toJSON() { return { action: 'click', - args: [ - { - type: 'pointer', - id: 'finger1', - parameters: { pointerType: 'touch' }, - actions: [ - { - type: 'pointerMove', - duration: 0, - x: this.point.x, - y: this.point.y, - }, - { type: 'pointerDown', button: 0 }, - { type: 'pause', duration: this.duration }, - { type: 'pointerUp', button: 0 }, - ], - }, - ], - }; + args: { + "actions": [ + { + type: 'pointer', + id: 'finger1', + parameters: { pointerType: 'touch' }, + actions: [ + { + type: 'pointerMove', + duration: 0, + x: this.point.x, + y: this.point.y, + }, + { type: 'pointerDown', button: 0 }, + { type: 'pause', duration: this.duration }, + { type: 'pointerUp', button: 0 }, + ], + }, + ], + } + } } } diff --git a/web/src/components/streaming/messages/swipe-message.ts b/web/src/components/streaming/messages/swipe-message.ts index c43ae741b..5a2e28e34 100644 --- a/web/src/components/streaming/messages/swipe-message.ts +++ b/web/src/components/streaming/messages/swipe-message.ts @@ -4,40 +4,40 @@ import { Point } from '../../../libs/coordinates'; export class SwipeControlMessage { constructor( readonly startPoint: Point, - readonly endPoint: Point, - ) {} - - private getActionJson() { - return [ - { - type: 'pointer', - id: 'finger1', - parameters: { pointerType: 'touch' }, - actions: [ - { - type: 'pointerMove', - duration: 0, - x: this.startPoint.x, - y: this.startPoint.y, - }, - { type: 'pointerDown', button: 0 }, - { - type: 'pointerMove', - duration: 200, - origin: 'viewport', - x: this.endPoint.x, - y: this.endPoint.y, - }, - { type: 'pointerUp', button: 0 }, - ], - }, - ]; + readonly endPoint: Point + ) { } public toJSON() { return { action: 'swipe', - args: this.getActionJson(), + args: { + 'actions': [ + { + type: 'pointer', + id: 'finger1', + parameters: { pointerType: 'touch' }, + actions: [ + { + type: 'pointerMove', + duration: 0, + x: this.startPoint.x, + y: this.startPoint.y + }, + { type: 'pointerDown', button: 0 }, + { type: 'pause', duration: 500 }, + { + type: 'pointerMove', + duration: 200, + origin: 'viewport', + x: this.endPoint.x, + y: this.endPoint.y + }, + { type: 'pointerUp', button: 0 } + ] + } + ] + } }; } }