How to view app logging when ui testing
Asked Answered
H

1

11

When running UI tests on my iOS app on our Jenkins CI slave, the UI is incorrect and my tests fail. Locally, the same UI is as expected and the tests pass.

I haven't been able to figure this out and I cannot debug it as it is on a remote machine. So, I would like to add logging to see what decisions are being made by the app to figure out why the UI is displaying incorrectly in the remote Jenkins slave.

The test log output does not contain log output from the app (via NSLog), nor can I find any of the strings from the appNSLog calls in any .xcactivitylog file in the derived data output folders.

Where can I find my logging output from my app when it is being run by the UI tests? This is with Xcode 8.2 running a iOS 9.3 simulated device.

Hapte answered 5/1, 2017 at 14:35 Comment(4)
Have you tried this? #10166141Caseation
Getting the UUID of the Simulator gives me exactly what I am looking for. Thank you!Hapte
This is the exact link: https://mcmap.net/q/74436/-how-can-i-get-the-console-logs-from-the-ios-simulatorHapte
I added functionality to the scan action of fastlane to collect the logs, include_simulator_logsHapte
E
5

The following solution is a bit hacky but allows you to get the logs even when running on the device.

Logger.h

#define Debug(...) _Debug(__VA_ARGS__)

void _Debug(NSString *format, ...);

Logger.m

void _Debug(NSString *format, ...)
{    
    format = [NSString stringWithFormat:@"[Debug]: %@", format];
    va_list args;
    va_start(args, format);
    NSLogv(format, args); // logs to the console

    NSString *logMessage = [[NSString alloc] initWithFormat:format arguments:arguments];
    UIApplication *application = [UIApplication sharedApplication];
    UIWindow *window = [application keyWindow];
    window.accessibilityValue = [NSString stringWithFormat:@"%@\n%@", window.accessibilityValue, logMessage];

    va_end(args);
}

Then from the UI Test, I can access the logs like this

+ (NSString *)logs
{
    XCUIElementQuery *windowQuery = [[[XCUIApplication alloc] init] windows];
    return [windowQuery elementAtIndex:0].value;
}
Elisavetgrad answered 18/4, 2017 at 2:29 Comment(1)
Yeah, that is one way to pass value back to UITest.Acicular

© 2022 - 2024 — McMap. All rights reserved.