From dfe454dd55acd57ce0a7e791d252d70c163ed0d5 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Mon, 18 Mar 2024 22:20:19 +0100 Subject: [PATCH 1/2] feat: Make native screen recording and screenshots configurable --- README.md | 16 ++++++++++++++++ .../Utilities/FBConfiguration.h | 3 +++ .../Utilities/FBConfiguration.m | 12 ++++++++++++ .../WebDriverAgentRunner/WebDriverAgentRunner.m | 6 +++++- 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e6bbbde..a76c880 100644 --- a/README.md +++ b/README.md @@ -767,6 +767,22 @@ def test_sending_custom_keys(driver): Parallel execution of multiple Mac2 driver instances is highly discouraged. Only one UI test must be running at the same time, since the access to accessibility layer is single-threaded. Also HID devices, like the mouse or the keyboard, must be acquired exclusively. +## Environment Variables + +The server part of the driver recognizes the following environment variables: + +- `ENABLE_AUTOMATIC_SCREENSHOTS`: enables automatic XCTest screenshots. + These screenshots are stored in the same folder where WDA test logs are located and are taken automatically. + This feature is disabled by default. Only enable it if you know what you are doing otherwise these + screenshots may quickly fill up the free disk space. +- `ENABLE_AUTOMATIC_SCREEN_RECORDINGS`: enables automatic XCTest screen recordings. + These screen recordings are stored in the same folder where WDA test logs are located and are taken automatically. This feature is disabled by default. + Only enable it if you know what you are doing otherwise these videos may quickly fill up the free disk space. + The native screen recording feature only works on Xcode 15+. +- `USE_PORT`. If enabled then the server listens on the given port. Otherwise, a random free port from the + 10100..10200 range is selected. By default, the port is selected by the driver (see the `appium:systemPort` + capability description). +- `VERBOSE_LOGGING`. If enabled then server logs should include various verbose details. Disabled by default. ## Development & Testing diff --git a/WebDriverAgentMac/WebDriverAgentLib/Utilities/FBConfiguration.h b/WebDriverAgentMac/WebDriverAgentLib/Utilities/FBConfiguration.h index c170284..8ff2db4 100644 --- a/WebDriverAgentMac/WebDriverAgentLib/Utilities/FBConfiguration.h +++ b/WebDriverAgentMac/WebDriverAgentLib/Utilities/FBConfiguration.h @@ -27,6 +27,9 @@ NS_ASSUME_NONNULL_BEGIN /*! Enables XCTest automated screenshots taking */ @property BOOL automaticScreenshots; +/*! Enables XCTest automated screen recordings taking in Xcode 15+ */ +@property BOOL automaticScreenRecordings; + /** The range of ports that the HTTP Server should attempt to bind on launch */ diff --git a/WebDriverAgentMac/WebDriverAgentLib/Utilities/FBConfiguration.m b/WebDriverAgentMac/WebDriverAgentLib/Utilities/FBConfiguration.m index 703c388..5265061 100644 --- a/WebDriverAgentMac/WebDriverAgentLib/Utilities/FBConfiguration.m +++ b/WebDriverAgentMac/WebDriverAgentLib/Utilities/FBConfiguration.m @@ -63,6 +63,18 @@ - (void)setAutomaticScreenshots:(BOOL)automaticScreenshots forKey:@"DisableScreenshots"]; } +- (BOOL)automaticScreenRecordings +{ + id value = [NSUserDefaults.standardUserDefaults objectForKey:@"DisableDiagnosticScreenRecordings"]; + return nil == value ? YES : ![value boolValue]; +} + +- (void)setAutomaticScreenRecordings:(BOOL)automaticScreenRecordings +{ + [[NSUserDefaults standardUserDefaults] setBool:!automaticScreenRecordings + forKey:@"DisableDiagnosticScreenRecordings"]; +} + - (NSRange)bindingPortRange { // 'WebDriverAgent --port 8080' can be passed via the arguments to the process diff --git a/WebDriverAgentMac/WebDriverAgentRunner/WebDriverAgentRunner.m b/WebDriverAgentMac/WebDriverAgentRunner/WebDriverAgentRunner.m index 943cd46..5288c3d 100644 --- a/WebDriverAgentMac/WebDriverAgentRunner/WebDriverAgentRunner.m +++ b/WebDriverAgentMac/WebDriverAgentRunner/WebDriverAgentRunner.m @@ -26,7 +26,11 @@ @implementation UITestingUITests + (void)setUp { FBConfiguration.sharedConfiguration.attributeKeyPathAnalysis = NO; - FBConfiguration.sharedConfiguration.automaticScreenshots = NO; + + FBConfiguration.sharedConfiguration.automaticScreenshots = + [NSProcessInfo.processInfo.environment[@"ENABLE_AUTOMATIC_SCREENSHOTS"] boolValue]; + FBConfiguration.sharedConfiguration.automaticScreenRecordings = + [NSProcessInfo.processInfo.environment[@"ENABLE_AUTOMATIC_SCREEN_RECORDINGS"] boolValue]; [super setUp]; } From d51c1423df3c81b3b01cf5a2bc23d94fac6f804a Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Mon, 18 Mar 2024 22:23:23 +0100 Subject: [PATCH 2/2] extra line --- WebDriverAgentMac/WebDriverAgentRunner/WebDriverAgentRunner.m | 1 - 1 file changed, 1 deletion(-) diff --git a/WebDriverAgentMac/WebDriverAgentRunner/WebDriverAgentRunner.m b/WebDriverAgentMac/WebDriverAgentRunner/WebDriverAgentRunner.m index 5288c3d..05d7406 100644 --- a/WebDriverAgentMac/WebDriverAgentRunner/WebDriverAgentRunner.m +++ b/WebDriverAgentMac/WebDriverAgentRunner/WebDriverAgentRunner.m @@ -26,7 +26,6 @@ @implementation UITestingUITests + (void)setUp { FBConfiguration.sharedConfiguration.attributeKeyPathAnalysis = NO; - FBConfiguration.sharedConfiguration.automaticScreenshots = [NSProcessInfo.processInfo.environment[@"ENABLE_AUTOMATIC_SCREENSHOTS"] boolValue]; FBConfiguration.sharedConfiguration.automaticScreenRecordings =