Skip to content

Commit fb5265c

Browse files
clayne11claude
andcommitted
feat: add trigger-screenshot command for iOS simulators
Add a new `trigger-screenshot` command that posts UIApplication.userDidTakeScreenshotNotification from within the XCTest runner process. This allows automating workflows that depend on screenshot detection (e.g., in-app bug reporters, feedback tools). The existing `screenshot` command captures an image via simctl but does not fire the in-app notification. This new command complements it by simulating what happens when a user presses the hardware screenshot buttons. iOS simulator-only (the notification cannot be spoofed on physical devices). Closes callstack#123 Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent 13b2e2c commit fb5265c

4 files changed

Lines changed: 26 additions & 0 deletions

File tree

‎ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,9 @@ final class RunnerTests: XCTestCase {
819819
}
820820
pinch(app: activeApp, scale: scale, x: command.x, y: command.y)
821821
return Response(ok: true, data: DataPayload(message: "pinched"))
822+
case .triggerScreenshot:
823+
NotificationCenter.default.post(name: UIApplication.userDidTakeScreenshotNotification, object: nil)
824+
return Response(ok: true, data: DataPayload(message: "screenshot notification triggered"))
822825
}
823826
}
824827

@@ -1748,6 +1751,7 @@ enum CommandType: String, Codable {
17481751
case pinch
17491752
case recordStart
17501753
case recordStop
1754+
case triggerScreenshot
17511755
case shutdown
17521756
}
17531757

‎src/core/capabilities.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const COMMAND_CAPABILITY_MATRIX: Record<string, CommandCapability> = {
3737
push: { ios: { simulator: true }, android: { emulator: true, device: true, unknown: true } },
3838
record: { ios: { simulator: true, device: true }, android: { emulator: true, device: true, unknown: true } },
3939
screenshot: { ios: { simulator: true, device: true }, android: { emulator: true, device: true, unknown: true } },
40+
'trigger-screenshot': { ios: { simulator: true } },
4041
scroll: { ios: { simulator: true, device: true }, android: { emulator: true, device: true, unknown: true } },
4142
scrollintoview: { ios: { simulator: true, device: true }, android: { emulator: true, device: true, unknown: true } },
4243
swipe: { ios: { simulator: true, device: true }, android: { emulator: true, device: true, unknown: true } },

‎src/core/dispatch.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,22 @@ export async function dispatchCommand(
362362
await interactor.screenshot(screenshotPath);
363363
return { path: screenshotPath };
364364
}
365+
case 'trigger-screenshot': {
366+
if (device.platform !== 'ios') {
367+
throw new AppError('UNSUPPORTED_PLATFORM', 'trigger-screenshot is only supported on iOS simulators');
368+
}
369+
await runIosRunnerCommand(
370+
device,
371+
{ command: 'triggerScreenshot', appBundleId: context?.appBundleId },
372+
{
373+
verbose: context?.verbose,
374+
logPath: context?.logPath,
375+
traceLogPath: context?.traceLogPath,
376+
requestId: context?.requestId,
377+
},
378+
);
379+
return { action: 'trigger-screenshot' };
380+
}
365381
case 'back': {
366382
if (device.platform === 'ios') {
367383
await runIosRunnerCommand(

‎src/utils/command-schema.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,11 @@ const COMMAND_SCHEMAS: Record<string, CommandSchema> = {
530530
positionalArgs: ['path?'],
531531
allowedFlags: ['out'],
532532
},
533+
'trigger-screenshot': {
534+
description: 'Simulate user screenshot (fires userDidTakeScreenshotNotification, iOS simulator only)',
535+
positionalArgs: [],
536+
allowedFlags: [],
537+
},
533538
record: {
534539
usageOverride: 'record start [path] [--fps <n>] | record stop',
535540
description: 'Start/stop screen recording',

0 commit comments

Comments
 (0)