Update tests with waiting

This commit is contained in:
Balazs Perlaki-Horvath 2025-05-31 11:46:45 +02:00
parent e8afa3ea88
commit 6c2ba7a295
4 changed files with 44 additions and 11 deletions

37
UITests_common/Wait.swift Normal file
View File

@ -0,0 +1,37 @@
// This file is part of Kiwix for iOS & macOS.
//
// Kiwix is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// any later version.
//
// Kiwix is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Kiwix; If not, see https://www.gnu.org/licenses/.
import Foundation
import XCTest
struct Wait {
private static let sec30: TimeInterval = 30
private static func actionFor(_ element: XCUIElement) -> String {
"waiting for: \(element)"
}
@discardableResult
static func inApp(
_ app: XCUIApplication,
forElement element: XCUIElement,
timeout: TimeInterval = sec30
) -> XCUIApplication {
XCTContext.runActivity(named: Self.actionFor(element)) { activity in
XCTAssertTrue(element.waitForExistence(timeout: timeout), activity.name)
return app
}
}
}

View File

@ -25,7 +25,6 @@ final class LoadingUI_iPad_Test: XCTestCase {
}
let app = XCUIApplication()
app.launchArguments = ["ui_testing"]
app.activate()
app.buttons.matching(identifier: "ToggleSidebar").element.tap()

View File

@ -24,16 +24,8 @@ final class LoadingUI_iPhone_Test: XCTestCase {
}
let app = XCUIApplication()
app.launchArguments = ["ui_testing"]
app.activate()
XCTAssertFalse(app.buttons["Go Back"].isEnabled)
XCTAssertFalse(app.buttons["Go Forward"].isEnabled)
XCTAssertFalse(app.buttons["Share"].isEnabled)
XCTAssertFalse(app.buttons["List"].isEnabled)
XCTAssertFalse(app.buttons["Random Page"].isEnabled)
app.buttons["Library"].tap()
Wait.inApp(app, forElement: app.buttons["Categories"])
XCTAssertTrue(app.buttons["Categories"].isSelected)
@ -42,5 +34,11 @@ final class LoadingUI_iPhone_Test: XCTestCase {
app.buttons["Opened"].tap()
app.buttons["Categories"].tap()
app.buttons["Done"].tap()
XCTAssertFalse(app.buttons["Go Back"].isEnabled)
XCTAssertFalse(app.buttons["Go Forward"].isEnabled)
XCTAssertFalse(app.buttons["Share"].isEnabled)
XCTAssertFalse(app.buttons["List"].isEnabled)
XCTAssertFalse(app.buttons["Random Page"].isEnabled)
}
}

View File

@ -20,7 +20,6 @@ final class LoadingUI_macOS_Test: XCTestCase {
func testSideBarItems() throws {
// UI tests must launch the application that they test.
let app = XCUIApplication()
app.launchArguments = ["ui_testing"]
app.activate()
app.staticTexts["Bookmarks"].click()