gpt4 book ai didi

ios - 在 xcode ui 测试执行过程中关闭设备的 wifi

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:38:02 28 4
gpt4 key购买 nike

我在 xcode ui 测试中遇到问题。

也就是说,在执行我的过程中,比在某些情况下

i have to off my wifi

我知道我可以使用命令来做到这一点

networksetup -setairportpower en0 on

我在 osx 中写了一个函数:

func runTerminalCommand(args: String...) -> Int32 {
let task = NSTask()
task.launchPath = "/usr/bin/env"
task.arguments = args
task.launch()
task.waitUntilExit()
return task.terminationStatus

如果我在 osx 中使用它,我可以关闭 wifi。

但我不能在我的 iOS 应用程序中使用它,或者不能在我的应用程序中使用它xcode 用户界面测试。

我如何在 xcode ui 测试正在进行时关闭我的 wifi?

最佳答案

Xcode 9 中,您现在可以在运行 UITest 时点击控制中心中的 wifi 按钮。

这里有一个小帮助函数,可以打开控制中心,点击 wifi 按钮并再次关闭它:

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

// open control center
let coord1 = app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.99))
let coord2 = app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.1))
coord1.press(forDuration: 0.1, thenDragTo: coord2)

let wifiButton = springboard.switches["wifi-button"]
wifiButton.tap()

// open your app back again
springboard.otherElements["com.your.app.identifier"].tap()
}

请记住,在运行测试时您必须使用电缆连接您的设备 ;-)

关于ios - 在 xcode ui 测试执行过程中关闭设备的 wifi,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39960490/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com