London Escorts sunderland escorts 1v1.lol unblocked yohoho 76 https://www.symbaloo.com/mix/yohoho?lang=EN yohoho https://www.symbaloo.com/mix/agariounblockedpvp https://yohoho-io.app/ https://www.symbaloo.com/mix/agariounblockedschool1?lang=EN
2.6 C
New York
Friday, January 31, 2025

ios – Tips on how to get the content material of a notification in XCUITest?


Tips on how to get the content material of a notification in XCUITest, particularly the notification’s identifier

I’ve a bit 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 *choose = [[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 methodology 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;
}

Once I carry out XCUITest to get notification data resembling notification identifier, I encounter difficulties and it appears incorrect. Might you assist me with a method to retrieve the notification identifier, label, and test if the notification has been displayed or not? Thanks.

Related Articles

Social Media Auto Publish Powered By : XYZScripts.com