问题描述
限时送ChatGPT账号..我正在测试一个 iOS 应用程序,目前我正在使用 isHittable
检查特定 XCUIElement
的存在.
I am testing an iOS Application and currently I am checking the existence of a particular XCUIElement
using isHittable
.
我想知道我们是否还可以检查 XCUIElement 在视图上的位置.例如,如果我们在视图的右下角有一个按钮,我们是否可以使用 XCTest 框架检查它是否真的在右下角?
I wanted to know if we can also check the position of the XCUIElement on the view. For instance, if we have a button in the bottom right corner of the view, can we check if it is actually in the bottom right corner using XCTest framework?
我查看了 XCTest 框架的 Apple 文档,但没有得到任何线索.任何帮助将不胜感激.
I had a look at the Apple Documentation for XCTest framework but did not get any clue. Any help will be greatly appreciated.
推荐答案
XCUIElement
有一个属性 frame
可用于查找相关元素的坐标.
XCUIElement
has a property frame
which you can use to find the coordinates of the element in question.
let button = XCUIApplication().buttons["someButton"]
let frame = button.frame
let xPosition = frame.origin.x
let yPosition = frame.origin.y
还有其他方法可以检索相对于框架的不同点,这是一个 CGRect
,比如midX
和midY
,取决于你想如何断言元素的位置.
There are other ways of retrieving different points relative to the frame, which is a CGRect
, such as midX
and midY
, depending on how you want to assert the position of the element.
您应该知道 XCTest 是一个功能性 UI 测试框架,如果您使用它来断言元素的位置,则每个设备/模拟器的位置可能会有所不同,这可能会导致你的测试很脆弱.
You should be aware that XCTest is a functional UI testing framework, and if you are using it for asserting the position of an element, the position will probably be different per device/simulator which may make your tests brittle.
这篇关于使用 XCTest 测试 iOS 应用程序时检查 XCUIElement 在屏幕上的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论