limrun-detox-testing

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Limrun Detox

Limrun Detox

Use this for Detox runtime work on Limrun iOS. Keep build concerns separate unless the user explicitly asks for a native build.
本指南适用于在Limrun iOS上进行Detox运行时相关操作。除非用户明确要求原生构建,否则请将构建相关问题与运行时操作分开处理。

Components

组件

  • Tester: local Node/Jest/Detox process.
  • Mediator:
    detox run-server
    , usually local to the agent machine.
  • App client: injected by limulator through
    lim ios launch-app --runtime detox
    .
  • 测试端:本地Node/Jest/Detox进程。
  • 中介:
    detox run-server
    ,通常部署在Agent机器本地。
  • 应用客户端:由limulator通过
    lim ios launch-app --runtime detox
    注入。

CLI Flow

CLI 流程

Check current help before running commands you have not used in this session:
bash
lim ios reverse --help
lim ios launch-app --help
Typical sequence:
bash
undefined
在运行本次会话中未使用过的命令前,请先查看当前帮助信息:
bash
lim ios reverse --help
lim ios launch-app --help
典型操作序列:
bash
undefined

Start the Detox mediator locally.

在本地启动Detox中介。

npx detox run-server -p 8099 -l verbose
npx detox run-server -p 8099 -l verbose

Expose the mediator to the simulator.

将中介暴露给模拟器。

lim ios reverse 57091:8099 --id <ios-id>
lim ios reverse 57091:8099 --id <ios-id>

Relaunch the app with the managed Detox runtime. Use the remote endpoint

使用托管的Detox运行时重新启动应用。请使用
lim ios reverse
输出的远程端点,而非用户机器上的127.0.0.1。

printed by
lim ios reverse
, not 127.0.0.1 on the user machine.

当从包含node_modules/detox的项目中运行时,--detox-version为可选参数。

--detox-version is optional when running from the project with node_modules/detox.

lim ios launch-app <bundle-id>
--id <ios-id>
--runtime detox
--detox-server-url ws://<reverse-remote-host>:57091
--detox-session-id <session-id>
--detox-version <detox-version>
lim ios launch-app <bundle-id>
--id <ios-id>
--runtime detox
--detox-server-url ws://<reverse-remote-host>:57091
--detox-session-id <session-id>
--detox-version <detox-version>

Run the tester with the same server/session.

使用相同的服务器/会话启动测试端。

npx detox test --no-start

Prefer starting the tester before the app connects, or use the maintained orchestration in `examples/detox-ios`, to avoid benign mediator "cannot forward" noise.
If you manually launch the app before `npx detox test --no-start`, that mediator message is expected until the tester connects.
npx detox test --no-start

建议先启动测试端,再让应用连接;或使用`examples/detox-ios`中维护的编排流程,以避免中介出现无关的“无法转发”日志。
如果在执行`npx detox test --no-start`前手动启动应用,那么在测试端连接前,中介出现该提示信息是正常现象。

Detox Test Setup

Detox 测试配置

npx detox test --no-start
still needs the normal Detox project configuration:
  • Pass the Detox config file and configuration name from your project (see
    examples/detox-ios/.detoxrc.cjs
    for a reference layout).
  • Use the Limrun third-party driver:
    type: '@limrun/detox/driver'
    .
  • Keep
    DETOX_SERVER
    and
    DETOX_SESSION_ID
    aligned with the mediator and launch command.
  • Provide Limrun driver env such as
    LIMRUN_IOS_ID
    ,
    LIMRUN_IOS_API_URL
    , and
    LIMRUN_IOS_TOKEN
    when screenshots or driver calls need the instance API.
Use
examples/detox-ios
as the maintained happy path for exact config/env wiring. Use
-l trace
on
detox run-server
only when verbose logs are not enough.
For native SwiftUI apps, a minimal Detox configuration usually looks like:
js
module.exports = {
  testRunner: { args: { $0: 'jest' }, jest: { setupTimeout: 120000 } },
  apps: { ios: { type: 'ios.app', binaryPath: 'unused-by-limrun' } },
  devices: {
    limrun: {
      type: '@limrun/detox/driver',
      device: { id: process.env.LIMRUN_IOS_ID },
    },
  },
  configurations: {
    'ios.limrun': {
      device: 'limrun',
      app: 'ios',
      behavior: { init: { reinstallApp: false }, cleanup: { shutdownDevice: false } },
    },
  },
};
Then launch with
lim ios launch-app <bundle-id> --runtime detox ...
and run
npx detox test --no-start
.
npx detox test --no-start
仍需常规的Detox项目配置:
  • 传入项目中的Detox配置文件和配置名称(参考
    examples/detox-ios/.detoxrc.cjs
    的布局)。
  • 使用Limrun第三方驱动:
    type: '@limrun/detox/driver'
  • 保持
    DETOX_SERVER
    DETOX_SESSION_ID
    与中介及启动命令一致。
  • 当需要调用实例API进行截图或驱动调用时,提供Limrun驱动环境变量,如
    LIMRUN_IOS_ID
    LIMRUN_IOS_API_URL
    LIMRUN_IOS_TOKEN
