diff --git a/README.md b/README.md index 1ff79d6..17c525f 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ Options available include: | Option | Description | |--------------------------|-----------------------------------------| +| ```--identifier``` | Divide by test target identifier | | ```--model``` | Divide by test target model | | ```--os``` | Divide by test target operating system | | ```--test-plan-config``` | Divide by test run configuration | diff --git a/Sources/xcparse/AttachmentsCommand.swift b/Sources/xcparse/AttachmentsCommand.swift index 05c2f88..ddd04e5 100644 --- a/Sources/xcparse/AttachmentsCommand.swift +++ b/Sources/xcparse/AttachmentsCommand.swift @@ -19,6 +19,7 @@ struct AttachmentsCommand: Command { var outputPath: PositionalArgument var verbose: OptionArgument + var divideByIdentifier: OptionArgument var divideByModel: OptionArgument var divideByOS: OptionArgument var divideByTestRun: OptionArgument @@ -38,6 +39,7 @@ struct AttachmentsCommand: Command { optional: true, usage: "Folder to export results to", completion: .filename) verbose = subparser.add(option: "--verbose", shortName: "-v", kind: Bool.self, usage: "Enable verbose logging") + divideByIdentifier = subparser.add(option: "--identifier", shortName: nil, kind: Bool.self, usage: "Divide attachments by device identifier") divideByModel = subparser.add(option: "--model", shortName: nil, kind: Bool.self, usage: "Divide attachments by model") divideByOS = subparser.add(option: "--os", shortName: nil, kind: Bool.self, usage: "Divide attachments by OS") divideByTestRun = subparser.add(option: "--test-run", shortName: nil, kind: Bool.self, usage: "Deprecated. Use --test-plan-config") @@ -80,6 +82,7 @@ struct AttachmentsCommand: Command { // Let's set up our export options var options = AttachmentExportOptions(addTestScreenshotsDirectory: false, + divideByIdentifier: arguments.get(self.divideByIdentifier) ?? false, divideByTargetModel: arguments.get(self.divideByModel) ?? false, divideByTargetOS: arguments.get(self.divideByOS) ?? false, divideByTestPlanConfig: arguments.get(self.divideByTestPlanConfig) ?? (arguments.get(self.divideByTestRun) ?? false), diff --git a/Sources/xcparse/CommandRegistry.swift b/Sources/xcparse/CommandRegistry.swift index 75d1296..2031283 100644 --- a/Sources/xcparse/CommandRegistry.swift +++ b/Sources/xcparse/CommandRegistry.swift @@ -65,6 +65,7 @@ struct CommandRegistry { let xcresulttoolCompatability = xcpParser.checkXCResultToolCompatability(destination: destination) let options = AttachmentExportOptions(addTestScreenshotsDirectory: true, + divideByIdentifier: false, divideByTargetModel: false, divideByTargetOS: false, divideByTestPlanConfig: false, diff --git a/Sources/xcparse/ScreenshotsCommand.swift b/Sources/xcparse/ScreenshotsCommand.swift index 77af67a..118cfbb 100644 --- a/Sources/xcparse/ScreenshotsCommand.swift +++ b/Sources/xcparse/ScreenshotsCommand.swift @@ -20,6 +20,7 @@ struct ScreenshotsCommand: Command { var verbose: OptionArgument var addTestScreenshotDirectory: OptionArgument + var divideByIdentifier: OptionArgument var divideByModel: OptionArgument var divideByOS: OptionArgument var divideByTestRun: OptionArgument @@ -40,6 +41,7 @@ struct ScreenshotsCommand: Command { verbose = subparser.add(option: "--verbose", shortName: "-v", kind: Bool.self, usage: "Enable verbose logging") addTestScreenshotDirectory = subparser.add(option: "--legacy", shortName: nil, kind: Bool.self, usage: "Create \"testScreenshots\" directory in outputDirectory & put screenshots in there") + divideByIdentifier = subparser.add(option: "--identifier", shortName: nil, kind: Bool.self, usage: "Divide attachments by device identifier") divideByModel = subparser.add(option: "--model", shortName: nil, kind: Bool.self, usage: "Divide screenshots by model") divideByOS = subparser.add(option: "--os", shortName: nil, kind: Bool.self, usage: "Divide screenshots by OS") divideByTestRun = subparser.add(option: "--test-run", shortName: nil, kind: Bool.self, usage: "Deprecated. Use --test-plan-config") @@ -82,6 +84,7 @@ struct ScreenshotsCommand: Command { // Let's set up our export options var options = AttachmentExportOptions(addTestScreenshotsDirectory: arguments.get(self.addTestScreenshotDirectory) ?? false, + divideByIdentifier: arguments.get(self.divideByIdentifier) ?? false, divideByTargetModel: arguments.get(self.divideByModel) ?? false, divideByTargetOS: arguments.get(self.divideByOS) ?? false, divideByTestPlanConfig: arguments.get(self.divideByTestPlanConfig) ?? (arguments.get(self.divideByTestRun) ?? false), diff --git a/Sources/xcparse/XCPParser.swift b/Sources/xcparse/XCPParser.swift index e9d0fc8..cd2f5b6 100644 --- a/Sources/xcparse/XCPParser.swift +++ b/Sources/xcparse/XCPParser.swift @@ -21,6 +21,7 @@ struct XCResultToolCompatability { struct AttachmentExportOptions { var addTestScreenshotsDirectory: Bool = false + var divideByIdentifier: Bool = false var divideByTargetModel: Bool = false var divideByTargetOS: Bool = false var divideByTestPlanConfig: Bool = false @@ -58,7 +59,9 @@ struct AttachmentExportOptions { modelName = "iPhone XR" } - if self.divideByTargetModel == true, self.divideByTargetOS == true { + if self.divideByIdentifier { + targetDeviceFolderName = deviceRecord.identifier + } else if self.divideByTargetModel == true, self.divideByTargetOS == true { targetDeviceFolderName = modelName + " (\(deviceRecord.operatingSystemVersion))" } else if self.divideByTargetModel { targetDeviceFolderName = modelName diff --git a/Tests/xcparseTests/xcparseTests.swift b/Tests/xcparseTests/xcparseTests.swift index 88aeefb..d05a200 100644 --- a/Tests/xcparseTests/xcparseTests.swift +++ b/Tests/xcparseTests/xcparseTests.swift @@ -35,6 +35,7 @@ final class xcparseTests: XCTestCase { static var allTests = [ ("testScreenshots", testScreenshots), ("testDivideByTestPlanConfig",testDivideByTestPlanConfig), + ("testDivideByIdentifier",testDivideByIdentifier), ("testDivideByOS",testDivideByOS), ("testDivideByModel",testDivideByModel), ("testDivideByLanguage",testDivideByLanguage), @@ -256,6 +257,27 @@ final class xcparseTests: XCTestCase { } + func testDivideByIdentifier() throws { + // Some of the APIs that we use below are available in macOS 10.13 and above. + guard #available(macOS 10.13, *) else { + return + } + + let file = try Resource(name: "testSuccess", type: "xcresult") + xcparseProcess.arguments = ["screenshots","--identifier",file.url.path,temporaryOutputDirectoryURL.path] + + try runAndWaitForXCParseProcess() + + // check for the files. The device identifier in xcresult is BFB8C9E3-0E55-4E20-B332-091631DF4F90 for simulator + // so we append "BFB8C9E3-0E55-4E20-B332-091631DF4F90" to temporary directory + + let fileUrls = FileManager.default.listFiles(path: temporaryOutputDirectoryURL.appendingPathComponent("BFB8C9E3-0E55-4E20-B332-091631DF4F90").path) + + XCTAssertTrue(fileUrls.count == 6) + XCTAssertTrue(fileUrls.filter{$0.path.contains("MyAutomation_darkMapView")}.count == 3) + XCTAssertTrue(fileUrls.filter{$0.path.contains("MyAutomation_todayWidget")}.count == 3) + } + func testDivideByOS() throws { // Some of the APIs that we use below are available in macOS 10.13 and above. guard #available(macOS 10.13, *) else {