@midscene/android 1.0.1-beta-20251022061922.0 → 1.0.1-beta-20251024063839.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/index.mjs +47 -58
- package/dist/lib/index.js +47 -58
- package/dist/types/index.d.ts +2 -24
- package/package.json +4 -4
package/dist/es/index.mjs
CHANGED
|
@@ -103,8 +103,7 @@ class AndroidDevice {
|
|
|
103
103
|
});
|
|
104
104
|
}),
|
|
105
105
|
defineActionKeyboardPress(async (param)=>{
|
|
106
|
-
|
|
107
|
-
await this.keyboardPress(key);
|
|
106
|
+
await this.keyboardPress(param.keyName);
|
|
108
107
|
}),
|
|
109
108
|
defineAction({
|
|
110
109
|
name: 'AndroidBackButton',
|
|
@@ -288,7 +287,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
288
287
|
}
|
|
289
288
|
async getScreenSize() {
|
|
290
289
|
var _this_options, _this_options1;
|
|
291
|
-
const shouldCache = !((null == (_this_options = this.options) ? void 0 : _this_options.
|
|
290
|
+
const shouldCache = !((null == (_this_options = this.options) ? void 0 : _this_options.alwaysRefreshScreenInfo) ?? false);
|
|
292
291
|
if (shouldCache && this.cachedScreenSize) return this.cachedScreenSize;
|
|
293
292
|
const adb = await this.getAdb();
|
|
294
293
|
if ('number' == typeof (null == (_this_options1 = this.options) ? void 0 : _this_options1.displayId)) try {
|
|
@@ -422,7 +421,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
422
421
|
}
|
|
423
422
|
async getDisplayOrientation() {
|
|
424
423
|
var _this_options;
|
|
425
|
-
const shouldCache = !((null == (_this_options = this.options) ? void 0 : _this_options.
|
|
424
|
+
const shouldCache = !((null == (_this_options = this.options) ? void 0 : _this_options.alwaysRefreshScreenInfo) ?? false);
|
|
426
425
|
if (shouldCache && null !== this.cachedOrientation) return this.cachedOrientation;
|
|
427
426
|
const adb = await this.getAdb();
|
|
428
427
|
let orientation = 0;
|
|
@@ -463,7 +462,8 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
463
462
|
const logicalHeight = Math.round(height * scale);
|
|
464
463
|
return {
|
|
465
464
|
width: logicalWidth,
|
|
466
|
-
height: logicalHeight
|
|
465
|
+
height: logicalHeight,
|
|
466
|
+
dpr: this.devicePixelRatio
|
|
467
467
|
};
|
|
468
468
|
}
|
|
469
469
|
adjustCoordinates(x, y) {
|
|
@@ -489,8 +489,8 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
489
489
|
const minScrollY = Math.min(minScrollDistance, actualScrollDistanceY);
|
|
490
490
|
actualScrollDistanceY = Math.max(minScrollY, actualScrollDistanceY);
|
|
491
491
|
}
|
|
492
|
-
const endX = 0 === deltaX ? start.x : deltaX > 0 ? Math.min(maxWidth, start.x + actualScrollDistanceX) : Math.max(0, start.x - actualScrollDistanceX);
|
|
493
|
-
const endY = 0 === deltaY ? start.y : deltaY > 0 ? Math.min(maxHeight, start.y + actualScrollDistanceY) : Math.max(0, start.y - actualScrollDistanceY);
|
|
492
|
+
const endX = Math.round(0 === deltaX ? start.x : deltaX > 0 ? Math.min(maxWidth, start.x + actualScrollDistanceX) : Math.max(0, start.x - actualScrollDistanceX));
|
|
493
|
+
const endY = Math.round(0 === deltaY ? start.y : deltaY > 0 ? Math.min(maxHeight, start.y + actualScrollDistanceY) : Math.max(0, start.y - actualScrollDistanceY));
|
|
494
494
|
return {
|
|
495
495
|
x: endX,
|
|
496
496
|
y: endY
|
|
@@ -552,7 +552,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
552
552
|
const adb = await this.getAdb();
|
|
553
553
|
await this.mouseClick(element.center[0], element.center[1]);
|
|
554
554
|
const IME_STRATEGY = ((null == (_this_options = this.options) ? void 0 : _this_options.imeStrategy) || globalConfigManager.getEnvConfigValue(MIDSCENE_ANDROID_IME_STRATEGY)) ?? IME_STRATEGY_YADB_FOR_NON_ASCII;
|
|
555
|
-
if (IME_STRATEGY === IME_STRATEGY_YADB_FOR_NON_ASCII) await
|
|
555
|
+
if (IME_STRATEGY === IME_STRATEGY_YADB_FOR_NON_ASCII) await adb.clearTextField(100);
|
|
556
556
|
else await adb.shell(`app_process${this.getDisplayArg()} -Djava.class.path=/data/local/tmp/yadb /data/local/tmp com.ysbing.yadb.Main -keyboard "~CLEAR~"`);
|
|
557
557
|
if (await adb.isSoftKeyboardPresent()) return;
|
|
558
558
|
await this.mouseClick(element.center[0], element.center[1]);
|
|
@@ -569,12 +569,12 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
569
569
|
if (startPoint) {
|
|
570
570
|
const { height } = await this.size();
|
|
571
571
|
const start = {
|
|
572
|
-
x: startPoint.left,
|
|
573
|
-
y: startPoint.top
|
|
572
|
+
x: Math.round(startPoint.left),
|
|
573
|
+
y: Math.round(startPoint.top)
|
|
574
574
|
};
|
|
575
575
|
const end = {
|
|
576
576
|
x: start.x,
|
|
577
|
-
y: height
|
|
577
|
+
y: Math.round(height)
|
|
578
578
|
};
|
|
579
579
|
await repeat(defaultScrollUntilTimes, ()=>this.mouseDrag(start, end, defaultFastScrollDuration));
|
|
580
580
|
await sleep(1000);
|
|
@@ -586,8 +586,8 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
586
586
|
async scrollUntilBottom(startPoint) {
|
|
587
587
|
if (startPoint) {
|
|
588
588
|
const start = {
|
|
589
|
-
x: startPoint.left,
|
|
590
|
-
y: startPoint.top
|
|
589
|
+
x: Math.round(startPoint.left),
|
|
590
|
+
y: Math.round(startPoint.top)
|
|
591
591
|
};
|
|
592
592
|
const end = {
|
|
593
593
|
x: start.x,
|
|
@@ -604,11 +604,11 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
604
604
|
if (startPoint) {
|
|
605
605
|
const { width } = await this.size();
|
|
606
606
|
const start = {
|
|
607
|
-
x: startPoint.left,
|
|
608
|
-
y: startPoint.top
|
|
607
|
+
x: Math.round(startPoint.left),
|
|
608
|
+
y: Math.round(startPoint.top)
|
|
609
609
|
};
|
|
610
610
|
const end = {
|
|
611
|
-
x: width,
|
|
611
|
+
x: Math.round(width),
|
|
612
612
|
y: start.y
|
|
613
613
|
};
|
|
614
614
|
await repeat(defaultScrollUntilTimes, ()=>this.mouseDrag(start, end, defaultFastScrollDuration));
|
|
@@ -621,8 +621,8 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
621
621
|
async scrollUntilRight(startPoint) {
|
|
622
622
|
if (startPoint) {
|
|
623
623
|
const start = {
|
|
624
|
-
x: startPoint.left,
|
|
625
|
-
y: startPoint.top
|
|
624
|
+
x: Math.round(startPoint.left),
|
|
625
|
+
y: Math.round(startPoint.top)
|
|
626
626
|
};
|
|
627
627
|
const end = {
|
|
628
628
|
x: 0,
|
|
@@ -637,11 +637,11 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
637
637
|
}
|
|
638
638
|
async scrollUp(distance, startPoint) {
|
|
639
639
|
const { height } = await this.size();
|
|
640
|
-
const scrollDistance = distance || height;
|
|
640
|
+
const scrollDistance = Math.round(distance || height);
|
|
641
641
|
if (startPoint) {
|
|
642
642
|
const start = {
|
|
643
|
-
x: startPoint.left,
|
|
644
|
-
y: startPoint.top
|
|
643
|
+
x: Math.round(startPoint.left),
|
|
644
|
+
y: Math.round(startPoint.top)
|
|
645
645
|
};
|
|
646
646
|
const end = this.calculateScrollEndPoint(start, 0, scrollDistance, 0, height);
|
|
647
647
|
await this.mouseDrag(start, end);
|
|
@@ -651,11 +651,11 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
651
651
|
}
|
|
652
652
|
async scrollDown(distance, startPoint) {
|
|
653
653
|
const { height } = await this.size();
|
|
654
|
-
const scrollDistance = distance || height;
|
|
654
|
+
const scrollDistance = Math.round(distance || height);
|
|
655
655
|
if (startPoint) {
|
|
656
656
|
const start = {
|
|
657
|
-
x: startPoint.left,
|
|
658
|
-
y: startPoint.top
|
|
657
|
+
x: Math.round(startPoint.left),
|
|
658
|
+
y: Math.round(startPoint.top)
|
|
659
659
|
};
|
|
660
660
|
const end = this.calculateScrollEndPoint(start, 0, -scrollDistance, 0, height);
|
|
661
661
|
await this.mouseDrag(start, end);
|
|
@@ -665,11 +665,11 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
665
665
|
}
|
|
666
666
|
async scrollLeft(distance, startPoint) {
|
|
667
667
|
const { width } = await this.size();
|
|
668
|
-
const scrollDistance = distance || width;
|
|
668
|
+
const scrollDistance = Math.round(distance || width);
|
|
669
669
|
if (startPoint) {
|
|
670
670
|
const start = {
|
|
671
|
-
x: startPoint.left,
|
|
672
|
-
y: startPoint.top
|
|
671
|
+
x: Math.round(startPoint.left),
|
|
672
|
+
y: Math.round(startPoint.top)
|
|
673
673
|
};
|
|
674
674
|
const end = this.calculateScrollEndPoint(start, scrollDistance, 0, width, 0);
|
|
675
675
|
await this.mouseDrag(start, end);
|
|
@@ -679,11 +679,11 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
679
679
|
}
|
|
680
680
|
async scrollRight(distance, startPoint) {
|
|
681
681
|
const { width } = await this.size();
|
|
682
|
-
const scrollDistance = distance || width;
|
|
682
|
+
const scrollDistance = Math.round(distance || width);
|
|
683
683
|
if (startPoint) {
|
|
684
684
|
const start = {
|
|
685
|
-
x: startPoint.left,
|
|
686
|
-
y: startPoint.top
|
|
685
|
+
x: Math.round(startPoint.left),
|
|
686
|
+
y: Math.round(startPoint.top)
|
|
687
687
|
};
|
|
688
688
|
const end = this.calculateScrollEndPoint(start, -scrollDistance, 0, width, 0);
|
|
689
689
|
await this.mouseDrag(start, end);
|
|
@@ -781,16 +781,16 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
781
781
|
if (0 === deltaX && 0 === deltaY) throw new Error('Scroll distance cannot be zero in both directions');
|
|
782
782
|
const { width, height } = await this.size();
|
|
783
783
|
const n = 4;
|
|
784
|
-
const startX = deltaX < 0 ? width / n * (n - 1) : width / n;
|
|
785
|
-
const startY = deltaY < 0 ? height / n * (n - 1) : height / n;
|
|
784
|
+
const startX = Math.round(deltaX < 0 ? width / n * (n - 1) : width / n);
|
|
785
|
+
const startY = Math.round(deltaY < 0 ? height / n * (n - 1) : height / n);
|
|
786
786
|
const maxNegativeDeltaX = startX;
|
|
787
|
-
const maxPositiveDeltaX = width / n * (n - 1);
|
|
787
|
+
const maxPositiveDeltaX = Math.round(width / n * (n - 1));
|
|
788
788
|
const maxNegativeDeltaY = startY;
|
|
789
|
-
const maxPositiveDeltaY = height / n * (n - 1);
|
|
789
|
+
const maxPositiveDeltaY = Math.round(height / n * (n - 1));
|
|
790
790
|
deltaX = Math.max(-maxNegativeDeltaX, Math.min(deltaX, maxPositiveDeltaX));
|
|
791
791
|
deltaY = Math.max(-maxNegativeDeltaY, Math.min(deltaY, maxPositiveDeltaY));
|
|
792
|
-
const endX = startX - deltaX;
|
|
793
|
-
const endY = startY - deltaY;
|
|
792
|
+
const endX = Math.round(startX - deltaX);
|
|
793
|
+
const endY = Math.round(startY - deltaY);
|
|
794
794
|
const { x: adjustedStartX, y: adjustedStartY } = this.adjustCoordinates(startX, startY);
|
|
795
795
|
const { x: adjustedEndX, y: adjustedEndY } = this.adjustCoordinates(endX, endY);
|
|
796
796
|
const adb = await this.getAdb();
|
|
@@ -828,13 +828,13 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
828
828
|
async pullDown(startPoint, distance, duration = 800) {
|
|
829
829
|
const { width, height } = await this.size();
|
|
830
830
|
const start = startPoint ? {
|
|
831
|
-
x: startPoint.left,
|
|
832
|
-
y: startPoint.top
|
|
831
|
+
x: Math.round(startPoint.left),
|
|
832
|
+
y: Math.round(startPoint.top)
|
|
833
833
|
} : {
|
|
834
|
-
x: width / 2,
|
|
835
|
-
y: 0.15 * height
|
|
834
|
+
x: Math.round(width / 2),
|
|
835
|
+
y: Math.round(0.15 * height)
|
|
836
836
|
};
|
|
837
|
-
const pullDistance = distance || 0.5 * height;
|
|
837
|
+
const pullDistance = Math.round(distance || 0.5 * height);
|
|
838
838
|
const end = {
|
|
839
839
|
x: start.x,
|
|
840
840
|
y: start.y + pullDistance
|
|
@@ -851,13 +851,13 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
851
851
|
async pullUp(startPoint, distance, duration = 600) {
|
|
852
852
|
const { width, height } = await this.size();
|
|
853
853
|
const start = startPoint ? {
|
|
854
|
-
x: startPoint.left,
|
|
855
|
-
y: startPoint.top
|
|
854
|
+
x: Math.round(startPoint.left),
|
|
855
|
+
y: Math.round(startPoint.top)
|
|
856
856
|
} : {
|
|
857
|
-
x: width / 2,
|
|
858
|
-
y: 0.85 * height
|
|
857
|
+
x: Math.round(width / 2),
|
|
858
|
+
y: Math.round(0.85 * height)
|
|
859
859
|
};
|
|
860
|
-
const pullDistance = distance || 0.4 * height;
|
|
860
|
+
const pullDistance = Math.round(distance || 0.4 * height);
|
|
861
861
|
const end = {
|
|
862
862
|
x: start.x,
|
|
863
863
|
y: start.y - pullDistance
|
|
@@ -978,18 +978,7 @@ async function agentFromAdbDevice(deviceId, opts) {
|
|
|
978
978
|
deviceId = devices[0].udid;
|
|
979
979
|
debugAgent('deviceId not specified, will use the first device (id = %s)', deviceId);
|
|
980
980
|
}
|
|
981
|
-
const device = new AndroidDevice(deviceId, {
|
|
982
|
-
autoDismissKeyboard: null == opts ? void 0 : opts.autoDismissKeyboard,
|
|
983
|
-
androidAdbPath: null == opts ? void 0 : opts.androidAdbPath,
|
|
984
|
-
remoteAdbHost: null == opts ? void 0 : opts.remoteAdbHost,
|
|
985
|
-
remoteAdbPort: null == opts ? void 0 : opts.remoteAdbPort,
|
|
986
|
-
imeStrategy: null == opts ? void 0 : opts.imeStrategy,
|
|
987
|
-
displayId: null == opts ? void 0 : opts.displayId,
|
|
988
|
-
usePhysicalDisplayIdForScreenshot: null == opts ? void 0 : opts.usePhysicalDisplayIdForScreenshot,
|
|
989
|
-
usePhysicalDisplayIdForDisplayLookup: null == opts ? void 0 : opts.usePhysicalDisplayIdForDisplayLookup,
|
|
990
|
-
screenshotResizeScale: null == opts ? void 0 : opts.screenshotResizeScale,
|
|
991
|
-
alwaysFetchScreenInfo: null == opts ? void 0 : opts.alwaysFetchScreenInfo
|
|
992
|
-
});
|
|
981
|
+
const device = new AndroidDevice(deviceId, opts || {});
|
|
993
982
|
await device.connect();
|
|
994
983
|
return new AndroidAgent(device, opts);
|
|
995
984
|
}
|
package/dist/lib/index.js
CHANGED
|
@@ -149,8 +149,7 @@ class AndroidDevice {
|
|
|
149
149
|
});
|
|
150
150
|
}),
|
|
151
151
|
(0, device_namespaceObject.defineActionKeyboardPress)(async (param)=>{
|
|
152
|
-
|
|
153
|
-
await this.keyboardPress(key);
|
|
152
|
+
await this.keyboardPress(param.keyName);
|
|
154
153
|
}),
|
|
155
154
|
(0, device_namespaceObject.defineAction)({
|
|
156
155
|
name: 'AndroidBackButton',
|
|
@@ -334,7 +333,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
334
333
|
}
|
|
335
334
|
async getScreenSize() {
|
|
336
335
|
var _this_options, _this_options1;
|
|
337
|
-
const shouldCache = !((null == (_this_options = this.options) ? void 0 : _this_options.
|
|
336
|
+
const shouldCache = !((null == (_this_options = this.options) ? void 0 : _this_options.alwaysRefreshScreenInfo) ?? false);
|
|
338
337
|
if (shouldCache && this.cachedScreenSize) return this.cachedScreenSize;
|
|
339
338
|
const adb = await this.getAdb();
|
|
340
339
|
if ('number' == typeof (null == (_this_options1 = this.options) ? void 0 : _this_options1.displayId)) try {
|
|
@@ -468,7 +467,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
468
467
|
}
|
|
469
468
|
async getDisplayOrientation() {
|
|
470
469
|
var _this_options;
|
|
471
|
-
const shouldCache = !((null == (_this_options = this.options) ? void 0 : _this_options.
|
|
470
|
+
const shouldCache = !((null == (_this_options = this.options) ? void 0 : _this_options.alwaysRefreshScreenInfo) ?? false);
|
|
472
471
|
if (shouldCache && null !== this.cachedOrientation) return this.cachedOrientation;
|
|
473
472
|
const adb = await this.getAdb();
|
|
474
473
|
let orientation = 0;
|
|
@@ -509,7 +508,8 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
509
508
|
const logicalHeight = Math.round(height * scale);
|
|
510
509
|
return {
|
|
511
510
|
width: logicalWidth,
|
|
512
|
-
height: logicalHeight
|
|
511
|
+
height: logicalHeight,
|
|
512
|
+
dpr: this.devicePixelRatio
|
|
513
513
|
};
|
|
514
514
|
}
|
|
515
515
|
adjustCoordinates(x, y) {
|
|
@@ -535,8 +535,8 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
535
535
|
const minScrollY = Math.min(minScrollDistance, actualScrollDistanceY);
|
|
536
536
|
actualScrollDistanceY = Math.max(minScrollY, actualScrollDistanceY);
|
|
537
537
|
}
|
|
538
|
-
const endX = 0 === deltaX ? start.x : deltaX > 0 ? Math.min(maxWidth, start.x + actualScrollDistanceX) : Math.max(0, start.x - actualScrollDistanceX);
|
|
539
|
-
const endY = 0 === deltaY ? start.y : deltaY > 0 ? Math.min(maxHeight, start.y + actualScrollDistanceY) : Math.max(0, start.y - actualScrollDistanceY);
|
|
538
|
+
const endX = Math.round(0 === deltaX ? start.x : deltaX > 0 ? Math.min(maxWidth, start.x + actualScrollDistanceX) : Math.max(0, start.x - actualScrollDistanceX));
|
|
539
|
+
const endY = Math.round(0 === deltaY ? start.y : deltaY > 0 ? Math.min(maxHeight, start.y + actualScrollDistanceY) : Math.max(0, start.y - actualScrollDistanceY));
|
|
540
540
|
return {
|
|
541
541
|
x: endX,
|
|
542
542
|
y: endY
|
|
@@ -598,7 +598,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
598
598
|
const adb = await this.getAdb();
|
|
599
599
|
await this.mouseClick(element.center[0], element.center[1]);
|
|
600
600
|
const IME_STRATEGY = ((null == (_this_options = this.options) ? void 0 : _this_options.imeStrategy) || env_namespaceObject.globalConfigManager.getEnvConfigValue(env_namespaceObject.MIDSCENE_ANDROID_IME_STRATEGY)) ?? IME_STRATEGY_YADB_FOR_NON_ASCII;
|
|
601
|
-
if (IME_STRATEGY === IME_STRATEGY_YADB_FOR_NON_ASCII) await
|
|
601
|
+
if (IME_STRATEGY === IME_STRATEGY_YADB_FOR_NON_ASCII) await adb.clearTextField(100);
|
|
602
602
|
else await adb.shell(`app_process${this.getDisplayArg()} -Djava.class.path=/data/local/tmp/yadb /data/local/tmp com.ysbing.yadb.Main -keyboard "~CLEAR~"`);
|
|
603
603
|
if (await adb.isSoftKeyboardPresent()) return;
|
|
604
604
|
await this.mouseClick(element.center[0], element.center[1]);
|
|
@@ -615,12 +615,12 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
615
615
|
if (startPoint) {
|
|
616
616
|
const { height } = await this.size();
|
|
617
617
|
const start = {
|
|
618
|
-
x: startPoint.left,
|
|
619
|
-
y: startPoint.top
|
|
618
|
+
x: Math.round(startPoint.left),
|
|
619
|
+
y: Math.round(startPoint.top)
|
|
620
620
|
};
|
|
621
621
|
const end = {
|
|
622
622
|
x: start.x,
|
|
623
|
-
y: height
|
|
623
|
+
y: Math.round(height)
|
|
624
624
|
};
|
|
625
625
|
await (0, shared_utils_namespaceObject.repeat)(defaultScrollUntilTimes, ()=>this.mouseDrag(start, end, defaultFastScrollDuration));
|
|
626
626
|
await (0, utils_namespaceObject.sleep)(1000);
|
|
@@ -632,8 +632,8 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
632
632
|
async scrollUntilBottom(startPoint) {
|
|
633
633
|
if (startPoint) {
|
|
634
634
|
const start = {
|
|
635
|
-
x: startPoint.left,
|
|
636
|
-
y: startPoint.top
|
|
635
|
+
x: Math.round(startPoint.left),
|
|
636
|
+
y: Math.round(startPoint.top)
|
|
637
637
|
};
|
|
638
638
|
const end = {
|
|
639
639
|
x: start.x,
|
|
@@ -650,11 +650,11 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
650
650
|
if (startPoint) {
|
|
651
651
|
const { width } = await this.size();
|
|
652
652
|
const start = {
|
|
653
|
-
x: startPoint.left,
|
|
654
|
-
y: startPoint.top
|
|
653
|
+
x: Math.round(startPoint.left),
|
|
654
|
+
y: Math.round(startPoint.top)
|
|
655
655
|
};
|
|
656
656
|
const end = {
|
|
657
|
-
x: width,
|
|
657
|
+
x: Math.round(width),
|
|
658
658
|
y: start.y
|
|
659
659
|
};
|
|
660
660
|
await (0, shared_utils_namespaceObject.repeat)(defaultScrollUntilTimes, ()=>this.mouseDrag(start, end, defaultFastScrollDuration));
|
|
@@ -667,8 +667,8 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
667
667
|
async scrollUntilRight(startPoint) {
|
|
668
668
|
if (startPoint) {
|
|
669
669
|
const start = {
|
|
670
|
-
x: startPoint.left,
|
|
671
|
-
y: startPoint.top
|
|
670
|
+
x: Math.round(startPoint.left),
|
|
671
|
+
y: Math.round(startPoint.top)
|
|
672
672
|
};
|
|
673
673
|
const end = {
|
|
674
674
|
x: 0,
|
|
@@ -683,11 +683,11 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
683
683
|
}
|
|
684
684
|
async scrollUp(distance, startPoint) {
|
|
685
685
|
const { height } = await this.size();
|
|
686
|
-
const scrollDistance = distance || height;
|
|
686
|
+
const scrollDistance = Math.round(distance || height);
|
|
687
687
|
if (startPoint) {
|
|
688
688
|
const start = {
|
|
689
|
-
x: startPoint.left,
|
|
690
|
-
y: startPoint.top
|
|
689
|
+
x: Math.round(startPoint.left),
|
|
690
|
+
y: Math.round(startPoint.top)
|
|
691
691
|
};
|
|
692
692
|
const end = this.calculateScrollEndPoint(start, 0, scrollDistance, 0, height);
|
|
693
693
|
await this.mouseDrag(start, end);
|
|
@@ -697,11 +697,11 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
697
697
|
}
|
|
698
698
|
async scrollDown(distance, startPoint) {
|
|
699
699
|
const { height } = await this.size();
|
|
700
|
-
const scrollDistance = distance || height;
|
|
700
|
+
const scrollDistance = Math.round(distance || height);
|
|
701
701
|
if (startPoint) {
|
|
702
702
|
const start = {
|
|
703
|
-
x: startPoint.left,
|
|
704
|
-
y: startPoint.top
|
|
703
|
+
x: Math.round(startPoint.left),
|
|
704
|
+
y: Math.round(startPoint.top)
|
|
705
705
|
};
|
|
706
706
|
const end = this.calculateScrollEndPoint(start, 0, -scrollDistance, 0, height);
|
|
707
707
|
await this.mouseDrag(start, end);
|
|
@@ -711,11 +711,11 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
711
711
|
}
|
|
712
712
|
async scrollLeft(distance, startPoint) {
|
|
713
713
|
const { width } = await this.size();
|
|
714
|
-
const scrollDistance = distance || width;
|
|
714
|
+
const scrollDistance = Math.round(distance || width);
|
|
715
715
|
if (startPoint) {
|
|
716
716
|
const start = {
|
|
717
|
-
x: startPoint.left,
|
|
718
|
-
y: startPoint.top
|
|
717
|
+
x: Math.round(startPoint.left),
|
|
718
|
+
y: Math.round(startPoint.top)
|
|
719
719
|
};
|
|
720
720
|
const end = this.calculateScrollEndPoint(start, scrollDistance, 0, width, 0);
|
|
721
721
|
await this.mouseDrag(start, end);
|
|
@@ -725,11 +725,11 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
725
725
|
}
|
|
726
726
|
async scrollRight(distance, startPoint) {
|
|
727
727
|
const { width } = await this.size();
|
|
728
|
-
const scrollDistance = distance || width;
|
|
728
|
+
const scrollDistance = Math.round(distance || width);
|
|
729
729
|
if (startPoint) {
|
|
730
730
|
const start = {
|
|
731
|
-
x: startPoint.left,
|
|
732
|
-
y: startPoint.top
|
|
731
|
+
x: Math.round(startPoint.left),
|
|
732
|
+
y: Math.round(startPoint.top)
|
|
733
733
|
};
|
|
734
734
|
const end = this.calculateScrollEndPoint(start, -scrollDistance, 0, width, 0);
|
|
735
735
|
await this.mouseDrag(start, end);
|
|
@@ -827,16 +827,16 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
827
827
|
if (0 === deltaX && 0 === deltaY) throw new Error('Scroll distance cannot be zero in both directions');
|
|
828
828
|
const { width, height } = await this.size();
|
|
829
829
|
const n = 4;
|
|
830
|
-
const startX = deltaX < 0 ? width / n * (n - 1) : width / n;
|
|
831
|
-
const startY = deltaY < 0 ? height / n * (n - 1) : height / n;
|
|
830
|
+
const startX = Math.round(deltaX < 0 ? width / n * (n - 1) : width / n);
|
|
831
|
+
const startY = Math.round(deltaY < 0 ? height / n * (n - 1) : height / n);
|
|
832
832
|
const maxNegativeDeltaX = startX;
|
|
833
|
-
const maxPositiveDeltaX = width / n * (n - 1);
|
|
833
|
+
const maxPositiveDeltaX = Math.round(width / n * (n - 1));
|
|
834
834
|
const maxNegativeDeltaY = startY;
|
|
835
|
-
const maxPositiveDeltaY = height / n * (n - 1);
|
|
835
|
+
const maxPositiveDeltaY = Math.round(height / n * (n - 1));
|
|
836
836
|
deltaX = Math.max(-maxNegativeDeltaX, Math.min(deltaX, maxPositiveDeltaX));
|
|
837
837
|
deltaY = Math.max(-maxNegativeDeltaY, Math.min(deltaY, maxPositiveDeltaY));
|
|
838
|
-
const endX = startX - deltaX;
|
|
839
|
-
const endY = startY - deltaY;
|
|
838
|
+
const endX = Math.round(startX - deltaX);
|
|
839
|
+
const endY = Math.round(startY - deltaY);
|
|
840
840
|
const { x: adjustedStartX, y: adjustedStartY } = this.adjustCoordinates(startX, startY);
|
|
841
841
|
const { x: adjustedEndX, y: adjustedEndY } = this.adjustCoordinates(endX, endY);
|
|
842
842
|
const adb = await this.getAdb();
|
|
@@ -874,13 +874,13 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
874
874
|
async pullDown(startPoint, distance, duration = 800) {
|
|
875
875
|
const { width, height } = await this.size();
|
|
876
876
|
const start = startPoint ? {
|
|
877
|
-
x: startPoint.left,
|
|
878
|
-
y: startPoint.top
|
|
877
|
+
x: Math.round(startPoint.left),
|
|
878
|
+
y: Math.round(startPoint.top)
|
|
879
879
|
} : {
|
|
880
|
-
x: width / 2,
|
|
881
|
-
y: 0.15 * height
|
|
880
|
+
x: Math.round(width / 2),
|
|
881
|
+
y: Math.round(0.15 * height)
|
|
882
882
|
};
|
|
883
|
-
const pullDistance = distance || 0.5 * height;
|
|
883
|
+
const pullDistance = Math.round(distance || 0.5 * height);
|
|
884
884
|
const end = {
|
|
885
885
|
x: start.x,
|
|
886
886
|
y: start.y + pullDistance
|
|
@@ -897,13 +897,13 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
897
897
|
async pullUp(startPoint, distance, duration = 600) {
|
|
898
898
|
const { width, height } = await this.size();
|
|
899
899
|
const start = startPoint ? {
|
|
900
|
-
x: startPoint.left,
|
|
901
|
-
y: startPoint.top
|
|
900
|
+
x: Math.round(startPoint.left),
|
|
901
|
+
y: Math.round(startPoint.top)
|
|
902
902
|
} : {
|
|
903
|
-
x: width / 2,
|
|
904
|
-
y: 0.85 * height
|
|
903
|
+
x: Math.round(width / 2),
|
|
904
|
+
y: Math.round(0.85 * height)
|
|
905
905
|
};
|
|
906
|
-
const pullDistance = distance || 0.4 * height;
|
|
906
|
+
const pullDistance = Math.round(distance || 0.4 * height);
|
|
907
907
|
const end = {
|
|
908
908
|
x: start.x,
|
|
909
909
|
y: start.y - pullDistance
|
|
@@ -1025,18 +1025,7 @@ async function agentFromAdbDevice(deviceId, opts) {
|
|
|
1025
1025
|
deviceId = devices[0].udid;
|
|
1026
1026
|
debugAgent('deviceId not specified, will use the first device (id = %s)', deviceId);
|
|
1027
1027
|
}
|
|
1028
|
-
const device = new AndroidDevice(deviceId, {
|
|
1029
|
-
autoDismissKeyboard: null == opts ? void 0 : opts.autoDismissKeyboard,
|
|
1030
|
-
androidAdbPath: null == opts ? void 0 : opts.androidAdbPath,
|
|
1031
|
-
remoteAdbHost: null == opts ? void 0 : opts.remoteAdbHost,
|
|
1032
|
-
remoteAdbPort: null == opts ? void 0 : opts.remoteAdbPort,
|
|
1033
|
-
imeStrategy: null == opts ? void 0 : opts.imeStrategy,
|
|
1034
|
-
displayId: null == opts ? void 0 : opts.displayId,
|
|
1035
|
-
usePhysicalDisplayIdForScreenshot: null == opts ? void 0 : opts.usePhysicalDisplayIdForScreenshot,
|
|
1036
|
-
usePhysicalDisplayIdForDisplayLookup: null == opts ? void 0 : opts.usePhysicalDisplayIdForDisplayLookup,
|
|
1037
|
-
screenshotResizeScale: null == opts ? void 0 : opts.screenshotResizeScale,
|
|
1038
|
-
alwaysFetchScreenInfo: null == opts ? void 0 : opts.alwaysFetchScreenInfo
|
|
1039
|
-
});
|
|
1028
|
+
const device = new AndroidDevice(deviceId, opts || {});
|
|
1040
1029
|
await device.connect();
|
|
1041
1030
|
return new AndroidAgent(device, opts);
|
|
1042
1031
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { AbstractInterface } from '@midscene/core/device';
|
|
|
2
2
|
import { ADB } from 'appium-adb';
|
|
3
3
|
import { Agent } from '@midscene/core/agent';
|
|
4
4
|
import { AgentOpt } from '@midscene/core/agent';
|
|
5
|
+
import { AndroidDeviceInputOpt } from '@midscene/core/device';
|
|
6
|
+
import { AndroidDeviceOpt } from '@midscene/core/device';
|
|
5
7
|
import { Device } from 'appium-adb';
|
|
6
8
|
import { DeviceAction } from '@midscene/core';
|
|
7
9
|
import type { ElementInfo } from '@midscene/shared/extractor';
|
|
@@ -114,32 +116,8 @@ export declare class AndroidDevice implements AbstractInterface {
|
|
|
114
116
|
hideKeyboard(options?: AndroidDeviceInputOpt, timeoutMs?: number): Promise<boolean>;
|
|
115
117
|
}
|
|
116
118
|
|
|
117
|
-
declare type AndroidDeviceInputOpt = {
|
|
118
|
-
autoDismissKeyboard?: boolean;
|
|
119
|
-
keyboardDismissStrategy?: 'esc-first' | 'back-first';
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
declare type AndroidDeviceOpt = {
|
|
123
|
-
androidAdbPath?: string;
|
|
124
|
-
remoteAdbHost?: string;
|
|
125
|
-
remoteAdbPort?: number;
|
|
126
|
-
imeStrategy?: ImeStrategy;
|
|
127
|
-
displayId?: number;
|
|
128
|
-
usePhysicalDisplayIdForScreenshot?: boolean;
|
|
129
|
-
usePhysicalDisplayIdForDisplayLookup?: boolean;
|
|
130
|
-
customActions?: DeviceAction<any>[];
|
|
131
|
-
screenshotResizeScale?: number;
|
|
132
|
-
alwaysFetchScreenInfo?: boolean;
|
|
133
|
-
} & AndroidDeviceInputOpt;
|
|
134
|
-
|
|
135
119
|
export declare function getConnectedDevices(): Promise<Device[]>;
|
|
136
120
|
|
|
137
|
-
declare const IME_STRATEGY_ALWAYS_YADB: "always-yadb";
|
|
138
|
-
|
|
139
|
-
declare const IME_STRATEGY_YADB_FOR_NON_ASCII: "yadb-for-non-ascii";
|
|
140
|
-
|
|
141
|
-
declare type ImeStrategy = typeof IME_STRATEGY_ALWAYS_YADB | typeof IME_STRATEGY_YADB_FOR_NON_ASCII;
|
|
142
|
-
|
|
143
121
|
export { overrideAIConfig }
|
|
144
122
|
|
|
145
123
|
export { }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midscene/android",
|
|
3
|
-
"version": "1.0.1-beta-
|
|
3
|
+
"version": "1.0.1-beta-20251024063839.0",
|
|
4
4
|
"description": "Android automation library for Midscene",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Android UI automation",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"appium-adb": "12.12.1",
|
|
30
|
-
"@midscene/
|
|
31
|
-
"@midscene/
|
|
30
|
+
"@midscene/core": "1.0.1-beta-20251024063839.0",
|
|
31
|
+
"@midscene/shared": "1.0.1-beta-20251024063839.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@rslib/core": "^0.11.2",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"typescript": "^5.8.3",
|
|
38
38
|
"tsx": "^4.19.2",
|
|
39
39
|
"vitest": "3.0.5",
|
|
40
|
-
"@midscene/playground": "1.0.1-beta-
|
|
40
|
+
"@midscene/playground": "1.0.1-beta-20251024063839.0"
|
|
41
41
|
},
|
|
42
42
|
"license": "MIT",
|
|
43
43
|
"scripts": {
|