Skip to content

Commit 8d70ef1

Browse files
committed
Revert e3134db
1 parent e7f60db commit 8d70ef1

File tree

3 files changed

+15
-35
lines changed

3 files changed

+15
-35
lines changed

PrivateHeaders/XCTest/XCUIScreen.h

Lines changed: 0 additions & 25 deletions
This file was deleted.

WebDriverAgent.xcodeproj/project.pbxproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,6 @@
724724
EEC088E71CB56DA400B65968 /* FBExceptionHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FBExceptionHandler.m; sourceTree = "<group>"; };
725725
EEC088EA1CB5706D00B65968 /* FBSpringboardApplication.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FBSpringboardApplication.h; path = WebDriverAgentLib/FBSpringboardApplication.h; sourceTree = SOURCE_ROOT; };
726726
EEC088EB1CB5706D00B65968 /* FBSpringboardApplication.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FBSpringboardApplication.m; path = WebDriverAgentLib/FBSpringboardApplication.m; sourceTree = SOURCE_ROOT; };
727-
EED404361FCF02AB00D08020 /* XCUIScreen.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XCUIScreen.h; sourceTree = "<group>"; };
728727
EEDBEBBA1CB2681900A790A2 /* WebDriverAgent.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = WebDriverAgent.bundle; sourceTree = "<group>"; };
729728
EEDFE11F1D9C06F800E6FFE5 /* XCUIDevice+FBHealthCheck.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "XCUIDevice+FBHealthCheck.h"; sourceTree = "<group>"; };
730729
EEDFE1201D9C06F800E6FFE5 /* XCUIDevice+FBHealthCheck.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "XCUIDevice+FBHealthCheck.m"; sourceTree = "<group>"; };
@@ -1322,7 +1321,6 @@
13221321
EE35AD051E3B77D600A02D78 /* XCUIRecorderNodeFinderMatch.h */,
13231322
EE35AD061E3B77D600A02D78 /* XCUIRecorderTimingMessage.h */,
13241323
EE35AD071E3B77D600A02D78 /* XCUIRecorderUtilities.h */,
1325-
EED404361FCF02AB00D08020 /* XCUIScreen.h */,
13261324
);
13271325
path = XCTest;
13281326
sourceTree = "<group>";

WebDriverAgentLib/Categories/XCUIDevice+FBHelpers.m

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
#import "FBMacros.h"
2222
#import "XCAXClient_iOS.h"
23-
#import "XCUIScreen.h"
2423

2524
static const NSTimeInterval FBHomeButtonCoolOffTime = 1.;
2625

@@ -43,8 +42,8 @@ - (BOOL)fb_goToHomescreenWithError:(NSError **)error
4342

4443
- (NSData *)fb_screenshotWithError:(NSError*__autoreleasing*)error
4544
{
46-
Class xcScreenClass = NSClassFromString(@"XCUIScreen");
47-
if (nil == xcScreenClass) {
45+
id xcScreen = NSClassFromString(@"XCUIScreen");
46+
if (nil == xcScreen) {
4847
NSData *result = [[XCAXClient_iOS sharedClient] screenshotData];
4948
if (nil == result) {
5049
if (error) {
@@ -55,19 +54,27 @@ - (NSData *)fb_screenshotWithError:(NSError*__autoreleasing*)error
5554
return result;
5655
}
5756

57+
id mainScreen = [xcScreen valueForKey:@"mainScreen"];
58+
CGSize screenSize = FBAdjustDimensionsForApplication(FBApplication.fb_activeApplication.frame.size, (UIInterfaceOrientation)[self.class sharedDevice].orientation);
59+
SEL mSelector = NSSelectorFromString(@"screenshotDataForQuality:rect:error:");
60+
NSMethodSignature *mSignature = [mainScreen methodSignatureForSelector:mSelector];
61+
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:mSignature];
62+
[invocation setTarget:mainScreen];
63+
[invocation setSelector:mSelector];
5864
// https://developer.apple.com/documentation/xctest/xctimagequality?language=objc
5965
// Select lower quality, since XCTest crashes randomly if the maximum quality (zero value) is selected
6066
// and the resulting screenshot does not fit the memory buffer preallocated for it by the operating system
61-
CGSize screenSize = FBAdjustDimensionsForApplication(FBApplication.fb_activeApplication.frame.size, (UIInterfaceOrientation)[self.class sharedDevice].orientation);
6267
NSUInteger quality = 1;
68+
[invocation setArgument:&quality atIndex:2];
6369
CGRect screenRect = CGRectMake(0, 0, screenSize.width, screenSize.height);
64-
65-
XCUIScreen *mainScreen = (XCUIScreen *)[xcScreenClass mainScreen];
66-
NSData *result = [mainScreen screenshotDataForQuality:quality rect:screenRect error:error];
70+
[invocation setArgument:&screenRect atIndex:3];
71+
[invocation setArgument:&error atIndex:4];
72+
[invocation invoke];
73+
NSData __unsafe_unretained *result;
74+
[invocation getReturnValue:&result];
6775
if (nil == result) {
6876
return nil;
6977
}
70-
7178
// The resulting data is a JPEG image, so we need to convert it to PNG representation
7279
UIImage *image = [UIImage imageWithData:result];
7380
return (NSData *)UIImagePNGRepresentation(image);

0 commit comments

Comments
 (0)