// // XCUIElement+Extensions.swift // MullvadVPNUITests // // Created by Niklas Berglund on 2024-03-25. // Copyright © 2025 Mullvad VPN AB. All rights reserved. // import XCTest extension XCUIElement { func waitForNonExistence(timeout: TimeInterval) -> Bool { let predicate = NSPredicate(format: "exists == FALSE") let expectation = XCTNSPredicateExpectation(predicate: predicate, object: self) _ = XCTWaiter().wait(for: [expectation], timeout: timeout) return !exists } func scrollDownToElement(element: XCUIElement, maxScrolls: UInt = 5) { var count = 0 while !element.isVisible && count < maxScrolls { swipeUp(velocity: .slow) count += 1 } } func scrollUpToElement(element: XCUIElement, maxScrolls: UInt = 5) { var count = 0 while !element.isVisible && count < maxScrolls { swipeDown(velocity: .slow) count += 1 } } var isVisible: Bool { guard self.exists && !self.frame.isEmpty else { return false } return XCUIApplication().windows.element(boundBy: 0).frame.contains(self.frame) } }