【问题标题】:Unable to monitor event loop AND Wait for app to idle无法监控事件循环并等待应用空闲
【发布时间】:2017-03-02 13:24:03
【问题描述】:

我正在使用 XCTest 为我的应用程序编写 UITest 案例。应用程序在主屏幕中进行多次服务器调用。我无法导航到下一个屏幕。自动化通常会保持空闲 1 分钟甚至更长的时间

等待应用空闲

无法监控事件循环

有没有办法让应用程序执行我的测试用例打破这个???

【问题讨论】:

    标签: ios xcode xctest xctestcase


    【解决方案1】:

    我在 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 分钟。

    【讨论】:

      【解决方案2】:

      我的建议是帮助您使用以下这两种方法之一。第一个等待一个元素出现在屏幕上。第二个元素正在等待命中。但无论如何这些方法对你有帮助,也许你可以使用方法 sleep(param)。喜欢sleep(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)
                  }
              }
          }
      }
      

      我希望能在某些方面有所帮助

      【讨论】:

      • 感谢您抽出时间帮助我。该元素仍然是可点击的并且存在,但它再次等待很长时间并显示相同的“等待应用程序空闲”消息。有时我确实会看到此消息 ----“未收到应用动画完成通知,将尝试继续”。
      猜你喜欢
      • 1970-01-01
      • 2020-03-27
      • 1970-01-01
      • 2015-03-13
      • 1970-01-01
      • 1970-01-01
      • 2019-02-05
      • 1970-01-01
      • 2023-01-20
      相关资源
      最近更新 更多