get the content material of a notification in XCUITest, particularly the notification’s identifier
I’ve a chunk of code in my app to point out a notification as follows:
- (NSString *)showNotificationWithIdentifier:(NSString * _Nullable)identifier
title:(NSString *)title
description:(NSString *)description {
NSString *_id;
// No ID specified (computerized increment)
if (identifier == nil) {
NSUserDefaults *desire = [[NSUserDefaults alloc] initWithSuiteName:AfibNotificationManager.TAG];
NSString *latestIdStr = [prefer stringForKey:AfibNotificationManager.LATEST_ID_KEY];
int tmpId;
if (latestIdStr == nil) {
tmpId = INT_MIN;
} else {
tmpId = [latestIdStr intValue];
tmpId += 1;
}
_id = [NSString stringWithFormat:@"%d", tmpId];
[prefer setValue:_id forKey:AfibNotificationManager.LATEST_ID_KEY];
}
// ID specified
else {
_id = identifier;
}
UNMutableNotificationContent *content material = [[UNMutableNotificationContent alloc] init];
content material.title = title;
content material.physique = description;
content material.sound = [UNNotificationSound defaultSound];
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:_id content:content trigger:nil];
dispatch_async(dispatch_get_main_queue(), ^{
[[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:nil];
});
return _id;
}
That is my UITest code:
- (void)checkNotification {
XCUIApplication *app = [[XCUIApplication alloc] init];
[app launch];
[app.buttons[@"btn"] faucet]; //click on button will name technique showNotificationWithIdentifier to point out notification
XCUIApplication *springboard = [[XCUIApplication alloc];
initWithBundleIdentifier:@"com.apple.springboard"];
XCUICoordinate *begin = [app coordinateWithNormalizedOffset:CGVectorMake(0.5, 0.0)];
XCUICoordinate *end = [app coordinateWithNormalizedOffset:CGVectorMake(0.5, 1.5)];
[start pressForDuration:0.1 thenDragToCoordinate:finish];
XCUIElement *notification = springboard.buttons[@"NotificationCell"];
XCTAssertTrue([notification waitForExistenceWithTimeout:5]);
NSString *identifier = notification.identifier;
}
After I carry out XCUITest to get notification info akin to notification identifier, I encounter difficulties and it appears incorrect. May you assist me with a solution to retrieve the notification identifier, label, and test if the notification has been displayed or not? Thanks.