@midscene/ios 1.0.1-beta-20251022061922.0 → 1.0.1-beta-20251024064637.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 CHANGED
@@ -196,19 +196,45 @@ class IOSWebDriverClient extends WebDriverClient {
196
196
  }
197
197
  async swipe(fromX, fromY, toX, toY, duration = 500) {
198
198
  this.ensureSession();
199
- try {
200
- await this.makeRequest('POST', `/session/${this.sessionId}/wda/dragfromtoforduration`, {
201
- fromX,
202
- fromY,
203
- toX,
204
- toY,
205
- duration: duration / 1000
206
- });
207
- debugIOS(`Swiped from (${fromX}, ${fromY}) to (${toX}, ${toY}) in ${duration}ms`);
208
- } catch (error) {
209
- debugIOS(`Failed to swipe from (${fromX}, ${fromY}) to (${toX}, ${toY}): ${error}`);
210
- throw new Error(`Failed to swipe: ${error}`);
211
- }
199
+ const actions = {
200
+ actions: [
201
+ {
202
+ type: 'pointer',
203
+ id: 'finger1',
204
+ parameters: {
205
+ pointerType: 'touch'
206
+ },
207
+ actions: [
208
+ {
209
+ type: 'pointerMove',
210
+ duration: 0,
211
+ x: fromX,
212
+ y: fromY
213
+ },
214
+ {
215
+ type: 'pointerDown',
216
+ button: 0
217
+ },
218
+ {
219
+ type: 'pause',
220
+ duration: 100
221
+ },
222
+ {
223
+ type: 'pointerMove',
224
+ duration,
225
+ x: toX,
226
+ y: toY
227
+ },
228
+ {
229
+ type: 'pointerUp',
230
+ button: 0
231
+ }
232
+ ]
233
+ }
234
+ ]
235
+ };
236
+ await this.makeRequest('POST', `/session/${this.sessionId}/actions`, actions);
237
+ debugIOS(`Swiped using W3C Actions from (${fromX}, ${fromY}) to (${toX}, ${toY}) in ${duration}ms`);
212
238
  }
213
239
  async longPress(x, y, duration = 1000) {
214
240
  this.ensureSession();
@@ -354,8 +380,7 @@ class IOSDevice {
354
380
  await this.swipe(from.center[0], from.center[1], to.center[0], to.center[1]);
355
381
  }),
356
382
  defineActionKeyboardPress(async (param)=>{
357
- const key = param.keyName;
358
- await this.pressKey(key);
383
+ await this.pressKey(param.keyName);
359
384
  }),
