Skip to content

Commit

Permalink
fix android actions from browser to mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
saikrishna321 committed Mar 23, 2024
1 parent 077fba9 commit c5e004a
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 49 deletions.
2 changes: 1 addition & 1 deletion src/modules
14 changes: 14 additions & 0 deletions test/e2e/android/conf.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
4 changes: 4 additions & 0 deletions web/src/api-service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', {});
}
Expand Down
6 changes: 6 additions & 0 deletions web/src/components/device-card/device-card/device-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,14 @@ export default class DeviceCard extends React.Component<IDeviceCardProps, any> {

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 {
Expand Down
40 changes: 21 additions & 19 deletions web/src/components/streaming/messages/click-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
],
},
],
}
}
}
}
58 changes: 29 additions & 29 deletions web/src/components/streaming/messages/swipe-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
]
}
]
}
};
}
}

0 comments on commit c5e004a

Please sign in to comment.