Skip to content

Commit

Permalink
Add screenshot tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tattn committed Oct 18, 2023
1 parent 7e06059 commit e5731c9
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 41 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ jobs:

test-ui-preview:
runs-on: macOS-13
permissions:
checks: write

steps:
- uses: actions/checkout@main
Expand All @@ -40,8 +38,9 @@ jobs:

- name: Archive xcresult
uses: actions/upload-artifact@v3
if: success() || failure()
with:
name: xcresults-uitest
name: xcresult-uitest
path: /tmp/*.xcresult
if-no-files-found: error

8 changes: 4 additions & 4 deletions app/xcode/App/VCam.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
061238782ADE9CEE00B67618 /* VCam in Frameworks */ = {isa = PBXBuildFile; productRef = 061238772ADE9CEE00B67618 /* VCam */; };
06EC61182ADEE7A900D2A5C9 /* VCamStub in Frameworks */ = {isa = PBXBuildFile; productRef = 06EC61172ADEE7A900D2A5C9 /* VCamStub */; };
06EC61202AE016C300D2A5C9 /* VCamUIPreviewUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06EC611F2AE016C300D2A5C9 /* VCamUIPreviewUITests.swift */; };
06EC61222AE016C300D2A5C9 /* VCamUIPreviewUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06EC61212AE016C300D2A5C9 /* VCamUIPreviewUITestsLaunchTests.swift */; };
06EC61222AE016C300D2A5C9 /* LaunchScreenshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06EC61212AE016C300D2A5C9 /* LaunchScreenshotTests.swift */; };
06EC61292AE0296600D2A5C9 /* VCamLocalization in Frameworks */ = {isa = PBXBuildFile; productRef = 06EC61282AE0296600D2A5C9 /* VCamLocalization */; };
/* End PBXBuildFile section */

Expand All @@ -39,7 +39,7 @@
061238742ADE9C6D00B67618 /* xcode */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = xcode; path = ..; sourceTree = "<group>"; };
06EC611D2AE016C300D2A5C9 /* VCamUIPreviewUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = VCamUIPreviewUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
06EC611F2AE016C300D2A5C9 /* VCamUIPreviewUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VCamUIPreviewUITests.swift; sourceTree = "<group>"; };
06EC61212AE016C300D2A5C9 /* VCamUIPreviewUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VCamUIPreviewUITestsLaunchTests.swift; sourceTree = "<group>"; };
06EC61212AE016C300D2A5C9 /* LaunchScreenshotTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LaunchScreenshotTests.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -114,7 +114,7 @@
isa = PBXGroup;
children = (
06EC611F2AE016C300D2A5C9 /* VCamUIPreviewUITests.swift */,
06EC61212AE016C300D2A5C9 /* VCamUIPreviewUITestsLaunchTests.swift */,
06EC61212AE016C300D2A5C9 /* LaunchScreenshotTests.swift */,
);
path = VCamUIPreviewUITests;
sourceTree = "<group>";
Expand Down Expand Up @@ -236,7 +236,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
06EC61222AE016C300D2A5C9 /* VCamUIPreviewUITestsLaunchTests.swift in Sources */,
06EC61222AE016C300D2A5C9 /* LaunchScreenshotTests.swift in Sources */,
06EC61202AE016C300D2A5C9 /* VCamUIPreviewUITests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
51 changes: 51 additions & 0 deletions app/xcode/App/VCamUIPreviewUITests/LaunchScreenshotTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// LaunchScreenshotTests.swift
// VCamUIPreviewUITests
//
// Created by Tatsuya Tanaka on 2023/10/18.
//

import XCTest
import VCamLocalization

final class LaunchScreenshotTests: XCTestCase {

override class var runsForEachTargetApplicationUIConfiguration: Bool {
true
}

override func setUpWithError() throws {
continueAfterFailure = false
LocalizationEnvironment.currentLocale = { "en_US" }
}

func testLaunch() throws {
let app = XCUIApplication()
app.launch()

XCTContext.runActivity(named: "Launch Screen") { activity in
add(.keepAlways(screenshot: app.screenshot(), activity: activity))
}

XCTContext.runActivity(named: "\(L10n.recording.text) Screen") { activity in
app.buttons[L10n.recording.text].click()
_ = app.staticTexts[L10n.whiteBalance.text].waitForExistence(timeout: 5)
add(.keepAlways(screenshot: app.screenshot(), activity: activity))
}

XCTContext.runActivity(named: "\(L10n.screenEffect.text) Screen") { activity in
app.buttons[L10n.screenEffect.text].click()
_ = app.staticTexts[L10n.startRecording.text].waitForExistence(timeout: 5)
add(.keepAlways(screenshot: app.screenshot(), activity: activity))
}
}
}

private extension XCTAttachment {
static func keepAlways(screenshot: XCUIScreenshot, activity: XCTActivity) -> XCTAttachment {
let attachment = XCTAttachment(screenshot: screenshot)
attachment.name = activity.name
attachment.lifetime = .keepAlways
return attachment
}
}
9 changes: 4 additions & 5 deletions app/xcode/App/VCamUIPreviewUITests/VCamUIPreviewUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ final class VCamUIPreviewUITests: XCTestCase {
let app = XCUIApplication()
app.launch()

XCTContext.runActivity(named: "Close the alert about the virtual camera if needed") { _ in
if app.staticTexts[L10n.installVirtualCamera.text].exists {
app.buttons["OK"].click()
app.buttons["OK"].click()
}
// Close the alert about the virtual camera if needed"
if app.staticTexts[L10n.installVirtualCamera.text].exists {
app.buttons["OK"].click()
app.buttons["OK"].click()
}

XCTContext.runActivity(named: "Check VCamUI") { _ in
Expand Down

This file was deleted.

0 comments on commit e5731c9

Please sign in to comment.