Merge pull request #1218 from kiwix/1214-iphone-ipad-split-for-ui-tests

1214 iphone ipad split for UI tests
This commit is contained in:
Kelson 2025-05-27 13:49:05 +02:00 committed by GitHub
commit c945186e68
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 156 additions and 47 deletions

View File

@ -75,9 +75,13 @@ jobs:
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Run UI Tests on iOS
- name: Run UI Tests on iPhone
if: matrix.platform == 'iOS'
run: xcodebuild test -scheme UITests_iOS -destination 'platform=iOS Simulator,name=iPhone 16 Pro'
run: xcodebuild test -scheme UITests_iPhone -destination 'platform=iOS Simulator,name=iPhone 16 Pro'
- name: Run UI Tests on iPad
if: matrix.platform == 'iOS'
run: xcodebuild test -scheme UITests_iPad -destination 'platform=iOS Simulator,name=iPad Pro 13-inch (M4)'
- name: Run UI Tests on macOS
if: matrix.platform == 'macOS'

View File

@ -4,5 +4,6 @@ included:
- Views/Settings/
excluded:
- Support/LocalString.swift
- UITests_iOS
- UITests_iPhone
- UITests_iPad
- UITests_macOS

View File

@ -211,7 +211,7 @@ private struct CompactView: View {
presentedSheet = .library(downloads: false)
} label: {
Label(LocalString.common_tab_menu_library, systemImage: "folder")
}
}.accessibilityIdentifier("Library")
Spacer()
}
if !Brand.hideShareButton {

View File

@ -72,6 +72,7 @@ final class SidebarViewController: UICollectionViewController, NSFetchedResultsC
init() {
super.init(collectionViewLayout: UICollectionViewLayout())
collectionView.accessibilityIdentifier = "sidebar_collection_view"
collectionView.collectionViewLayout = UICollectionViewCompositionalLayout { _, layoutEnvironment in
var config = UICollectionLayoutListConfiguration(appearance: .sidebar)
config.headerMode = .supplementary
@ -244,6 +245,7 @@ final class SidebarViewController: UICollectionViewController, NSFetchedResultsC
config.image = UIImage(systemName: item.icon)
config.imageProperties.tintColor = item.iconForegroundColor
cell.contentConfiguration = config
cell.accessibilityIdentifier = item.accessibilityIdentifier
}
}

View File

@ -290,6 +290,27 @@ enum MenuItem: Hashable {
}
}
var accessibilityIdentifier: String {
switch self {
case .tab:
"tab"
case .bookmarks:
"bookmarks"
case .opened:
"opened"
case .categories:
"categories"
case .new:
"new"
case .downloads:
"downloads"
case .settings:
"settings"
case .donation:
"donation"
}
}
var icon: String {
switch self {
case .bookmarks:

View File

@ -1,33 +0,0 @@
// 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 XCTest
final class LoadingUI_iOS_Test: XCTestCase {
@MainActor
func testLaunchingApp_onIPhone() throws {
let app = XCUIApplication()
app.launchArguments = ["ui_testing"]
app.activate()
app/*@START_MENU_TOKEN@*/.buttons["Library"]/*[[".otherElements.buttons[\"Library\"]",".buttons[\"Library\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.tap()
app/*@START_MENU_TOKEN@*/.buttons["New"]/*[[".tabBars",".buttons[\"New\"]",".buttons[\"newspaper\"]"],[[[-1,2],[-1,1],[-1,0,1]],[[-1,2],[-1,1]]],[1]]@END_MENU_TOKEN@*/.tap()
app/*@START_MENU_TOKEN@*/.buttons["Downloads"]/*[[".tabBars",".buttons[\"Downloads\"]",".buttons[\"tray.and.arrow.down\"]"],[[[-1,2],[-1,1],[-1,0,1]],[[-1,2],[-1,1]]],[1]]@END_MENU_TOKEN@*/.tap()
app/*@START_MENU_TOKEN@*/.buttons["Opened"]/*[[".tabBars",".buttons[\"Opened\"]",".buttons[\"folder\"]"],[[[-1,2],[-1,1],[-1,0,1]],[[-1,2],[-1,1]]],[1]]@END_MENU_TOKEN@*/.tap()
app/*@START_MENU_TOKEN@*/.buttons["Categories"]/*[[".tabBars",".buttons[\"Categories\"]",".buttons[\"books.vertical\"]"],[[[-1,2],[-1,1],[-1,0,1]],[[-1,2],[-1,1]]],[1]]@END_MENU_TOKEN@*/.tap()
app/*@START_MENU_TOKEN@*/.buttons["Done"]/*[[".otherElements[\"Done\"].buttons.firstMatch",".otherElements.buttons[\"Done\"]",".buttons[\"Done\"]"],[[[-1,2],[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.tap()
}
}

View File

@ -0,0 +1,45 @@
// 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 XCTest
final class LoadingUI_iPad_Test: XCTestCase {
@MainActor
func testLaunchingApp_on_iPad() throws {
if !XCUIDevice.shared.orientation.isLandscape {
XCUIDevice.shared.orientation = .landscapeLeft
}
let app = XCUIApplication()
app.launchArguments = ["ui_testing"]
app.activate()
app.buttons.matching(identifier: "ToggleSidebar").element.tap()
let sidebar = app.collectionViews["sidebar_collection_view"]
XCTAssert(sidebar.cells["New Tab"].isSelected)
sidebar.cells["bookmarks"].tap()
sidebar.cells["opened"].tap()
sidebar.cells["categories"].tap()
sidebar.cells["downloads"].tap()
sidebar.cells["new"].tap()
sidebar.cells["settings"].tap()
sidebar.cells["donation"].tap()
}
}

View File

@ -0,0 +1,46 @@
// 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 XCTest
final class LoadingUI_iPhone_Test: XCTestCase {
@MainActor
func testLaunchingApp_onIPhone() throws {
if !XCUIDevice.shared.orientation.isPortrait {
XCUIDevice.shared.orientation = .portrait
}
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()
XCTAssertTrue(app.buttons["Categories"].isSelected)
app.buttons["New"].tap()
app.buttons["Downloads"].tap()
app.buttons["Opened"].tap()
app.buttons["Categories"].tap()
app.buttons["Done"].tap()
}
}

View File

@ -20,13 +20,13 @@ 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/*@START_MENU_TOKEN@*/.staticTexts["Bookmarks"]/*[[".cells.staticTexts[\"Bookmarks\"]",".staticTexts[\"Bookmarks\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.click()
let cellsQuery = app.cells
cellsQuery/*@START_MENU_TOKEN@*/.containing(.staticText, identifier: "Opened").firstMatch/*[[".element(boundBy: 3)",".containing(.staticText, identifier: \"Opened\").firstMatch"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.click()
cellsQuery/*@START_MENU_TOKEN@*/.containing(.staticText, identifier: "Categories").firstMatch/*[[".element(boundBy: 4)",".containing(.staticText, identifier: \"Categories\").firstMatch"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.click()
app/*@START_MENU_TOKEN@*/.staticTexts["Downloads"]/*[[".cells.staticTexts[\"Downloads\"]",".staticTexts[\"Downloads\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.click()
cellsQuery/*@START_MENU_TOKEN@*/.containing(.staticText, identifier: "New").firstMatch/*[[".element(boundBy: 6)",".containing(.staticText, identifier: \"New\").firstMatch"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.click()
app.staticTexts["Bookmarks"].click()
app.staticTexts["Opened"].click()
app.staticTexts["Categories"].click()
app.staticTexts["Downloads"].click()
app.staticTexts["New"].click()
}
}

View File

@ -153,7 +153,7 @@ targets:
dependencies:
- target: Kiwix
UITests_iOS:
UITests_iPhone:
type: bundle.ui-testing
supportedDestinations: [iOS]
settings:
@ -163,7 +163,21 @@ targets:
entitlements:
path: Support/Kiwix-unitTest.entitlements
sources:
- path: UITests_iOS
- path: UITests_iPhone
dependencies:
- target: Kiwix
UITests_iPad:
type: bundle.ui-testing
supportedDestinations: [iOS]
settings:
PRODUCT_BUNDLE_IDENTIFIER: org.kiwix.UITests
# TEST_HOST: $(BUILT_PRODUCTS_DIR)/Kiwix.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Kiwix
BUNDLE_LOADER: $(TEST_HOST)
entitlements:
path: Support/Kiwix-unitTest.entitlements
sources:
- path: UITests_iPad
dependencies:
- target: Kiwix
@ -189,12 +203,21 @@ schemes:
- UITests_macOS
commandLineArguments:
testing: true
UITests_iOS:
UITests_iPhone:
build:
targets:
Kiwix: all
test:
targets:
- UITests_iOS
- UITests_iPhone
commandLineArguments:
testing: true
UITests_iPad:
build:
targets:
Kiwix: all
test:
targets:
- UITests_iPad
commandLineArguments:
testing: true