How to Access Application Logs when UI Testing in Xcode 9.2 ?

Hi,


I'm using Xcode 9.2 and iOS 11.2 Simulator.

I would like to see my application's logs (NSLog call) while the app is tested with XCTest UI tests.

I can launch the test with:


xcodebuild -project MyProject.xcodeproj -scheme MyScheme -destination "platform=iOS Simulator,name=iPhone 5s,OS=11.2" test


The output of this command is the ouput of the UI test, but I don't see the application NSLog logs.


Test Case '-[TestsUIOrangeEtMoi.OEMHomeTest testTapOnFactureTile]' started.
    t =     0.00s Start Test at 2017-12-07 11:26:05.743
    t =     0.04s Set Up
    t =     0.15s     Open com.orange.fr.orangeetmoisettings.bdx2
    t =     0.18s         Launch com.orange.fr.orangeetmoisettings.bdx2
    t =     4.30s             Wait for com.orange.fr.orangeetmoisettings.bdx2 to idle
    t =     6.49s     Tap "Adresse mail ou numéro de mobile" TextField
    t =     6.49s         Wait for com.orange.fr.orangeetmoisettings.bdx2 to idle


In the Simulator, I can go to 'Debug > Open System Log...", and it will open a log file ~/Library/Logs/CoreSimulator/DA22333D-A6BF-41EC-8BA4-F21C0EE6E177/system.log where DA22333D-A6BF-41EC-8BA4-F21C0EE6E177 is a hash of the simulator id. If I tail -f this file, I don't see any application logs, just "core" logs.


Any idea how to access the application logs in this case ?


Regards,


Jc

Replies

Here https://michele.io/test-logs-in-xcode/ you can find a detailed explanaition of the test logs, maybe that can help you.

I ran into this problem when I was trying to see the logs on my CI system, but I have decided to use fastlane scan since it can present the the test results on an html file without the need of a plugin, parse logs or something like that.

When the test is running, you can go to the Debug Navigator (7th tab) and select the tested target (instead of the test runner). That will change the console to spit out logs from the app instead of the test runner.


After the test is completed, you can go to the Report Navigator (9th tab) and select your project (as opposed to the test target). There, you should see Debug entries, each one correlates to one session (one for each test).

 yufei's answer is correct. Attaching a screenshot as it might be helpful. Solution: Choose the App target -> 2 as indicated in the screenshot to print app logs in the console.