iPhone 屏幕/安卓屏幕上的 X 和 Y 轴格式是什么?



我一直在研究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 循环中使用正确的语法。 如果有人对如何将滑动功能正确合并到其中有任何建议,那将有很大帮助。

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

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

请查看如何在滚动到底部时借助设备的高度和宽度获得动态 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;

相关内容

最新更新