ScreenshotTests.swift (2420B)
1 /* 2 * This file is part of GNU Taler 3 * (C) 2026 Bohdan, Volodymyr Potuzhnyi 4 * 5 * GNU Taler is free software; you can redistribute it and/or modify it under the 6 * terms of the GNU General Public License as published by the Free Software 7 * Foundation; either version 3, or (at your option) any later version. 8 * 9 * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY 10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 * A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License along with 14 * GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 */ 16 17 import XCTest 18 19 final class ScreenshotTests: XCTestCase { 20 21 private static let scenarios = [ 22 "login", 23 "mfa-select", 24 "mfa-code", 25 "amount-entry", 26 "order", 27 "order-custom", 28 "order-custom-added", 29 "payment", 30 "payment-success", 31 "history", 32 "refund", 33 "refund-qr", 34 "navigation", 35 "settings", 36 ] 37 38 private var screenshotLocale: String { 39 ProcessInfo.processInfo.environment["SCREENSHOT_LOCALE"] ?? "en" 40 } 41 42 func testAllScreenshots() { 43 runScenarios(Self.scenarios) 44 } 45 46 func testSelectedScenarios() { 47 let env = ProcessInfo.processInfo.environment["SCREENSHOT_SCENARIOS"] ?? "" 48 let selected = env.split(separator: ",").map(String.init) 49 guard !selected.isEmpty else { 50 XCTFail("SCREENSHOT_SCENARIOS env var is empty") 51 return 52 } 53 runScenarios(selected) 54 } 55 56 private func runScenarios(_ scenarios: [String]) { 57 for scenario in scenarios { 58 let app = XCUIApplication() 59 app.launchArguments = ["-SCREENSHOT_SCENARIO", scenario, 60 "-SCREENSHOT_LOCALE", screenshotLocale] 61 app.launch() 62 63 if UIDevice.current.userInterfaceIdiom == .pad { 64 XCUIDevice.shared.orientation = .landscapeLeft 65 } 66 67 sleep(1) 68 69 let screenshot = XCUIScreen.main.screenshot() 70 let attachment = XCTAttachment(screenshot: screenshot) 71 attachment.name = scenario 72 attachment.lifetime = .keepAlways 73 add(attachment) 74 75 app.terminate() 76 } 77 } 78 }