You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

RN Detox iOS测试:能否将全系列测试录制成单个视频?

Answer to your Detox iOS Video Recording Question

Great question! I’ve dealt with this exact need for a single consolidated video of our full Detox test suite on iOS, and while Detox doesn’t support this natively out of the box, there are reliable workarounds to make it happen:

1. Post-Test Script + FFmpeg Video Merging

This is the most straightforward approach—we’ll let Detox generate individual test videos as usual, then automatically stitch them together into one full-length video after the test run completes.

Step-by-Step Setup:

  • Keep using your existing command: Continue running Detox with --record-videos all (you can also specify a custom artifacts path with --artifacts-location ./my-test-artifacts to keep things organized). Detox will save each test’s video in the videos subfolder of your artifacts directory.
  • Install FFmpeg: You’ll need this tool to merge the videos. On macOS, use brew install ffmpeg; on Linux, use sudo apt-get install ffmpeg.
  • Create a merge script: Write a simple shell script (e.g., scripts/combine_detox_videos.sh) to sort the videos by execution order and merge them:
#!/bin/bash

# Navigate to the videos directory (update path if you used --artifacts-location)
ARTIFACTS_DIR="./artifacts/videos"
cd "$ARTIFACTS_DIR" || exit 1

# Generate a list of videos sorted by modification time (matches test execution order)
ls -tr *.mp4 | grep -v "full-test-run" > video_list.txt

# Merge all videos into a single file
ffmpeg -f concat -safe 0 -i video_list.txt -c copy full-test-run.mp4

# Clean up the temporary list file
rm video_list.txt

echo "Successfully merged all test videos into full-test-run.mp4"
  • Automate the script with Detox hooks: Add a postTest hook to your detox.config.js to run the script automatically after the entire test suite finishes:
module.exports = {
  // ... your existing Detox config
  hooks: {
    postTest: async () => {
      const { execSync } = require('child_process');
      try {
        execSync('./scripts/combine_detox_videos.sh', { stdio: 'inherit' });
      } catch (error) {
        console.warn('Warning: Failed to merge test videos. Error:', error.message);
      }
    }
  }
};

Notes:

  • If you run into encoding issues (e.g., videos won’t merge), replace -c copy in the FFmpeg command with -c:v libx264 -c:a aac—this re-encodes the videos to a compatible format, though it will take a bit longer.
  • The ls -tr command sorts files by modification time, which aligns with the order your tests ran (since each video is saved right after its test completes).

2. Why Native Support Isn’t Available

Just to clarify: Detox’s iOS video recording relies on Apple’s XCUIRecorder API, which creates a new recording session for each individual XCTest method. This means there’s no way to natively record across multiple test cases in a single session—hence the need for post-processing.

This workaround has been solid for our team, and it lets us keep the per-test videos for debugging while also having a single video for design/validation checks.

内容的提问来源于stack exchange,提问作者Nicolas Smit

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 08:22:37