执行“detox test”命令时,iOS 模拟器应用程序无法启动 #2305

Posted

技术标签:

【中文标题】执行“detox test”命令时,iOS 模拟器应用程序无法启动 #2305【英文标题】:iOS simulator app doesn't launch when 'detox test' command executed #2305 【发布时间】:2020-12-24 04:04:15 【问题描述】:

说明

执行“detox test”命令时,ios 模拟器应用无法启动

Detox --loglevel verbose 输出显示 [DetoxServer.js/CANNOT_FORWARD]

[x] 我已经在最新的 Detox 版本中测试过这个问题,它仍然可以重现 再生产

排毒测试最后一次运行是在 4 月,使用以下设置


  "main": "node_modules/expo/AppEntry.js",
  "scripts": 
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "eject": "expo eject",
    "test": "jest"
  ,
  "dependencies": 
    "expo": "^37.0.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-37.0.0.tar.gz",
  ,
  "devDependencies": 
    "detox": "^15.3.0",
    "detox-expo-helpers": "^0.6.0",
    "expo-detox-hook": "^1.0.10",
    "jest-expo": "^37.0.0",
    "metro-react-native-babel-preset": "^0.53.1",
    "react-native-testing-library": "^1.12.0",
    "react-test-renderer": "^16.12.0",
  ,
  "jest": 
    "preset": "jest-expo",
    "transformIgnorePatterns": [
      "node_modules/(?!(jest-)?react-native|react-clone-referenced-element|@react-native-community|expo(nent)?|@expo(nent)?/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|@sentry/.*|sentry-expo|native-base|react-native-multi-slider|@ptomasroos/.*)"
    ],
    "setupFilesAfterEnv": [
      "<rootDir>/unit_tests/setupTests.js"
    ],
    "testMatch": [
      "<rootDir>/unit_tests/**/*.test.js?(x)"
    ]
  ,
  "detox": 
    "test-runner": "jest",
    "configurations": 
      "ios.sim": 
        "binaryPath": "<app_name>.app",
        "type": "ios.simulator",
        "name": "iPhone 11 Pro Max"
      
    
  

他们现在失败了,如上所述,package.json


  "main": "node_modules/expo/AppEntry.js",
  "scripts": 
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "eject": "expo eject",
    "test": "jest"
  ,
  "dependencies": 
    "expo": "^37.0.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-37.0.0.tar.gz",
  ,
  "devDependencies": 
    "detox": "^17.4.5",
    "detox-expo-helpers": "^0.6.0",
    "expo-detox-hook": "^1.0.10",
    "jest-expo": "^37.0.0",
"metro-react-native-babel-preset": "^0.53.1",
    "react-native-testing-library": "^1.12.0",
    "react-test-renderer": "^16.12.0",
  ,
  "jest": 
    "preset": "jest-expo",
    "transformIgnorePatterns": [
      "node_modules/(?!(jest-)?react-native|react-clone-referenced-element|@react-native-community/async-storage/.*|expo(nent)?|@expo(nent)?/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|@sentry/.*|sentry-expo|native-base|react-native-multi-slider|@ptomasroos/.*)"
    ],
    "setupFilesAfterEnv": [
      "<rootDir>/unit_tests/setupTests.js"
    ],
    "testMatch": [
      "<rootDir>/unit_tests/**/*.test.js?(x)"
    ]
  ,
  "detox": 
    "test-runner": "jest",
    "configurations": 
      "ios.sim": 
        "binaryPath": "<app_name>.app",
        "type": "ios.simulator",
        "name": "iPhone 11 Pro Max"
      
    
  

预期行为

运行detox test 应该会在模拟器中打开应用并执行测试。

环境(请填写以下信息): 排毒:17.4.5 反应原生:0.61 节点:v14.5.0 设备:iOS 模拟器 iPhone 11 pro max Xcode:11.3.1(使用 expo 进行开发) iOS:13.3 macOS:10.14.4

日志

如果您在测试中遇到超时 [x] 我已按照Lower-level Idling Resources Debug 下的说明进行操作,并提供以下日志:

尝试运行detox test --debug-synchronization 200

终端挂起,输出如下

detox[16107] INFO:  [test.js] debugSynchronization=200 reportSpecs=true useCustomLogger=true forceAdbInstall=false DETOX_START_TIMESTAMP=1599257790958 node_modules/.bin/jest --config e2e/config.json '--testNamePattern=^((?!:android:).)*$' --maxWorkers 1 e2e
detox[16109] INFO:  at e2e/tests/Auth/login.spec.js:11:11 
 describe(Auth)
detox[16109] INFO:  at e2e/init.js:21:19 
 beforeAll
