我一直在为我的应用程序编写测试。但是运行我的测试时,我不断收到错误Stall on main thread
我的功能如何将一个私有函数变成一个辅助函数?
private func waitForElementToAppear(testCase: XCTestCase,
element: XCUIElement,
file: String = #file,
line: UInt = #line) {
let existsPredicate = NSPredicate(format: "exists == true")
testCase.expectationForPredicate(existsPredicate,
evaluatedWithObject: element, handler: nil)
testCase.waitForExpectationsWithTimeout(5) { (error) -> Void in
if (error != nil) {
let message = "Failed to find \(element) after 5 seconds."
testCase.recordFailureWithDescription(message,
inFile: file, atLine: line, expected: true)
}
}
}
我用这个功能好几次在我的测试/代码。我怎样才能将它转换成辅助函数,所以我只需要编写一次这个函数。感谢您提前帮助:)
感谢您的回答!我已经将该函数移入扩展类 - 但是现在,当尝试使用该函数时,出现错误“使用未解析的标识符'waitForElement'”,例如'waitForElementToAppear(app.staticTexts [“添加评论”])' –
删除'私人' – Alistra
我的男人,谢谢G! –