diff --git a/Docs/ProjectSpec.md b/Docs/ProjectSpec.md index 326e17f3c..6c00bdf5a 100644 --- a/Docs/ProjectSpec.md +++ b/Docs/ProjectSpec.md @@ -1063,6 +1063,7 @@ A multiline script can be written using the various YAML multiline methods, for - [ ] **captureScreenshotsAutomatically**: **Bool** - indicates whether screenshots should be captured automatically while UI Testing. This defaults to true. - [ ] **deleteScreenshotsWhenEachTestSucceeds**: **Bool** - whether successful UI tests should cause automatically-captured screenshots to be deleted. If `captureScreenshotsAutomatically` is false, this value is ignored. This defaults to true. - [ ] **testPlans**: **[[Test Plan](#test-plan)]** - List of test plan locations that will be referenced in the scheme. +- [ ] **preferredScreenCaptureFormat**: **String** - automatic screen capture format to use while UI Testing. Possible values are `screenshots`, `screenRecording`. Default is `screenRecording`. #### Test Target A target can be one of a 2 types: diff --git a/Package.resolved b/Package.resolved index 3ae8a3daf..3cd0e4a2c 100644 --- a/Package.resolved +++ b/Package.resolved @@ -86,8 +86,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/tuist/XcodeProj.git", "state" : { - "revision" : "6e60fb55271c80f83a186c9b1b4982fd991cfc0a", - "version" : "8.13.0" + "revision" : "3797181813ee963fe305d939232bc576d23ddbb0", + "version" : "8.15.0" } }, { diff --git a/Package.swift b/Package.swift index 474834940..78ae5ce42 100644 --- a/Package.swift +++ b/Package.swift @@ -16,7 +16,7 @@ let package = Package( .package(url: "https://github.com/yonaskolb/JSONUtilities.git", from: "4.2.0"), .package(url: "https://github.com/kylef/Spectre.git", from: "0.9.2"), .package(url: "https://github.com/onevcat/Rainbow.git", from: "4.0.0"), - .package(url: "https://github.com/tuist/XcodeProj.git", exact: "8.13.0"), + .package(url: "https://github.com/tuist/XcodeProj.git", exact: "8.15.0"), .package(url: "https://github.com/jakeheis/SwiftCLI.git", from: "6.0.3"), .package(url: "https://github.com/mxcl/Version", from: "2.0.0"), .package(url: "https://github.com/SwiftDocOrg/GraphViz.git", exact: "0.2.0"), diff --git a/Sources/ProjectSpec/Scheme.swift b/Sources/ProjectSpec/Scheme.swift index db6aca739..b539c1a3d 100644 --- a/Sources/ProjectSpec/Scheme.swift +++ b/Sources/ProjectSpec/Scheme.swift @@ -201,6 +201,7 @@ public struct Scheme: Equatable { public static let debugEnabledDefault = true public static let captureScreenshotsAutomaticallyDefault = true public static let deleteScreenshotsWhenEachTestSucceedsDefault = true + public static let preferredScreenCaptureFormatDefault = XCScheme.TestAction.ScreenCaptureFormat.screenRecording public var config: String? public var gatherCoverageData: Bool @@ -218,6 +219,7 @@ public struct Scheme: Equatable { public var captureScreenshotsAutomatically: Bool public var deleteScreenshotsWhenEachTestSucceeds: Bool public var testPlans: [TestPlan] + public var preferredScreenCaptureFormat: XCScheme.TestAction.ScreenCaptureFormat public struct TestTarget: Equatable, ExpressibleByStringLiteral { @@ -284,7 +286,8 @@ public struct Scheme: Equatable { debugEnabled: Bool = debugEnabledDefault, customLLDBInit: String? = nil, captureScreenshotsAutomatically: Bool = captureScreenshotsAutomaticallyDefault, - deleteScreenshotsWhenEachTestSucceeds: Bool = deleteScreenshotsWhenEachTestSucceedsDefault + deleteScreenshotsWhenEachTestSucceeds: Bool = deleteScreenshotsWhenEachTestSucceedsDefault, + preferredScreenCaptureFormat: XCScheme.TestAction.ScreenCaptureFormat = preferredScreenCaptureFormatDefault ) { self.config = config self.gatherCoverageData = gatherCoverageData @@ -302,6 +305,7 @@ public struct Scheme: Equatable { self.customLLDBInit = customLLDBInit self.captureScreenshotsAutomatically = captureScreenshotsAutomatically self.deleteScreenshotsWhenEachTestSucceeds = deleteScreenshotsWhenEachTestSucceeds + self.preferredScreenCaptureFormat = preferredScreenCaptureFormat } public var shouldUseLaunchSchemeArgsEnv: Bool { @@ -616,6 +620,7 @@ extension Scheme.Test: JSONObjectConvertible { customLLDBInit = jsonDictionary.json(atKeyPath: "customLLDBInit") captureScreenshotsAutomatically = jsonDictionary.json(atKeyPath: "captureScreenshotsAutomatically") ?? Scheme.Test.captureScreenshotsAutomaticallyDefault deleteScreenshotsWhenEachTestSucceeds = jsonDictionary.json(atKeyPath: "deleteScreenshotsWhenEachTestSucceeds") ?? Scheme.Test.deleteScreenshotsWhenEachTestSucceedsDefault + preferredScreenCaptureFormat = jsonDictionary.json(atKeyPath: "preferredScreenCaptureFormat") ?? Scheme.Test.preferredScreenCaptureFormatDefault } } @@ -658,6 +663,10 @@ extension Scheme.Test: JSONEncodable { dict["deleteScreenshotsWhenEachTestSucceeds"] = deleteScreenshotsWhenEachTestSucceeds } + if preferredScreenCaptureFormat != Scheme.Test.preferredScreenCaptureFormatDefault { + dict["preferredScreenCaptureFormat"] = preferredScreenCaptureFormat.toJSONValue() + } + return dict } } @@ -1009,3 +1018,9 @@ extension XCScheme.LaunchAction.GPUValidationMode: JSONEncodable { } } } + +extension XCScheme.TestAction.ScreenCaptureFormat: JSONEncodable { + public func toJSONValue() -> Any { + rawValue + } +} diff --git a/Sources/XcodeGenKit/SchemeGenerator.swift b/Sources/XcodeGenKit/SchemeGenerator.swift index 1f2a08105..c04474a05 100644 --- a/Sources/XcodeGenKit/SchemeGenerator.swift +++ b/Sources/XcodeGenKit/SchemeGenerator.swift @@ -301,6 +301,7 @@ public class SchemeGenerator { language: scheme.test?.language, region: scheme.test?.region, systemAttachmentLifetime: scheme.test?.systemAttachmentLifetime, + preferredScreenCaptureFormat: scheme.test?.preferredScreenCaptureFormat, customLLDBInitFile: scheme.test?.customLLDBInit ) diff --git a/Tests/XcodeGenKitTests/SchemeGeneratorTests.swift b/Tests/XcodeGenKitTests/SchemeGeneratorTests.swift index b5f392d38..39a56da3a 100644 --- a/Tests/XcodeGenKitTests/SchemeGeneratorTests.swift +++ b/Tests/XcodeGenKitTests/SchemeGeneratorTests.swift @@ -568,6 +568,42 @@ class SchemeGeneratorTests: XCTestCase { .init(reference: "container:\(testPlanPath2)", default: true), ] } + + $0.it("generates scheme with screenshots as preferred screen capture format") { + let scheme = Scheme( + name: "MyScheme", + build: Scheme.Build(targets: [buildTarget]), + run: Scheme.Run(config: "Debug"), + test: Scheme.Test(config: "Debug", preferredScreenCaptureFormat: .screenshots) + ) + let project = Project( + name: "test", + targets: [app, framework], + schemes: [scheme] + ) + let xcodeProject = try project.generateXcodeProject() + + let xcscheme = try unwrap(xcodeProject.sharedData?.schemes.first) + try expect(xcscheme.testAction?.preferredScreenCaptureFormat) == .screenshots + } + + $0.it("generates scheme with screen recording as preferred screen capture format") { + let scheme = Scheme( + name: "MyScheme", + build: Scheme.Build(targets: [buildTarget]), + run: Scheme.Run(config: "Debug"), + test: Scheme.Test(config: "Debug", preferredScreenCaptureFormat: .screenRecording) + ) + let project = Project( + name: "test", + targets: [app, framework], + schemes: [scheme] + ) + let xcodeProject = try project.generateXcodeProject() + + let xcscheme = try unwrap(xcodeProject.sharedData?.schemes.first) + try expect(xcscheme.testAction?.preferredScreenCaptureFormat) == .screenRecording + } } }