【问题标题】:What is the X and Y axis format on an iPhone screen/Android screen?iPhone 屏幕/Android 屏幕上的 X 和 Y 轴格式是什么?
【发布时间】:2020-05-05 10:58:18
【问题描述】:

我一直在研究 iPhone 屏幕上设置的 X 和 Y 轴,因为我正在尝试使用 Appium 在应用程序上运行自动化测试。我正在做的部分工作是滑动,但我遇到了移动点、X 点和 Y 点的问题。

我不知道 iPhone 屏幕或 Android 屏幕上 X 轴和 Y 轴的限制是什么。因此,我不确定我的光标从哪里滑动到哪里。

到目前为止,我已经能够通过下面的代码进行一次滑动,

TouchAction action1 = new TouchAction((PerformsTouchActions) driver);
        action1.press(PointOption.point(250,200))
                .waitAction(new WaitOptions().withDuration(Duration.ofMillis(250))) //you can change wait durations as per your requirement
                .moveTo(PointOption.point(50, 250))
                .release()
                .perform();

        Thread.sleep(5000);

这会成功向左滑动一次,但第二次滑动会成功运行,但不会向左滑动屏幕。如,滑动它,但它不会将其移动到所需的阈值以将其移动到下一页。

让我们知道上面的代码放在一个for循环中,如下所示。

 for(int i = 0; i <= 3; i++){
        TouchAction action1 = new TouchAction((PerformsTouchActions) driver);
        action1.press(PointOption.point(250,200))
                .waitAction(new WaitOptions().withDuration(Duration.ofMillis(250))) //you can change wait durations as per your requirement
                .moveTo(PointOption.point(50, 250))
                .release()
                .perform();

        Thread.sleep(5000);

    }

是否有任何适用于 iPhone 或 Android 的文档显示 X 和 Y 轴的设置、限制等

编辑:

第一段代码放在 for 循环之外。我相信那是一段正确刷屏的代码。一旦进入for循环,屏幕就无法正常滑动。我相信我没有在 for 循环中使用正确的语法。 如果有人对如何将滑动功能正确合并到 for 有任何建议,那将有很大帮助。

【问题讨论】:

  • x 和 y 的限制由设备类型决定。通常(至少在 iOS 中),我们将 x 和 y 值与视图的boundswidthheight 进行比较...
  • @Light Upvote 提出一个好问题和最需要知道的问题

标签: java android ios appium


【解决方案1】:

X、Y 坐标取决于您使用的设备/模拟器 如果设备有大显示屏,自动化,X,Y 值会很高。

我建议不要在滑动或滚动时使用hardcoded value of X, Y,并借助it can throw exception points are out of device whenever you will be shifted on small screen Device 的坐标。

请查看如何在滚动到底部时借助设备的高度和宽度获取动态 X、Y 值

public void scrollToBottom() {

// we are  scrolling to bottom so X will be constant so we are taking mid point in width. 
      int  x = driver.manage().window().getSize().width / 2;

// starting of Y is from 20% of height as we have one bar in all device for showing network and battery status
      int start_y = (int) (driver.manage().window().getSize().height * 0.2);

// end of Y is 80% of height
      int end_y = (int) (driver.manage().window().getSize().height * 0.8);

// here scrolling length is (80% -20%) 60%.
        TouchAction dragNDrop = new TouchAction(driver)
                        .press(PointOption.point(x,start_y)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(500)))
                        .moveTo(PointOption.point(x, end_y))
                        .release();
        dragNDrop.perform();
    }

如果你想get X,Y coordinate of any Mobile Element你可以得到如下所述

MobileElement element = (MobileElement) driver.findElementByAccessibilityId("SomeAccessibilityID");
Point location = element.getLocation();

int leftX = element.getLocation().getX();
int rightX = leftX + element.getSize().getWidth();
int middleX = (rightX + leftX) / 2;
int upperY = element.getLocation().getY();
int lowerY = upperY+element.getSize().getHeight();
int middleY = (upperY + lowerY) / 2;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多