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

Added an option to divide by device identifier #83

Open
wants to merge 2 commits 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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
3 changes: 3 additions & 0 deletions Sources/xcparse/AttachmentsCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct AttachmentsCommand: Command {
var outputPath: PositionalArgument<PathArgument>
var verbose: OptionArgument<Bool>

var divideByIdentifier: OptionArgument<Bool>
var divideByModel: OptionArgument<Bool>
var divideByOS: OptionArgument<Bool>
var divideByTestRun: OptionArgument<Bool>
Expand All @@ -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")
Expand Down Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions Sources/xcparse/CommandRegistry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions Sources/xcparse/ScreenshotsCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct ScreenshotsCommand: Command {
var verbose: OptionArgument<Bool>

var addTestScreenshotDirectory: OptionArgument<Bool>
var divideByIdentifier: OptionArgument<Bool>
var divideByModel: OptionArgument<Bool>
var divideByOS: OptionArgument<Bool>
var divideByTestRun: OptionArgument<Bool>
Expand All @@ -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")
Expand Down Expand Up @@ -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),
Expand Down
5 changes: 4 additions & 1 deletion Sources/xcparse/XCPParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions Tests/xcparseTests/xcparseTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ final class xcparseTests: XCTestCase {
static var allTests = [
("testScreenshots", testScreenshots),
("testDivideByTestPlanConfig",testDivideByTestPlanConfig),
("testDivideByIdentifier",testDivideByIdentifier),
("testDivideByOS",testDivideByOS),
("testDivideByModel",testDivideByModel),
("testDivideByLanguage",testDivideByLanguage),
Expand Down Expand Up @@ -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 {
Expand Down