Skip to content

Commit

Permalink
Merge pull request #27 from Darock-Studio/dev/test-screenshot
Browse files Browse the repository at this point in the history
Make UI Test Screenshots Ready to View in CI
  • Loading branch information
WindowsMEMZ authored Dec 11, 2023
2 parents df231eb + 171ef0d commit c19b7a0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/status-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:

- name: Build DarockBili App
run: |
xcodebuild -scheme 'DarockBili Watch App' -configuration Release build CODE_SIGN_IDENTITY=""
xcodebuild -scheme 'DarockBili Watch App' -configuration Release build CODE_SIGN_IDENTITY="" -quiet
echo "FIN_STATUS=success" >> $GITHUB_ENV
- name: Update Check Status
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ui-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:

- name: Run DarockBili Watch App UI Test
run: |
xcodebuild test -scheme 'DarockBili Watch App' -configuration Release -destination 'platform=watchOS Simulator,name=Apple Watch Series 7 (41mm),OS=10.0' -destination 'platform=watchOS Simulator,name=Apple Watch Series 9 (45mm),OS=10.0' -testPlan WatchAppUITestPlan -testProductsPath ./Caches/TestProducts.xctestproducts -derivedDataPath ./Caches/DerivedData
xcodebuild test -scheme 'DarockBili Watch App' -configuration Release -destination 'platform=watchOS Simulator,name=Apple Watch Series 7 (41mm),OS=10.0' -testPlan WatchAppUITestPlan -testProductsPath ./Caches/TestProducts.xctestproducts -derivedDataPath ./Caches/DerivedData
echo "FIN_STATUS=success" >> $GITHUB_ENV
- name: Process Test Result
Expand All @@ -72,5 +72,5 @@ jobs:
/repos/${{ github.repository }}/statuses/$GITHUB_SHA \
-f state='${{ env.FIN_STATUS }}' \
-f target_url='https://github.com/Darock-Studio/Darock-Bili/actions/runs/${{ github.run_id }}' \
-f context='Unit Test'
-f context='UI Test'
14 changes: 11 additions & 3 deletions DarockBili Watch App UI Tests/DarockBili_Watch_App_UI_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,19 @@ final class DarockBili_Watch_App_UI_Tests: XCTestCase {
app.launch()
sleep(2)
takeScreenshot(of: app, named: "Launch")
// In main tabview first page (suggestions)
app.buttons["SuggestVideo"].firstMatch.tap()
sleep(1)
takeScreenshot(of: app, named: "RMVideo")
app.swipeUp()
sleep(1)
takeScreenshot(of: app, named: "RMVideoP2")
app.swipeLeft()
sleep(5)
takeScreenshot(of: app, named: "RMVideoComments")
app.navigationBars.buttons.element(boundBy: 0).tap()
sleep(1)
// Backed to suggestions view
app.otherElements["MainTabView"].swipeLeft()
sleep(1)
takeScreenshot(of: app, named: "PersonalCenter")
Expand All @@ -60,18 +65,20 @@ final class DarockBili_Watch_App_UI_Tests: XCTestCase {
takeScreenshot(of: app, named: "NetworkFix1")
sleep(5)
takeScreenshot(of: app, named: "NetworkFix2")

}

func testLaunchPerformance() throws {
if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 7.0, *) {
// This measures how long it takes to launch your application.
measure(metrics: [XCTApplicationLaunchMetric()]) {
XCUIApplication().launch()
}
}
}
}

var screenshotCount = 1

extension XCTestCase {
/// Take a screenshot of a given app and add it to the test attachements.
/// - Parameters:
Expand All @@ -81,12 +88,13 @@ extension XCTestCase {
let screenshot = app.windows.firstMatch.screenshot()
let attachment = XCTAttachment(screenshot: screenshot)
#if os(iOS)
let name = "Screenshot-\(name)-\(UIDevice.current.name).png"
let name = "Screenshot-\(screenshotCount)-\(name)-\(UIDevice.current.name).png"
#else
let name = "Screenshot-\(name)-watchOS.png"
let name = "Screenshot-\(screenshotCount)-\(name)-watchOS.png"
#endif
attachment.name = name
attachment.lifetime = .keepAlways
add(attachment)
screenshotCount += 1
}
}

0 comments on commit c19b7a0

Please sign in to comment.