简体   繁体   English

Xamarin.UITest:如何检索设备显示的坐标

[英]Xamarin.UITest: How To Retrieve Coordinates of Device Display

I am writing a UITest in C# using Xamarin.UITest. 我正在使用Xamarin.UITest在C#中编写UITest。

How can I retrieve the coordinates of the device's screen dynamically in the UITest? 如何在UITest中动态检索设备屏幕的坐标?

In Xamarin.UITest, when you call app.Query() , the first query result will return the device display. 在Xamarin.UITest中,当您调用app.Query() ,第一个查询结果将返回设备显示。 You can then grab the XY coordinates using the Rect property. 然后,您可以使用Rect属性获取XY坐标。

Below is a sample REPL output showing the result of app.Query().First() , and sample code assigning the XY coordinates to variables in your UITest. 下面是一个示例REPL输出,显示了app.Query().First() ,以及将XY坐标分配给UITest中的变量的示例代码。

Sample Output from REPL REPL的样本输出

REPL的输出

Sample Code 样例代码

var windowQuery = app.Query().First();

var topLeftXCoordinate = windowQuery.Rect.X;
var topLeftYCoordinate = windowQuery.Rect.Y;

var topRightXCoordinate = windowQuery.Rect.X + windowQuery.Rect.Width;
var topRightYCoordinate = windowQuery.Rect.Y;

var bottomLeftXCoordinate = windowQuery.Rect.X;
var bottomLeftYCoordinate = windowQuery.Rect.Y + windowQuery.Rect.Height;

var bottomRightXCoordinate = windowQuery.Rect.X + windowQuery.Rect.Width;
var bottomRightYCoordinate = windowQuery.Rect.Y + windowQuery.Rect.Height;

var centerXCoordinate = windowQuery.Rect.CenterX;
var centerYCoordinate = windowQuery.Rect.CenterY;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM