appium-webdriveragent 4.8.1 → 4.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -9,7 +9,16 @@
|
|
|
9
9
|
|
|
10
10
|
#import "FBPasteboard.h"
|
|
11
11
|
|
|
12
|
+
#import <mach/mach_time.h>
|
|
13
|
+
#import "FBAlert.h"
|
|
14
|
+
#import "FBApplication.h"
|
|
12
15
|
#import "FBErrorBuilder.h"
|
|
16
|
+
#import "FBMacros.h"
|
|
17
|
+
#import "XCUIApplication+FBAlert.h"
|
|
18
|
+
|
|
19
|
+
#define ALERT_TIMEOUT_SEC 30
|
|
20
|
+
// Must not be less than FB_MONTORING_INTERVAL in FBAlertsMonitor
|
|
21
|
+
#define ALERT_CHECK_INTERVAL_SEC 2
|
|
13
22
|
|
|
14
23
|
#if !TARGET_OS_TV
|
|
15
24
|
@implementation FBPasteboard
|
|
@@ -50,21 +59,100 @@
|
|
|
50
59
|
return YES;
|
|
51
60
|
}
|
|
52
61
|
|
|
62
|
+
+ (nullable id)pasteboardContentForItem:(NSString *)item
|
|
63
|
+
instance:(UIPasteboard *)pbInstance
|
|
64
|
+
timeout:(NSTimeInterval)timeout
|
|
65
|
+
error:(NSError **)error
|
|
66
|
+
{
|
|
67
|
+
SEL selector = NSSelectorFromString(item);
|
|
68
|
+
NSMethodSignature *methodSignature = [pbInstance methodSignatureForSelector:selector];
|
|
69
|
+
if (nil == methodSignature) {
|
|
70
|
+
NSString *description = [NSString stringWithFormat:@"Cannot retrieve '%@' from a UIPasteboard instance", item];
|
|
71
|
+
if (error) {
|
|
72
|
+
*error = [[FBErrorBuilder.builder withDescription:description] build];
|
|
73
|
+
}
|
|
74
|
+
return nil;
|
|
75
|
+
}
|
|
76
|
+
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature];
|
|
77
|
+
[invocation setSelector:selector];
|
|
78
|
+
[invocation setTarget:pbInstance];
|
|
79
|
+
if (SYSTEM_VERSION_LESS_THAN(@"16.0")) {
|
|
80
|
+
[invocation invoke];
|
|
81
|
+
id __unsafe_unretained result;
|
|
82
|
+
[invocation getReturnValue:&result];
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// https://github.com/appium/appium/issues/17392
|
|
87
|
+
__block id pasteboardContent;
|
|
88
|
+
dispatch_queue_t backgroundQueue = dispatch_queue_create("GetPasteboard", NULL);
|
|
89
|
+
__block BOOL didFinishGetPasteboard = NO;
|
|
90
|
+
dispatch_async(backgroundQueue, ^{
|
|
91
|
+
[invocation invoke];
|
|
92
|
+
id __unsafe_unretained result;
|
|
93
|
+
[invocation getReturnValue:&result];
|
|
94
|
+
pasteboardContent = result;
|
|
95
|
+
didFinishGetPasteboard = YES;
|
|
96
|
+
});
|
|
97
|
+
uint64_t timeStarted = mach_absolute_time();
|
|
98
|
+
while (!didFinishGetPasteboard) {
|
|
99
|
+
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:ALERT_CHECK_INTERVAL_SEC]];
|
|
100
|
+
if (didFinishGetPasteboard) {
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
XCUIElement *alertElement = FBApplication.fb_systemApplication.fb_alertElement;
|
|
105
|
+
if (nil != alertElement) {
|
|
106
|
+
FBAlert *alert = [FBAlert alertWithElement:alertElement];
|
|
107
|
+
[alert acceptWithError:nil];
|
|
108
|
+
}
|
|
109
|
+
uint64_t timeElapsed = mach_absolute_time() - timeStarted;
|
|
110
|
+
if (timeElapsed / NSEC_PER_SEC > timeout) {
|
|
111
|
+
NSString *description = [NSString stringWithFormat:@"Cannot handle pasteboard alert within %@s timeout", @(timeout)];
|
|
112
|
+
if (error) {
|
|
113
|
+
*error = [[FBErrorBuilder.builder withDescription:description] build];
|
|
114
|
+
}
|
|
115
|
+
return nil;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return pasteboardContent;
|
|
119
|
+
}
|
|
120
|
+
|
|
53
121
|
+ (NSData *)dataForType:(NSString *)type error:(NSError **)error
|
|
54
122
|
{
|
|
55
123
|
UIPasteboard *pb = UIPasteboard.generalPasteboard;
|
|
56
124
|
if ([type.lowercaseString isEqualToString:@"plaintext"]) {
|
|
57
125
|
if (pb.hasStrings) {
|
|
58
|
-
|
|
126
|
+
id result = [self.class pasteboardContentForItem:@"strings"
|
|
127
|
+
instance:pb
|
|
128
|
+
timeout:ALERT_TIMEOUT_SEC
|
|
129
|
+
error:error
|
|
130
|
+
];
|
|
131
|
+
return nil == result
|
|
132
|
+
? nil
|
|
133
|
+
: [[(NSArray *)result componentsJoinedByString:@"\n"] dataUsingEncoding:NSUTF8StringEncoding];
|
|
59
134
|
}
|
|
60
135
|
} else if ([type.lowercaseString isEqualToString:@"image"]) {
|
|
61
136
|
if (pb.hasImages) {
|
|
62
|
-
|
|
137
|
+
id result = [self.class pasteboardContentForItem:@"image"
|
|
138
|
+
instance:pb
|
|
139
|
+
timeout:ALERT_TIMEOUT_SEC
|
|
140
|
+
error:error
|
|
141
|
+
];
|
|
142
|
+
return nil == result ? nil : UIImagePNGRepresentation((UIImage *)result);
|
|
63
143
|
}
|
|
64
144
|
} else if ([type.lowercaseString isEqualToString:@"url"]) {
|
|
65
145
|
if (pb.hasURLs) {
|
|
146
|
+
id result = [self.class pasteboardContentForItem:@"URLs"
|
|
147
|
+
instance:pb
|
|
148
|
+
timeout:ALERT_TIMEOUT_SEC
|
|
149
|
+
error:error
|
|
150
|
+
];
|
|
151
|
+
if (nil == result) {
|
|
152
|
+
return nil;
|
|
153
|
+
}
|
|
66
154
|
NSMutableArray<NSString *> *urls = [NSMutableArray array];
|
|
67
|
-
for (NSURL *url in
|
|
155
|
+
for (NSURL *url in (NSArray *)result) {
|
|
68
156
|
if (nil != url.absoluteString) {
|
|
69
157
|
[urls addObject:(id)url.absoluteString];
|
|
70
158
|
}
|
|
Binary file
|
|
@@ -71,11 +71,7 @@
|
|
|
71
71
|
FBWaitExact(1.0);
|
|
72
72
|
NSData *result = [FBPasteboard dataForType:@"plaintext" error:&error];
|
|
73
73
|
XCTAssertNil(error);
|
|
74
|
-
|
|
75
|
-
// Pasteboard permission appears in a simulator. Not in a real device.
|
|
76
|
-
} else {
|
|
77
|
-
XCTAssertEqualObjects(textField.value, [[NSString alloc] initWithData:result encoding:NSUTF8StringEncoding]);
|
|
78
|
-
}
|
|
74
|
+
XCTAssertEqualObjects(textField.value, [[NSString alloc] initWithData:result encoding:NSUTF8StringEncoding]);
|
|
79
75
|
}
|
|
80
76
|
|
|
81
77
|
- (void)testUrlCopyPaste
|