360
385
  defineAction({
361
386
  name: 'IOSHomeButton',
@@ -511,23 +536,23 @@ ScreenSize: ${size.width}x${size.height} (DPR: ${size.scale})
511
536
  return '';
512
537
  }
513
538
  async tap(x, y) {
514
- await this.wdaBackend.tap(x, y);
539
+ await this.wdaBackend.tap(Math.round(x), Math.round(y));
515
540
  }
516
541
  async mouseClick(x, y) {
517
542
  debugDevice(`mouseClick at coordinates (${x}, ${y})`);
518
543
  await this.tap(x, y);
519
544
  }
520
545
  async doubleTap(x, y) {
521
- await this.wdaBackend.doubleTap(x, y);
546
+ await this.wdaBackend.doubleTap(Math.round(x), Math.round(y));
522
547
  }
523
548
  async tripleTap(x, y) {
524
- await this.wdaBackend.tripleTap(x, y);
549
+ await this.wdaBackend.tripleTap(Math.round(x), Math.round(y));
525
550
  }
526
551
  async longPress(x, y, duration = 1000) {
527
- await this.wdaBackend.longPress(x, y, duration);
552
+ await this.wdaBackend.longPress(Math.round(x), Math.round(y), duration);
528
553
  }
529
554
  async swipe(fromX, fromY, toX, toY, duration = 500) {
530
- await this.wdaBackend.swipe(fromX, fromY, toX, toY, duration);
555
+ await this.wdaBackend.swipe(Math.round(fromX), Math.round(fromY), Math.round(toX), Math.round(toY), duration);
531
556
  }
532
557
  async typeText(text, options) {
533
558
  var _this_options;
@@ -550,49 +575,49 @@ ScreenSize: ${size.width}x${size.height} (DPR: ${size.scale})
550
575
  async scrollUp(distance, startPoint) {
551
576
  const { width, height } = await this.size();
552
577
  const start = startPoint ? {
553
- x: startPoint.left,
554
- y: startPoint.top
578
+ x: Math.round(startPoint.left),
579
+ y: Math.round(startPoint.top)
555
580
  } : {
556
- x: width / 2,
557
- y: height / 2
581
+ x: Math.round(width / 2),
582
+ y: Math.round(height / 2)
558
583
  };
559
- const scrollDistance = distance || height / 3;
584
+ const scrollDistance = Math.round(distance || height / 3);
560
585
  await this.swipe(start.x, start.y, start.x, start.y + scrollDistance);
561
586
  }
562
587
  async scrollDown(distance, startPoint) {
563
588
  const { width, height } = await this.size();
564
589
  const start = startPoint ? {
565
- x: startPoint.left,
566
- y: startPoint.top
590
+ x: Math.round(startPoint.left),
591
+ y: Math.round(startPoint.top)
567
592
  } : {
568
- x: width / 2,
569
- y: height / 2
593
+ x: Math.round(width / 2),
594
+ y: Math.round(height / 2)
570
595
  };
571
- const scrollDistance = distance || height / 3;
596
+ const scrollDistance = Math.round(distance || height / 3);
572
597
  await this.swipe(start.x, start.y, start.x, start.y - scrollDistance);
573
598
  }
574
599
  async scrollLeft(distance, startPoint) {
575
600
  const { width, height } = await this.size();
576
601
  const start = startPoint ? {
577
- x: startPoint.left,
578
- y: startPoint.top
602
+ x: Math.round(startPoint.left),
603
+ y: Math.round(startPoint.top)
579
604
  } : {
580
- x: width / 2,
581
- y: height / 2
605
+ x: Math.round(width / 2),
606
+ y: Math.round(height / 2)
582
607
  };
583
- const scrollDistance = distance || width / 3;
608
+ const scrollDistance = Math.round(distance || 0.7 * width);
584
609
  await this.swipe(start.x, start.y, start.x + scrollDistance, start.y);
585
610
  }
586
611
  async scrollRight(distance, startPoint) {
587
612
  const { width, height } = await this.size();
588
613
  const start = startPoint ? {
589
- x: startPoint.left,
590
- y: startPoint.top
614
+ x: Math.round(startPoint.left),
615
+ y: Math.round(startPoint.top)
591
616
  } : {
592
- x: width / 2,
593
- y: height / 2
617
+ x: Math.round(width / 2),
618
+ y: Math.round(height / 2)
594
619
  };
595
- const scrollDistance = distance || width / 3;
620
+ const scrollDistance = Math.round(distance || 0.7 * width);
596
621
  await this.swipe(start.x, start.y, start.x - scrollDistance, start.y);
597
622
  }
598
623
  async scrollUntilTop(startPoint) {
@@ -633,32 +658,32 @@ ScreenSize: ${size.width}x${size.height} (DPR: ${size.scale})
633
658
  const { width, height } = await this.size();
634
659
  let start;
635
660
  if (startPoint) start = {
636
- x: startPoint.left,
637
- y: startPoint.top
661
+ x: Math.round(startPoint.left),
662
+ y: Math.round(startPoint.top)
638
663
  };
639
664
  else switch(direction){
640
665
  case 'up':
641
666
  start = {
642
- x: width / 2,
643
- y: 0.2 * height
667
+ x: Math.round(width / 2),
668
+ y: Math.round(0.2 * height)
644
669
  };
645
670
  break;
646
671
  case 'down':
647
672
  start = {
648
- x: width / 2,
649
- y: 0.8 * height
673
+ x: Math.round(width / 2),
674
+ y: Math.round(0.8 * height)
650
675
  };
651
676
  break;
652
677
  case 'left':
653
678
  start = {
654
- x: 0.8 * width,
655
- y: height / 2
679
+ x: Math.round(0.8 * width),
680
+ y: Math.round(height / 2)
656
681
  };
657
682
  break;
658
683
  case 'right':
659
684
  start = {
660
- x: 0.2 * width,
661
- y: height / 2
685
+ x: Math.round(0.2 * width),
686
+ y: Math.round(height / 2)
662
687
  };
663
688
  break;
664
689
  }
@@ -685,7 +710,7 @@ ScreenSize: ${size.width}x${size.height} (DPR: ${size.scale})
685
710
  break;
686
711
  }
687
712
  lastScreenshot = currentScreenshot;
688
- const scrollDistance = 'left' === direction || 'right' === direction ? 0.6 * width : 0.6 * height;
713
+ const scrollDistance = Math.round('left' === direction || 'right' === direction ? 0.6 * width : 0.6 * height);
689
714
  debugDevice(`Performing scroll: ${direction}, distance: ${scrollDistance}`);
690
715
  switch(direction){
691
716
  case 'up':
@@ -722,9 +747,9 @@ ScreenSize: ${size.width}x${size.height} (DPR: ${size.scale})
722
747
  try {
723
748
  debugDevice('Triggering app switcher with slow swipe up gesture');
724
749
  const { width, height } = await this.size();
725
- const centerX = width / 2;
726
- const startY = height - 5;
727
- const endY = 0.5 * height;
750
+ const centerX = Math.round(width / 2);
751
+ const startY = Math.round(height - 5);
752
+ const endY = Math.round(0.5 * height);
728
753
  await this.wdaBackend.swipe(centerX, startY, centerX, endY, 1500);
729
754
  await sleep(800);
730
755
  } catch (error) {
@@ -742,9 +767,9 @@ ScreenSize: ${size.width}x${size.height} (DPR: ${size.scale})
742
767
  return true;
743
768
  }
744
769
  const windowSize = await this.wdaBackend.getWindowSize();
745
- const centerX = windowSize.width / 2;
746
- const startY = 0.33 * windowSize.height;
747
- const endY = 0.33 * windowSize.height + 10;
770
+ const centerX = Math.round(windowSize.width / 2);
771
+ const startY = Math.round(0.33 * windowSize.height);
772
+ const endY = Math.round(0.33 * windowSize.height + 10);
748
773
  await this.swipe(centerX, startY, centerX, endY, 50);
749
774
  debugDevice('Dismissed keyboard with swipe down gesture at screen one-third position');
750
775
  await sleep(300);