Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create 2 separate log files for xcuitest subcommand #361

Merged
merged 4 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions tidevice/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,26 @@ def cmd_xcuitest(args: argparse.Namespace):
"""
Run XCTest required WDA installed.
"""
if args.debug:
setup_logger(LOG.xcuitest, level=logging.DEBUG)
log_level = logging.DEBUG if args.debug else logging.INFO
setup_logger(LOG.xcuitest, level=log_level)

if args.test_process_log_path:
logger.info('XCUITest test process log file path: %s', args.test_process_log_path)
# Use the default formatter that is a no-op formatter.
setup_logger(LOG.xcuitest_test_process_log,
logfile=args.test_process_log_path,
disableStderrLogger=True, # Disable console logging.
level=log_level,
formatter=logging.Formatter())

if args.test_output_path:
logger.info('XCUITest test output file path: %s', args.test_output_path)
# Use the default formatter that is a no-op formatter.
setup_logger(LOG.xcuitest_test_output,
logfile=args.test_output_path,
disableStderrLogger=True, # Disable console logging.
level=log_level,
formatter=logging.Formatter())

d = _udid2device(args.udid)
env = {}
Expand Down Expand Up @@ -861,6 +879,10 @@ def cmd_test(args: argparse.Namespace):
help="set command line args to target app with a comma-separated list of strings"),
dict(args=['--tests-to-run'],
help="specify a set of test classes or test methods to run, format: a comma-separated list of Test-Class-Name[/Test-Method-Name]"),
dict(args=['--test_process_log_path'],
help='The file path to store XCUITest test process logs. By default they are not stored to a file.'),
dict(args=['--test_output_path'],
help='The file path to store XCUITest test output, e.g. UI activity summaries. By default they are not stored to a file.'),
],
help="run XCTest (XCUITest)"),
dict(
Expand Down
20 changes: 20 additions & 0 deletions tidevice/_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
from .session import Session

logger = logging.getLogger(__name__)
xctest_test_process_logger = logging.getLogger(LOG.xcuitest_test_process_log)
xctest_test_output_logger = logging.getLogger(LOG.xcuitest_test_output)


def pil_imread(data: Union[str, pathlib.Path, bytes, bytearray]) -> Image.Image:
Expand Down Expand Up @@ -939,6 +941,10 @@ def _callback(m: DTXMessage):
if method == 'outputReceived:fromProcess:atTime:':
# logger.info("Output: %s", args[0].strip())
logger.debug("logProcess: %s", args[0].rstrip())
# XCTestOutputBarrier is just ouput separators, no need to
# print them in the logs.
if args[0].rstrip() != 'XCTestOutputBarrier':
xctest_test_output_logger.debug('%s', args[0].rstrip())
# In low iOS versions, 'Using singleton test manager' may not be printed... mark wda launch status = True if server url has been printed
if "ServerURLHere" in args[0]:
logger.info("%s", args[0].rstrip())
Expand All @@ -947,6 +953,13 @@ def _callback(m: DTXMessage):
def _log_message_callback(m: DTXMessage):
identifier, args = m.result
logger.debug("logConsole: %s", args)
if isinstance(args, (tuple, list)):
for msg in args:
msg = msg.rstrip() if isinstance(msg, str) else msg
xctest_test_process_logger.debug('%s', msg)
else:
xctest_test_process_logger.debug('%s', args)


conn.register_callback("_XCT_logDebugMessage:", _log_message_callback)
conn.register_callback(Event.NOTIFICATION, _callback)
Expand Down Expand Up @@ -1059,6 +1072,13 @@ def _show_log_message(m: DTXMessage):
logger.info("Test runner ready detected")
_start_executing()

if isinstance(m.result[1], (tuple, list)):
for msg in m.result[1]:
msg = msg.rstrip() if isinstance(msg, str) else msg
xctest_test_process_logger.debug('%s', msg)
else:
xctest_test_process_logger.debug('%s', m.result[1])

test_results = []
test_results_lock = threading.Lock()

Expand Down
2 changes: 2 additions & 0 deletions tidevice/_proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
class LOG(str, enum.Enum):
root = "tidevice"
xcuitest = "tidevice.xctest"
xcuitest_test_process_log = "tidevice.xctest.test_process_log"
xcuitest_test_output = "tidevice.xctest.test_output"
socket = "tidevice.socket"


Expand Down
Loading