在较旧的 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(点击观看,原谅方向)