Skip to content

Commit

Permalink
Delete videos of passed tests, add flag to retain (#502)
Browse files Browse the repository at this point in the history
  • Loading branch information
RainNapper authored Jul 12, 2021
1 parent 63a6c10 commit 8295908
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ A full list supported options are listed here.
| runner-app-path | -u | The test runner for UI tests. | N | n/a |
| screenshots-directory | n/a | Directory where simulator screenshots for failed ui tests will be stored. | N | n/a |
| videos-directory | n/a | Directory where videos of test runs will be saved. If not provided, videos are not recorded. | N | n/a |
| keep-passing-videos | n/a | Whether to keep the recorded video for passing tests. Deleted by default. | N | false |
| video-paths | -V | A list of videos that will be saved in the simulators. | N | n/a |
| image-paths | -I | A list of images that will be saved in the simulators. | N | n/a |
| unsafe-skip-xcode-version-check | | Skip Xcode version check | N | NO |
Expand Down
1 change: 1 addition & 0 deletions bluepill/tests/BPIntegrationTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ - (BPConfiguration *)generateConfigWithVideoDir:(NSString *)videoDir {
config.quiet = [BPUtils isBuildScript];
if (videoDir != nil) {
config.videosDirectory = videoDir;
config.keepPassingVideos = true;
}
return config;
}
Expand Down
1 change: 1 addition & 0 deletions bp/src/BPConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ typedef NS_ENUM(NSInteger, BPProgram) {
@property (nonatomic, strong) NSString *testTimeEstimatesJsonFile;
@property (nonatomic, strong) NSString *screenshotsDirectory;
@property (nonatomic, strong) NSString *videosDirectory;
@property (nonatomic) BOOL keepPassingVideos;
@property (nonatomic, strong) NSString *simulatorPreferencesFile;
@property (nonatomic, strong) NSString *scriptFilePath;
@property (nonatomic) BOOL headlessMode;
Expand Down
2 changes: 2 additions & 0 deletions bp/src/BPConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ typedef NS_OPTIONS(NSUInteger, BPOptionType) {
"Retry the tests after an app crash and if it passes on retry, consider them non-fatal."},
{367, "videos-directory", BLUEPILL_BINARY | BP_BINARY, NO, NO, required_argument, NULL, BP_VALUE | BP_PATH, "videosDirectory",
"Directory where videos of test runs will be saved. If not provided, videos are not recorded."},
{368, "keep-passing-videos", BLUEPILL_BINARY | BP_BINARY, NO, NO, no_argument, "Off", BP_VALUE | BP_BOOL, "keepPassingVideos",
"Whether recorded videos should be kept if the test passed. They are deleted by default."},
{0, 0, 0, 0, 0, 0, 0}
};

Expand Down
10 changes: 9 additions & 1 deletion bp/src/BPTMDRunnerConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ @interface BPTMDRunnerConnection()<XCTMessagingChannel_DaemonToIDE, XCTMessaging
@property (nonatomic, strong) NSString *bundleID;
@property (nonatomic, assign) pid_t appProcessPID;
@property (nonatomic, nullable) NSTask *recordVideoTask;
//@property (nonatomic, nullable) NSPipe *recordVideoPipe;
@property (nonatomic, nullable) NSString *videoFileName;


@end
Expand Down Expand Up @@ -168,6 +168,7 @@ - (void)startVideoRecordingForTestClass:(NSString *)testClass method:(NSString *
NSString *command = [NSString stringWithFormat:@"xcrun simctl io %@ recordVideo --force %@", [self.simulator UDID], videoFileName];
NSTask *task = [BPUtils buildShellTaskForCommand:command];
self.recordVideoTask = task;
self.videoFileName = videoFileName;
[task launch];
[BPUtils printInfo:INFO withString:@"Started recording video to %@", videoFileName];
[BPUtils printInfo:DEBUGINFO withString:@"Started recording video task with pid %d and command: %@", [task processIdentifier], [BPUtils getCommandStringForTask:task]];
Expand Down Expand Up @@ -308,6 +309,13 @@ - (id)_XCT_testCaseDidFinishForTestClass:(NSString *)testClass method:(NSString
[BPUtils printInfo:DEBUGINFO withString: @"BPTestBundleConnection_XCT_testCaseDidFinishForTestClass: %@, method: %@, withStatus: %@, duration: %@", testClass, method, statusString, duration];
if ([self shouldRecordVideo]) {
[self stopVideoRecording:NO];
if ([statusString isEqual: @"passed"] && ![self.context.config keepPassingVideos]) {
NSError *deleteError = nil;
BOOL success = [NSFileManager.defaultManager removeItemAtPath:self.videoFileName error:&deleteError];
if (deleteError != nil || !success) {
[BPUtils printInfo:WARNING withString:@"Failed to delete video of successful run at path %@", self.videoFileName];
}
}
}
return nil;
}
Expand Down

0 comments on commit 8295908

Please sign in to comment.