From 9e906270d88fd512fda0f540305dae0570fa45e5 Mon Sep 17 00:00:00 2001 From: WindowsMEMZ <45706356+WindowsMEMZ@users.noreply.github.com> Date: Thu, 16 Nov 2023 23:41:20 +0800 Subject: [PATCH] Update DarockBili_Watch_App_UI_Tests.swift --- .../DarockBili_Watch_App_UI_Tests.swift | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/DarockBili Watch App UI Tests/DarockBili_Watch_App_UI_Tests.swift b/DarockBili Watch App UI Tests/DarockBili_Watch_App_UI_Tests.swift index e5167428f..f0c9b3b23 100644 --- a/DarockBili Watch App UI Tests/DarockBili_Watch_App_UI_Tests.swift +++ b/DarockBili Watch App UI Tests/DarockBili_Watch_App_UI_Tests.swift @@ -26,8 +26,11 @@ final class DarockBili_Watch_App_UI_Tests: XCTestCase { // UI tests must launch the application that they test. let app = XCUIApplication() app.launch() + + takeScreenshot(of: app, named: "Launch") - app.tabBars.buttons.element(boundBy: 1).tap() + app.tabBars["MainTabView"].swipeLeft() + sleep(1) app.buttons["AppSettingsButton"].tap() } @@ -40,3 +43,21 @@ final class DarockBili_Watch_App_UI_Tests: XCTestCase { } } } + +extension XCTestCase { + /// Take a screenshot of a given app and add it to the test attachements. + /// - Parameters: + /// - app: The app to take a screenshot of. + /// - name: The name of the screenshot. + func takeScreenshot(of app: XCUIApplication, named name: String) { + let screenshot = app.windows.firstMatch.screenshot() + let attachment = XCTAttachment(screenshot: screenshot) + #if os(iOS) + attachment.name = "Screenshot-\(name)-\(UIDevice.current.name).png" + #else + attachment.name = "Screenshot-\(name)-macOS.png" + #endif + attachment.lifetime = .keepAlways + add(attachment) + } +}