【问题标题】:Is it possible to move an app to a split view / a slider over view programmatically inside ui test after an app running?在应用程序运行后,是否可以在 ui 测试中以编程方式将应用程序移动到拆分视图/滑块视图?
【发布时间】:2018-06-06 07:38:56
【问题描述】:

我想测试某些功能在拆分/幻灯片视图中是否有效。

我当前的 ui 测试打开停靠面板并尝试将 iMessage 应用程序拖到模拟器屏幕的右边框。

看起来任何交互都不适用于与我的应用无关的元素。

是否可以在应用运行后以编程方式在 ui 测试中将应用移动到拆分视图或滑块?

【问题讨论】:

  • 您好,请问您是如何在 UI 测试中打开停靠面板的?
  • 很遗憾,我没有。

标签: ios xcuitest


【解决方案1】:

在较旧的 iOS 版本上可以。但是,据我所知,它需要使用坐标手动完成。我在这里找到了一个现有的帮助程序存储库,可能会有所帮助(虽然我没有使用过)https://github.com/superz515/UITestingMultitaskingHelper

iOS 15 借助多任务支持 UI 让这一切变得更加容易。

如果您在 XCUITest 过程中观察跳板应用程序,您会看到:

默认状态:

Button, 0x600001a02d80, {{1004.5, 667.0}, {14.0, 32.0}}, identifier: 'top-affordance:XCUITestSplit', label: 'XCUITestSplit, Multitasking controls'

点击控件后:

Button, 0x600001431340, {{968.0, 609.0}, {40.0, 40.0}}, identifier: 'top-affordance-full-screen-button', label: 'Full screen', Selected
Button, 0x600001431500, {{968.0, 663.0}, {40.0, 40.0}}, identifier: 'top-affordance-split-view-button', label: 'Split view'
Button, 0x6000014316c0, {{968.0, 717.0}, {40.0, 40.0}}, identifier: 'top-affordance-slide-over-button', label: 'Slide over'

点击选项后:

BannerNotification, 0x600001a38000, {{966.0, 574.5}, {50.0, 217.5}}
    Button, 0x600001a380e0, {{966.0, 574.5}, {50.0, 217.5}}, label: 'Split View, Choose another app'

图标示例

Icon, {{0.0, 0.0}, {0.0, 0.0}}, identifier: 'Files', label: 'Files'
Icon, {{0.0, 0.0}, {0.0, 0.0}}, identifier: 'Reminders', label: 'Reminders'
Icon, {{0.0, 0.0}, {0.0, 0.0}}, identifier: 'News', label: 'News'
Icon, {{0.0, 0.0}, {0.0, 0.0}}, identifier: 'Calendar', label: 'Calendar'
Icon, {{0.0, 0.0}, {0.0, 0.0}}, identifier: 'Reminders', label: 'Reminders'
Icon, {{0.0, 0.0}, {0.0, 0.0}}, identifier: 'Maps', label: 'Maps'
Icon, {{0.0, 0.0}, {0.0, 0.0}}, identifier: 'News', label: 'News'
Icon, {{0.0, 0.0}, {0.0, 0.0}}, identifier: 'Settings', label: 'Settings'
Icon, {{810.5, 155.0}, {95.5, 77.0}}, identifier: 'Shortcuts', label: 'Create XCUITestSplit split view with Shortcuts'
Icon, {{810.5, 353.0}, {95.5, 72.5}}, identifier: 'Contacts', label: 'Create XCUITestSplit split view with Contacts'
Icon, {{810.5, 548.0}, {95.5, 75.0}}, identifier: 'Magnifier', label: 'Create XCUITestSplit split view with Magnifier'

示例

以上内容可以让您很快进入拆分视图。 然而,对多少列的更多控制需要移动分隔线,这需要更多的工作(正如我之前提到的),并且您还需要考虑重置状态,以便应用程序不会在拆分视图中再次启动。

func testExample() throws {
    let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
    let app = XCUIApplication()

    app.launch()
    springboard.buttons["top-affordance:XCUITestSplit"].tap()
    springboard.buttons["top-affordance-split-view-button"].tap()
    springboard.icons["Shortcuts"].firstMatch.tap()
}

Gif(点击观看,原谅方向)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-08
    • 2013-12-18
    • 1970-01-01
    相关资源
    最近更新 更多