|
25 | 25 | #import "FBXCTestDaemonsProxy.h" |
26 | 26 | #import "XCUIApplication+FBQuiescence.h" |
27 | 27 | #import "XCUIElement.h" |
| 28 | +#import "XCUIElement+FBClassChain.h" |
28 | 29 |
|
29 | 30 | /*! |
30 | 31 | The intial value for the default application property. |
@@ -53,6 +54,22 @@ @implementation FBSession (FBAlertsMonitorDelegate) |
53 | 54 |
|
54 | 55 | - (void)didDetectAlert:(FBAlert *)alert |
55 | 56 | { |
| 57 | + NSString *autoClickAlertSelector = FBConfiguration.autoClickAlertSelector; |
| 58 | + if ([autoClickAlertSelector length] > 0) { |
| 59 | + @try { |
| 60 | + NSArray<XCUIElement*> *matches = [alert.alertElement fb_descendantsMatchingClassChain:autoClickAlertSelector |
| 61 | + shouldReturnAfterFirstMatch:YES]; |
| 62 | + if (matches.count > 0) { |
| 63 | + [[matches objectAtIndex:0] tap]; |
| 64 | + } |
| 65 | + } @catch (NSException *e) { |
| 66 | + [FBLogger logFmt:@"Could not click at the alert element '%@'. Original error: %@", |
| 67 | + autoClickAlertSelector, e.description]; |
| 68 | + } |
| 69 | + // This setting has priority over other settings if enabled |
| 70 | + return; |
| 71 | + } |
| 72 | + |
56 | 73 | if (nil == self.defaultAlertAction || 0 == self.defaultAlertAction.length) { |
57 | 74 | return; |
58 | 75 | } |
@@ -125,23 +142,41 @@ + (instancetype)initWithApplication:(nullable XCUIApplication *)application |
125 | 142 | defaultAlertAction:(NSString *)defaultAlertAction |
126 | 143 | { |
127 | 144 | FBSession *session = [self.class initWithApplication:application]; |
128 | | - session.alertsMonitor = [[FBAlertsMonitor alloc] init]; |
129 | | - session.alertsMonitor.delegate = (id<FBAlertsMonitorDelegate>)session; |
130 | 145 | session.defaultAlertAction = [defaultAlertAction lowercaseString]; |
131 | | - [session.alertsMonitor enable]; |
| 146 | + [session enableAlertsMonitor]; |
132 | 147 | return session; |
133 | 148 | } |
134 | 149 |
|
| 150 | +- (BOOL)enableAlertsMonitor |
| 151 | +{ |
| 152 | + if (nil != self.alertsMonitor) { |
| 153 | + return NO; |
| 154 | + } |
| 155 | + |
| 156 | + self.alertsMonitor = [[FBAlertsMonitor alloc] init]; |
| 157 | + self.alertsMonitor.delegate = (id<FBAlertsMonitorDelegate>)self; |
| 158 | + [self.alertsMonitor enable]; |
| 159 | + return YES; |
| 160 | +} |
| 161 | + |
| 162 | +- (BOOL)disableAlertsMonitor |
| 163 | +{ |
| 164 | + if (nil == self.alertsMonitor) { |
| 165 | + return NO; |
| 166 | + } |
| 167 | + |
| 168 | + [self.alertsMonitor disable]; |
| 169 | + self.alertsMonitor = nil; |
| 170 | + return YES; |
| 171 | +} |
| 172 | + |
135 | 173 | - (void)kill |
136 | 174 | { |
137 | 175 | if (nil == _activeSession) { |
138 | 176 | return; |
139 | 177 | } |
140 | 178 |
|
141 | | - if (nil != self.alertsMonitor) { |
142 | | - [self.alertsMonitor disable]; |
143 | | - self.alertsMonitor = nil; |
144 | | - } |
| 179 | + [self disableAlertsMonitor]; |
145 | 180 |
|
146 | 181 | FBScreenRecordingPromise *activeScreenRecording = FBScreenRecordingContainer.sharedInstance.screenRecordingPromise; |
147 | 182 | if (nil != activeScreenRecording) { |
|
0 commit comments