Wait for page to load completely and content become visible. XCUI Appliction

45 Views Asked by At
for i in 1......1000{
    sleep(5)
    makeScreenshot(name:  "Page-\(i)")
    app.swipeLeft()
}

Instead of sleep I want to implement dynamic wait that waits for page to load completely and content on each page becomes visible before taking screenshot.

I tried using XCUIApplication().waitForExcistence(timeout: 10) but it didn't work as expected it took screenshot before content become visible for some pages.

I also tried this Function from ChatGpt, but it didn't work as expected it took screenshot before content become visible for some pages.

func waitForAppQuiescence(timeout: TimeInterval) { 
    let quiescenceExpectation = XCTNSPredicateExpectation(predicate: NSPredicate(format: "exists ==                              true"), object: XCUIApplication()) 
    let result XCTWaiter().wait(for: [quiescenceExpectation], timeout: timeout) 
    if result =  .completed { 
        print("Timed out waiting for the app to become quiescent")
    }
}
0

There are 0 best solutions below