diff --git a/UITests_common/Wait.swift b/UITests_common/Wait.swift new file mode 100644 index 00000000..c22b2c8f --- /dev/null +++ b/UITests_common/Wait.swift @@ -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 + } + } +} diff --git a/UITests_iPad/LoadingUI_iPad_Test.swift b/UITests_iPad/LoadingUI_iPad_Test.swift index 55008cb5..75b93174 100644 --- a/UITests_iPad/LoadingUI_iPad_Test.swift +++ b/UITests_iPad/LoadingUI_iPad_Test.swift @@ -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() diff --git a/UITests_iPhone/LoadingUI_iPhone_Test.swift b/UITests_iPhone/LoadingUI_iPhone_Test.swift index a78d7c85..0538f0f6 100644 --- a/UITests_iPhone/LoadingUI_iPhone_Test.swift +++ b/UITests_iPhone/LoadingUI_iPhone_Test.swift @@ -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) } } diff --git a/UITests_macOS/LoadingUI_macOS_Test.swift b/UITests_macOS/LoadingUI_macOS_Test.swift index d6e56f05..4e6b9eee 100644 --- a/UITests_macOS/LoadingUI_macOS_Test.swift +++ b/UITests_macOS/LoadingUI_macOS_Test.swift @@ -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()