Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support preferred screen capture format in scheme test action #1450

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Docs/ProjectSpec.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
17 changes: 16 additions & 1 deletion Sources/ProjectSpec/Scheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {

Expand Down Expand Up @@ -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
Expand All @@ -302,6 +305,7 @@ public struct Scheme: Equatable {
self.customLLDBInit = customLLDBInit
self.captureScreenshotsAutomatically = captureScreenshotsAutomatically
self.deleteScreenshotsWhenEachTestSucceeds = deleteScreenshotsWhenEachTestSucceeds
self.preferredScreenCaptureFormat = preferredScreenCaptureFormat
}

public var shouldUseLaunchSchemeArgsEnv: Bool {
Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -658,6 +663,10 @@ extension Scheme.Test: JSONEncodable {
dict["deleteScreenshotsWhenEachTestSucceeds"] = deleteScreenshotsWhenEachTestSucceeds
}

if preferredScreenCaptureFormat != Scheme.Test.preferredScreenCaptureFormatDefault {
dict["preferredScreenCaptureFormat"] = preferredScreenCaptureFormat.toJSONValue()
}

return dict
}
}
Expand Down Expand Up @@ -1009,3 +1018,9 @@ extension XCScheme.LaunchAction.GPUValidationMode: JSONEncodable {
}
}
}

extension XCScheme.TestAction.ScreenCaptureFormat: JSONEncodable {
public func toJSONValue() -> Any {
rawValue
}
}
1 change: 1 addition & 0 deletions Sources/XcodeGenKit/SchemeGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
36 changes: 36 additions & 0 deletions Tests/XcodeGenKitTests/SchemeGeneratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

Expand Down