Как получить содержимое уведомления в XCUITest?IOS

Программируем под IOS
Ответить
Anonymous
 Как получить содержимое уведомления в XCUITest?

Сообщение Anonymous »

Как получить содержимое уведомления в XCUITest, в частности идентификатор уведомления
В моем приложении есть фрагмент кода для отображения уведомления следующим образом:

Код: Выделить всё

- (NSString *)showNotificationWithIdentifier:(NSString * _Nullable)identifier
title:(NSString *)title
description:(NSString *)description {
NSString *_id;
// No ID specified (automatic increment)
if (identifier == nil) {
NSUserDefaults *prefer = [[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 = [[UNMutableNotificationContent alloc] init];
content.title = title;
content.body = description;
content.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;
}
Это мой код теста пользовательского интерфейса:

Код: Выделить всё

- (void)checkNotification {

XCUIApplication *app = [[XCUIApplication alloc] init];
[app launch];
[app.buttons[@"btn"] tap]; //click button will call method showNotificationWithIdentifier to show notification

XCUIApplication *springboard = [[XCUIApplication alloc];
initWithBundleIdentifier:@"com.apple.springboard"];
XCUICoordinate *start = [app coordinateWithNormalizedOffset:CGVectorMake(0.5, 0.0)];
XCUICoordinate *finish = [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;
}
Когда я выполняю XCUITest для получения информации об уведомлении, например идентификатора уведомления, я сталкиваюсь с трудностями, и это кажется неправильным. Не могли бы вы помочь мне получить идентификатор уведомления, метку и проверить, отобразилось ли уведомление или нет? Спасибо.

Подробнее здесь: https://stackoverflow.com/questions/792 ... n-xcuitest
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «IOS»