【问题标题】:iOS UITesting How to Dismiss Popover (iPad Popover NOT Alert Style)iOS UITesting 如何关闭弹出框(iPad 弹出框不提醒样式)
【发布时间】:2017-01-27 08:59:48
【问题描述】:

我有一个非常复杂的应用程序,其中包含大量视图和弹出框,用于快速选择条目。

我无法关闭弹出框。我尝试了很多:

  • 在窗口中点击坐标
  • app.otherElements["PopoverDismissRegion"] 击中后面的元素
  • 弹出框(根本无法点击)

当我在 XCode 中记录它时,我得到: app.otherElements["PopoverDismissRegion"]

这对我来说毫无意义。

希望有人能提供帮助。

谢谢

信息:iOS 10.2,Xcode 8.2.1, iPad Air 2(设备和模拟器,结果相同)

【问题讨论】:

标签: ios swift testing


【解决方案1】:

编辑

找到了更好的解决方案here:

XCUIApplication().otherElements["PopoverDismissRegion"].tap()

原解决方案:

试试这个:

XCUIApplication().windows.element(boundBy: 0).tap()

点击窗口并关闭当前活动的弹出框。

【讨论】:

  • 我以前试过这个,看看我的第二个子弹。这也被建议了很多,但它对我没有用。它可能适用于警报控制器,但不适用于显示为导航栏项目弹出框的表格视图。
【解决方案2】:

只需执行以下操作,iPhone 模拟器上的一切都对我有用:

app.swipeDown(velocity: .fast)

当我想在 iPad 模拟器上运行相同的测试时,我开始遇到问题。正在应用该手势,但它还不足以关闭视图。我尝试了不同的方法,例如:

XCUIApplication().windows.element(boundBy: 0).tap()

或

app.otherElements["PopoverDismissRegion"].tap()

但没有任何工作。该视图仍未被关闭。

对其进行更多测试后,我发现如果 iPad 模拟器处于横向状态,发送 swipeDown 手势实际上会关闭视图。所以...我能够像这样解决问题:

// If iPad, put the simulator on landscape mode
if UIDevice.current.userInterfaceIdiom == .pad { 
    XCUIDevice.shared.orientation = .landscapeLeft
}

// Perform the swipe
app.swipeDown(velocity: .fast)

// Restore device portrait mode
if UIDevice.current.userInterfaceIdiom == .pad { 
    XCUIDevice.shared.orientation = .portrait
}

【讨论】:

    猜你喜欢
    • 2012-12-28
    • 2012-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-26
    • 1970-01-01
    • 2011-07-10
    • 1970-01-01
    相关资源
    最近更新 更多