Ios 无法监视事件循环并等待应用程序空闲
我正在使用XTest为我的应用程序编写UITest用例。应用程序在主屏幕上进行多次服务器调用。我无法导航到下一个屏幕。自动化通常会闲置1分钟,甚至超过消息的闲置时间 等待应用程序空闲 或 无法监视事件循环Ios 无法监视事件循环并等待应用程序空闲,ios,xcode,xctest,xctestcase,Ios,Xcode,Xctest,Xctestcase,我正在使用XTest为我的应用程序编写UITest用例。应用程序在主屏幕上进行多次服务器调用。我无法导航到下一个屏幕。自动化通常会闲置1分钟,甚至超过消息的闲置时间 等待应用程序空闲 或 无法监视事件循环 有没有一种方法可以让应用程序执行我的测试用例来打破这一点?我的建议是帮助您使用以下两种方法之一。第一个等待元素出现在屏幕上。第二个元素正在等待命中。但是在任何情况下,这些方法都可以帮助您,也许您可以使用sleep(param)方法。像睡眠(5)。等待5秒钟 import XCTest cla
有没有一种方法可以让应用程序执行我的测试用例来打破这一点?我的建议是帮助您使用以下两种方法之一。第一个等待元素出现在屏幕上。第二个元素正在等待命中。但是在任何情况下,这些方法都可以帮助您,也许您可以使用sleep(param)方法。像睡眠(5)。等待5秒钟
import XCTest
class BaseTestCase: XCTestCase {
func waitForElementToAppear(element: XCUIElement, timeout: NSTimeInterval = 60, file: String = #file, line: UInt = #line) {
let existsPredicate = NSPredicate(format: "exists == true")
expectationForPredicate(existsPredicate,
evaluatedWithObject: element, handler: nil)
waitForExpectationsWithTimeout(timeout) { (error) -> Void in
if (error != nil) {
let message = "Failed to find \(element) after \(timeout) seconds."
self.recordFailureWithDescription(message, inFile: file, atLine: line, expected: true)
}
}
}
func waitForHittable(element: XCUIElement, timeout: NSTimeInterval = 70, file: String = #file, line: UInt = #line) {
let existsPredicate = NSPredicate(format: "hittable == 1")
expectationForPredicate(existsPredicate, evaluatedWithObject: element, handler: nil)
waitForExpectationsWithTimeout(timeout) { (error) -> Void in
if (error != nil) {
let message = "Failed to find \(element) after \(timeout) seconds."
self.recordFailureWithDescription(message,
inFile: file, atLine: line, expected: true)
}
}
}
}
我希望在某种程度上有所帮助我在UI测试类中设置了参数
let app = XCUIApplication()
app.launchArguments = ["NoAnimations"]
app.launch()
在我的Appdelegate的didFinishLaunchingWithOptions方法中,我进行了检查
NSArray *args = [NSProcessInfo processInfo].arguments;
for (NSString *arg in args){
if ([arg isEqualToString:@"NoAnimations"]){
[UIView setAnimationsEnabled:false];
}
}
所以现在在我的应用程序中不会有任何动画,我的应用程序也不再被阻止。这将我的自动化时间从25分钟减少到2分钟。感谢您抽出时间帮助我。元素仍然是可命中的并且存在,但是它再次使用相同的“Wait for app to idle”消息等待很长时间。有时我确实会看到这样的消息--“未收到应用程序动画完成通知,将尝试继续”。