请将
examples/detox-ios
作为配置/环境变量设置的标准参考路径。仅当verbose日志不足以排查问题时,才在
detox run-server
中使用
-l trace
参数。
对于原生SwiftUI应用,最简Detox配置通常如下:
js
module.exports = {
  testRunner: { args: { $0: 'jest' }, jest: { setupTimeout: 120000 } },
  apps: { ios: { type: 'ios.app', binaryPath: 'unused-by-limrun' } },
  devices: {
    limrun: {
      type: '@limrun/detox/driver',
      device: { id: process.env.LIMRUN_IOS_ID },
    },
  },
  configurations: {
    'ios.limrun': {
      device: 'limrun',
      app: 'ios',
      behavior: { init: { reinstallApp: false }, cleanup: { shutdownDevice: false } },
    },
  },
};
随后使用
lim ios launch-app <bundle-id> --runtime detox ...
启动应用,并运行
npx detox test --no-start

Validation Signals

验证信号

  • App connected:
    detox run-server
    logs
    role:"app"
    and
    appConnected:true
    .
  • Tester connected: the same session reaches
    testerConnected:true, appConnected:true
    .
  • Runtime loaded: the app connects to the mediator after the
    --runtime detox
    launch.
  • UI visible:
    lim ios element-tree --id <ios-id>
    shows the expected app screen.
  • 应用已连接:
    detox run-server
    日志中出现
    role:"app"
    appConnected:true
  • 测试端已连接:同一会话显示
    testerConnected:true, appConnected:true
  • 运行时已加载:应用在通过
    --runtime detox
    启动后连接到中介。
  • UI可见:
    lim ios element-tree --id <ios-id>
    显示预期的应用界面。

Gotchas

注意事项

  • Do not pass arbitrary env vars, app args, or injectable paths. Use
    --runtime detox
    .
  • --detox-version
    should match the local
    detox
    package version used by the tester. If omitted,
    lim ios launch-app
    resolves it from the current working directory; pass it explicitly when running outside the Detox project.
  • Unsupported bundled Detox versions should fail with a clear supported-version list.
  • Cannot forward the message to the Detox client
    can simply mean the app connected before the tester did.
  • For SwiftUI, prefer stable accessibility identifiers, e.g.
    .accessibilityIdentifier("greetingText")
    with
    by.id('greetingText')
    ;
    by.text(...)
    can miss labels that appear in
    lim ios element-tree
    .
  • Debug failures by checking
    lim ios element-tree --id <ios-id>
    first, then mediator logs for app/tester connection state.
  • Cleanup manual runs by stopping
    detox run-server
    , stopping
    lim ios reverse
    , and deleting the instance with
    lim ios delete <ios-id>
    (
    --id
    is not valid for delete).
  • This does not make Detox own the iOS lifecycle; prepare or reuse the Limrun instance separately.
  • 请勿传递任意环境变量、应用参数或可注入路径,请使用
    --runtime detox
  • --detox-version
    应与测试端使用的本地
    detox
    包版本匹配。如果省略,
    lim ios launch-app
    会从当前工作目录解析版本;在Detox项目外运行时,请显式传递该参数。
  • 不支持的Detox捆绑版本会明确列出支持的版本列表并报错。
  • Cannot forward the message to the Detox client
    仅表示应用先于测试端连接。
  • 对于SwiftUI,建议使用稳定的可访问性标识符,例如
    .accessibilityIdentifier("greetingText")
    配合
    by.id('greetingText')
    by.text(...)
    可能无法识别
    lim ios element-tree
    中显示的标签。
  • 排查故障时,请先检查
    lim ios element-tree --id <ios-id>
    ,再查看中介日志中的应用/测试端连接状态。
  • 手动运行完成后,请通过停止
    detox run-server
    、停止
    lim ios reverse
    并使用
    lim ios delete <ios-id>
    (删除操作不支持
    --id
    参数)删除实例来清理环境。
  • 本流程不会让Detox接管iOS生命周期,请单独准备或复用Limrun实例。