我找到了打开今日/通知面板的方法.看起来很简单:
let statusbar = XCUIApplication().statusbars.elementBoundByIndex(0)statusbar.swipeDown()
但后来我找不到办法做一些有用的事情.可以在“今日/通知”面板中记录UI交互,但此类代码无法重现我的 *** 作.
解决方法 测试扩展有类似的问题.我发现你必须做的就是点击元素在屏幕上的位置而不是元素本身,以便驱动交互.我没有用你的场景测试过这个,但我还没有找到任何通过这种方法无法访问的东西.这是一个Swift示例,在Springboard上点击“X”按钮获取应用程序图标,同样无法通过典型的交互点击:
let iconFrame = icon.frame // App icon on the springboardlet springboardFrame = springboard.frame // The springboard (homescreen)icon.pressForDuration(1.3) // tap and hold// Tap the little "X" button at approximately where it is. The X is not exposed directlyspringboard.coordinateWithnormalizedOffset(CGVectorMake((iconFrame.minX + 3) / springboardFrame.maxX,(iconFrame.minY + 3) / springboardFrame.maxY)).tap()
通过获取超视图和子视图的框架,您可以计算元素应在屏幕上的位置.请注意,coordinateWithnormalizedOffset采用范围[0,1]中的向量,而不是帧或像素偏移.在坐标上点击元素本身也不起作用,因此您必须点击supervIEw / XCUIApplication()层.
更一般化的例子:
let myElementFrame = myElement.framelet appFrame = XCUIApplication().framelet mIDdleOfElementVector = CGVectorMake(iconFrame.mIDX / appFrame.maxX,iconFrame.mIDY / appFrame.maxY)// Tap element from the app-level at the given coordinateXCUIApplication().coordinateWithnormalizedOffset(mIDdleOfElementVector).tap()
如果您需要访问Springboard层并转到应用程序之外,您可以使用以下命令:
let springboard = XCUIApplication(privateWithPath: nil,bundleID: "com.apple.springboard")springboard.resolve()
但是您需要使用Objective-C公开一些私有的XCUITest方法:
@interface XCUIApplication (Private) { - (ID)initPrivateWithPath:(ID)arg1 bundleID:(ID)arg2;}@interface XCUIElement (Private) { - (voID) resolve;}总结
以上是内存溢出为你收集整理的ios – XCUITest和Today Widget全部内容,希望文章能够帮你解决ios – XCUITest和Today Widget所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)