detox[16109] INFO:  [DetoxServer.js] server listening on localhost:62081...
detox[16109] INFO:  at e2e/init.js:28:19 
 initialized

 RUNS  e2e/tests/Auth/login.spec.js

尝试添加“detoxPrintBusyIdleResources”

终端挂起并输出“使用“category == “EarlGreyStatistics””过滤日志数据”

尝试添加“disableSynchroniztion”。

运行detox test 后,测试代码似乎停止在“await device.disableSynchronization”(下一行代码永远不会调用控制台日志)

设备和详细排毒日志 [x] 我已经使用 --loglevel trace 参数运行了我的测试,并在下面提供了详细日志:
detox[15678] INFO:  [test.js] configuration="ios.sim" loglevel="verbose" cleanup=true reportSpecs=true useCustomLogger=true forceAdbInstall=false DETOX_START_TIMESTAMP=1599256657224 node_modules/.bin/jest --config e2e/config.json '--testNamePattern=^((?!:android:).)*$' --maxWorkers 1 e2e
detox[15680] INFO:  at e2e/tests/Auth/login.spec.js:11:11 
 describe(Auth)
detox[15680] INFO:  at e2e/init.js:21:19 
 beforeAll
detox[15680] INFO:  [DetoxServer.js] server listening on localhost:61596...
detox[15680] DEBUG: [AsyncWebSocket.js/WEBSOCKET_OPEN] opened web socket to: ws://localhost:61596
detox[15680] DEBUG: [DetoxServer.js/LOGIN] role=tester, sessionId=25a0b4f5-f767-48a9-1a95-ca18b51c4773
detox[15680] DEBUG: [DetoxServer.js/LOGIN_SUCCESS] role=tester, sessionId=25a0b4f5-f767-48a9-1a95-ca18b51c4773
detox[15680] DEBUG: [exec.js/EXEC_CMD, #0] applesimutils --list --byType "iPhone 11 Pro Max"
detox[15680] DEBUG: [exec.js/EXEC_CMD, #1] applesimutils --list --byId 0BABC374-4903-4E95-A1CB-C265C656F1D6 --maxResults 1
detox[15680] DEBUG: [exec.js/EXEC_CMD, #2] /usr/bin/xcrun simctl uninstall 0BABC374-4903-4E95-A1CB-C265C656F1D6 [BUNDLE_ID]
detox[15680] DEBUG: [exec.js/EXEC_TRY, #2] Uninstalling [BUNDLE_ID]...
detox[15680] DEBUG: [exec.js/EXEC_SUCCESS, #2] [BUNDLE_ID] uninstalled
detox[15680] DEBUG: [exec.js/EXEC_CMD, #3] /usr/bin/xcrun simctl install 0BABC374-4903-4E95-A1CB-C265C656F1D6 "/Users/bryanboyko/XCode/<app_name>.app"
detox[15680] DEBUG: [exec.js/EXEC_TRY, #3] Installing /Users/bryanboyko/XCode/<app_name>.app...
detox[15680] DEBUG: [exec.js/EXEC_SUCCESS, #3] /Users/bryanboyko/XCode/<app_name>.app installed
detox[15680] INFO:  at e2e/init.js:28:19 
 initialized
detox[15680] DEBUG: [DetoxServer.js/CANNOT_FORWARD] role=testee not connected, cannot fw action (sessionId=25a0b4f5-f767-48a9-1a95-ca18b51c4773)
detox[15680] INFO:  Auth: should show main feed after manual login
detox[15680] INFO:  at e2e/init.js:57:19 
 before each
detox[15680] DEBUG: [exec.js/EXEC_CMD, #4] /usr/bin/xcrun simctl terminate 0BABC374-4903-4E95-A1CB-C265C656F1D6 [BUNDLE_ID]
detox[15680] DEBUG: [exec.js/EXEC_TRY, #4] Terminating [BUNDLE_ID]...
detox[15680] DEBUG: [exec.js/EXEC_SUCCESS, #4] [BUNDLE_ID] terminated
detox[15680] DEBUG: [exec.js/EXEC_CMD, #5] applesimutils --byId 0BABC374-4903-4E95-A1CB-C265C656F1D6 --bundle [BUNDLE_ID] --restartSB --setPermissions location=inuse,notifications=YES
detox[15680] DEBUG: [exec.js/EXEC_TRY, #5] Trying to set permissions...
detox[15680] DEBUG: [exec.js/EXEC_SUCCESS, #5] Permissions are set
detox[15680] DEBUG: [exec.js/EXEC_CMD, #6] SIMCTL_CHILD_DYLD_INSERT_LIBRARIES="/Users/bryanboyko/Library/ExpoDetoxHook/ios/58b2f26a0f87b2136ea15b6c467bcf04a21fd6e7/ExpoDetoxHook.framework/ExpoDetoxHook:/Users/bryanboyko/Library/Detox/ios/26afbf8d93760131ef9f1ae830bc7169ba83b8b0/Detox.framework/Detox" /usr/bin/xcrun simctl launch 0BABC374-4903-4E95-A1CB-C265C656F1D6 [BUNDLE_ID] --args -detoxServer "ws://localhost:61596" -detoxSessionId "25a0b4f5-f767-48a9-1a95-ca18b51c4773" -EXKernelDisableNuxDefaultsKey "true" -detoxURLBlacklistRegex "\("http://192.168.1.19:19001/onchange","https://e.crashlytics.com/spi/v2/events"\)" -detoxURLOverride "exp://192.168.1.19:19000" -detoxSourceAppOverride "host.exp.exponent"
detox[15680] DEBUG: [exec.js/EXEC_TRY, #6] Launching [BUNDLE_ID]...
detox[15680] DEBUG: [exec.js/EXEC_CMD, #7] /usr/bin/xcrun simctl get_app_container 0BABC374-4903-4E95-A1CB-C265C656F1D6 [BUNDLE_ID]
detox[15680] INFO:  [AppleSimUtils.js] [BUNDLE_ID] launched. To watch simulator logs, run:
        /usr/bin/xcrun simctl spawn 0BABC374-4903-4E95-A1CB-C265C656F1D6 log stream --level debug --style compact --predicate 'process == "[BUNDLE_ID]"'
detox[15680] DEBUG: [DetoxServer.js/CANNOT_FORWARD] role=testee not connected, cannot fw action (sessionId=25a0b4f5-f767-48a9-1a95-ca18b51c4773)
detox[15680] DEBUG: [DetoxServer.js/LOGIN] role=testee, sessionId=25a0b4f5-f767-48a9-1a95-ca18b51c4773
detox[15680] DEBUG: [DetoxServer.js/LOGIN_SUCCESS] role=testee, sessionId=25a0b4f5-f767-48a9-1a95-ca18b51c4773
detox[15680] INFO:  at e2e/tests/Auth/login.spec.js:37:21 
 1st test
detox[15680] INFO:  Auth: should show main feed after manual login [FAIL]

detox[15680] INFO:  at e2e/init.js:73:19 
 after all
detox[15680] WARN:  [Client.js/PENDING_REQUESTS] App has not responded to the network requests below:
  (id = 1) setSyncSettings: "enabled":false
  (id = 2) invoke: "type":"expectation","predicate":"type":"id","value":"LOGIN_VIEW","expectation":"toBeVisible"
  (id = -1000) isReady: 

That might be the reason why the test "Auth should show main feed after manual login" has timed out.

detox[15680] DEBUG: [exec.js/EXEC_CMD, #8] /usr/bin/xcrun simctl shutdown 0BABC374-4903-4E95-A1CB-C265C656F1D6
detox[15680] DEBUG: [exec.js/EXEC_TRY, #8] Shutting down 0BABC374-4903-4E95-A1CB-C265C656F1D6...
detox[15680] DEBUG: [DetoxServer.js/DISCONNECT] role=tester, sessionId=25a0b4f5-f767-48a9-1a95-ca18b51c4773
detox[15680] DEBUG: [DetoxServer.js/DISCONNECT] role=testee, sessionId=25a0b4f5-f767-48a9-1a95-ca18b51c4773
detox[15680] DEBUG: [DetoxServer.js/CANNOT_FORWARD] role=tester not connected, cannot fw action (sessionId=25a0b4f5-f767-48a9-1a95-ca18b51c4773)
detox[15680] DEBUG: [exec.js/EXEC_SUCCESS, #8] 0BABC374-4903-4E95-A1CB-C265C656F1D6 shut down
detox[15680] DEBUG: [DetoxServer.js/WS_CLOSE] Detox server connections terminated gracefully
 FAIL  e2e/tests/Auth/login.spec.js (547.778s)
  Auth
    ✕ should show main feed after manual login (240426ms)

  ● Auth › should show main feed after manual login

    Timeout - Async callback was not invoked within the 300000ms timeout specified by jest.setTimeout.Error: Timeout - Async callback was not invoked within the 300000ms timeout specified by jest.setTimeout.

      at mapper (../node_modules/jest-jasmine2/build/queueRunner.js:25:45)

  ● Auth › should show main feed after manual login

    Timeout - Async callback was not invoked within the 120000ms timeout specified by jest.setTimeout.Error: Timeout - Async callback was not invoked within the 120000ms timeout specified by jest.setTimeout.

      at mapper (../node_modules/jest-jasmine2/build/queueRunner.js:25:45)

  ● Auth › should show main feed after manual login

    : Timeout - Async callback was not invoked within the 120000ms timeout specified by jest.setTimeout.Timeout - Async callback was not invoked within the 120000ms timeout specified by jest.setTimeout.

      30 | 
[private login info]
      34 | 
      35 |     // DOUBLE TAP LOGIN BUTTON

      at new Spec (../node_modules/jest-jasmine2/build/jasmine/Spec.js:116:22)
      at Suite.<anonymous> (tests/Auth/login.spec.js:32:3)
      at Object.<anonymous> (tests/Auth/login.spec.js:10:1)

detox[15680] INFO:  at e2e/init.js:21:19 
 beforeAll
detox[15680] INFO:  [DetoxServer.js] server listening on localhost:61703...
detox[15680] DEBUG: [AsyncWebSocket.js/WEBSOCKET_OPEN] opened web socket to: ws://localhost:61703
detox[15680] DEBUG: [DetoxServer.js/LOGIN] role=tester, sessionId=d7d6ad2d-d095-81b0-7955-6b83885362a3
detox[15680] DEBUG: [DetoxServer.js/LOGIN_SUCCESS] role=tester, sessionId=d7d6ad2d-d095-81b0-7955-6b83885362a3
detox[15680] DEBUG: [exec.js/EXEC_CMD, #0] applesimutils --list --byType "iPhone 11 Pro Max"
detox[15680] DEBUG: [exec.js/EXEC_CMD, #1] applesimutils --list --byId 0BABC374-4903-4E95-A1CB-C265C656F1D6 --maxResults 1
detox[15680] DEBUG: [exec.js/EXEC_CMD, #2] /usr/bin/xcrun simctl boot 0BABC374-4903-4E95-A1CB-C265C656F1D6 
detox[15680] DEBUG: [exec.js/EXEC_TRY, #2] Booting device 0BABC374-4903-4E95-A1CB-C265C656F1D6...
detox[15680] DEBUG: [exec.js/EXEC_CMD, #3] /usr/bin/xcrun simctl bootstatus 0BABC374-4903-4E95-A1CB-C265C656F1D6
detox[15680] DEBUG: [exec.js/EXEC_CMD, #4] /usr/bin/xcrun simctl io 0BABC374-4903-4E95-A1CB-C265C656F1D6 screenshot "/dev/null"
detox[15680] DEBUG: [exec.js/EXEC_CMD, #5] /usr/bin/xcrun simctl uninstall 0BABC374-4903-4E95-A1CB-C265C656F1D6 [BUNDLE_ID]
detox[15680] DEBUG: [exec.js/EXEC_TRY, #5] Uninstalling [BUNDLE_ID]...
detox[15680] DEBUG: [exec.js/EXEC_SUCCESS, #5] [BUNDLE_ID] uninstalled
detox[15680] DEBUG: [exec.js/EXEC_CMD, #6] /usr/bin/xcrun simctl install 0BABC374-4903-4E95-A1CB-C265C656F1D6 "/Users/bryanboyko/XCode/<app_name>.app"
detox[15680] DEBUG: [exec.js/EXEC_TRY, #6] Installing /Users/bryanboyko/XCode/<app_name>.app...
detox[15680] DEBUG: [exec.js/EXEC_SUCCESS, #6] /Users/bryanboyko/XCode/<app_name>.app installed
detox[15680] INFO:  at e2e/init.js:28:19 
 initialized
detox[15680] DEBUG: [DetoxServer.js/CANNOT_FORWARD] role=testee not connected, cannot fw action (sessionId=d7d6ad2d-d095-81b0-7955-6b83885362a3)

 RUNS  e2e/tests/Auth/registration.spec.js

【问题讨论】:

【参考方案1】:

我也遇到了这个问题,并且能够通过启动 Xcode 并启动一个与 detox 模拟器无关的新模拟器来解决它。我的猜测是,通过 Xcode 启动一个新的模拟器有助于解决问题。

但是,我也知道通常要避免禁用同步。所以我的第一个建议是评论它并重试。如果这不起作用,请尝试我的怪异 Xcode hack,将其注释掉并从那里开始。

作为参考,这里是关于 disableSynchronization 的文档,它应该解释为什么应该尽可能避免添加它:https://github.com/wix/detox/blob/master/docs/Troubleshooting.Synchronization.md#controlling-the-entire-synchronization-mechanism

【讨论】:

以上是关于执行“detox test”命令时,iOS 模拟器应用程序无法启动 #2305的主要内容,如果未能解决你的问题,请参考以下文章

从命令行自动执行 iOS monotouch GUI 测试

有没有办法从命令行关闭 iOS 模拟器?

iOS 模拟器在应用程序执行时是黑色的

在命令行运行 GH-Unit 时遇到 iOS 模拟器 libSystem 问题

为啥 Xcode 7 iOS 模拟器冻结?

命令行安装ipa包到手机、模拟器