我正在使用 Detox 对 React Native 应用程序进行端到端测试。当我使用
detox test
命令运行测试时,测试套件无法执行,并且我从 telnet 客户端收到“未收到响应”错误。这发生在我的 Android 模拟器上,错误如下所示:
我已确保我的模拟器正在运行并且在 adb 设备中可见。 APK 似乎安装正确,我可以在模拟器上手动打开该应用程序,没有任何问题。特别是在运行排毒测试时,问题就会出现。
这是我用来执行测试的命令:
detox test --configuration android.emu.debug
我正在 Windows 计算机上运行这些测试。
为了帮助诊断问题,这是我的
.detoxrc.js
和 jest.config.js
。
.detoxrc.js
/** @type {Detox.DetoxConfig} */
module.exports = {
testRunner: {
args: {
'$0': 'jest',
config: 'e2e/jest.config.js'
},
jest: {
setupTimeout: 120000
}
},
apps: {
'ios.debug': {
type: 'ios.app',
binaryPath: 'ios/build/Build/Products/Debug-iphonesimulator/copipet.app',
build: 'xcodebuild -workspace ios/copipet.xcworkspace -scheme copipet -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build'
},
'ios.release': {
type: 'ios.app',
binaryPath: 'ios/build/Build/Products/Release-iphonesimulator/copipet.app',
build: 'xcodebuild -workspace ios/copipet.xcworkspace -scheme copipet -configuration Release -sdk iphonesimulator -derivedDataPath ios/build'
},
'android.debug': {
type: 'android.apk',
binaryPath: 'android/app/build/outputs/apk/debug/app-debug.apk',
build: 'cd android && gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug',
reversePorts: [
8081
]
},
'android.release': {
type: 'android.apk',
binaryPath: 'android/app/build/outputs/apk/release/app-release.apk',
build: 'cd android && gradlew assembleRelease assembleAndroidTest -DtestBuildType=release'
}
},
devices: {
simulator: {
type: 'ios.simulator',
device: {
type: 'iPhone 15'
}
},
attached: {
type: 'android.attached',
device: {
adbName: '.*'
}
},
emulator: {
type: 'android.emulator',
device: {
avdName: 'Pixel_3a_API_30_x86'
}
}
},
configurations: {
'ios.sim.debug': {
device: 'simulator',
app: 'ios.debug'
},
'ios.sim.release': {
device: 'simulator',
app: 'ios.release'
},
'android.att.debug': {
device: 'attached',
app: 'android.debug'
},
'android.att.release': {
device: 'attached',
app: 'android.release'
},
'android.emu.debug': {
device: 'emulator',
app: 'android.debug'
},
'android.emu.release': {
device: 'emulator',
app: 'android.release'
}
}
};
jest.config.js
/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
rootDir: '..',
testMatch: ['<rootDir>/e2e/**/*.test.js'],
testTimeout: 120000,
maxWorkers: 1,
globalSetup: 'detox/runners/jest/globalSetup',
globalTeardown: 'detox/runners/jest/globalTeardown',
reporters: ['detox/runners/jest/reporter'],
testEnvironment: 'detox/runners/jest/testEnvironment',
verbose: true,
};
完整的日志文件
PS C:\Users\ricar\Documents\GitHub\T-ESP-900-esp902-56260-CopiPet-4\CopiPet> detox test --configuration android.emu.debug --loglevel trace
10:52:23.015 detox[16268] B lifecycle node_modules\detox\local-cli\cli.js test --configuration android.emu.debug --loglevel trace
data: {
"id": "79528ced-605f-7d8b-c315-b1ef1f46da3b",
"detoxConfig": {
"configurationName": "android.emu.debug",
"apps": {
"default": {
"type": "android.apk",
"binaryPath": "android/app/build/outputs/apk/debug/app-debug.apk",
"build": "cd android && gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug",
"reversePorts": [
8081
]
}
},
"artifacts": {
"rootDir": "artifacts\\android.emu.debug.2024-04-12 08-52-23Z",
"plugins": {
"log": {
"enabled": false,
"keepOnlyFailedTestsArtifacts": false
},
"screenshot": {
"enabled": true,
"shouldTakeAutomaticSnapshots": false,
"keepOnlyFailedTestsArtifacts": false
},
"video": {
"enabled": false,
"keepOnlyFailedTestsArtifacts": false
},
"instruments": {
"enabled": false,
"keepOnlyFailedTestsArtifacts": false
},
"uiHierarchy": {
"enabled": false,
"keepOnlyFailedTestsArtifacts": false
}
}
},
"behavior": {
"init": {
"keepLockFile": false,
"reinstallApp": true,
"exposeGlobals": true
},
"cleanup": {
"shutdownDevice": false
},
"launchApp": "auto"
},
"cli": {
"configuration": "android.emu.debug",
"loglevel": "trace",
"start": true
},
"device": {
"type": "android.emulator",
"device": {
"avdName": "Pixel_3a_API_30_x86"
}
},
"logger": {
"level": "trace",
"overrideConsole": true,
"options": {
"showLoggerName": true,
"showPid": true,
"showLevel": false,
"showMetadata": false,
"basepath": "C:\\Users\\ricar\\Documents\\GitHub\\T-ESP-900-esp902-56260-CopiPet-4\\CopiPet\\node_modules\\detox\\src",
"prefixers": {},
"stringifiers": {}
}
},
"testRunner": {
"retries": 0,
"forwardEnv": false,
"detached": false,
"bail": false,
"jest": {
"setupTimeout": 120000,
"teardownTimeout": 30000,
"retryAfterCircusRetries": false,
"reportWorkerAssign": true
},
"args": {
"$0": "jest",
"_": [],
"config": "e2e/jest.config.js",
"--": []
}
},
"session": {
"autoStart": true,
"debugSynchronization": 10000
}
},
"detoxIPCServer": "primary-16268",
"testResults": [],
"testSessionIndex": 0,
"workersCount": 0
}
10:52:23.064 detox[16268] i ipc Server path not specified, so defaulting to ipc.config.socketRoot + ipc.config.appspace + ipc.config.id /tmp/detox.primary-16268
10:52:23.066 detox[16268] i ipc starting server on /tmp/detox.primary-16268
10:52:23.066 detox[16268] i ipc starting TLS server false
10:52:23.067 detox[16268] i ipc starting server as Unix || Windows Socket
10:52:23.072 detox[16268] i ws-server Detox server listening on localhost:50900...
10:52:23.078 detox[16268] i lifecycle Serialized the session state at: C:\Users\ricar\AppData\Local\Temp\79528ced-605f-7d8b-c315-b1ef1f46da3b.detox.json
10:52:23.081 detox[16268] B lifecycle jest --config e2e/jest.config.js
Determining test suites to run...10:52:24.067 detox[10696] i ipc Service path not specified, so defaulting to ipc.config.socketRoot + ipc.config.appspace + id
10:52:24.076 detox[10696] i ipc requested connection to primary-16268 /tmp/detox.primary-16268
10:52:24.077 detox[10696] i ipc Connecting client on Unix Socket : /tmp/detox.primary-16268
10:52:24.078 detox[16268] i ipc ## socket connection to server detected ##
10:52:24.079 detox[10696] i ipc retrying reset
10:52:24.081 detox[10696] i ipc dispatching event to primary-16268 /tmp/detox.primary-16268 : registerContext , { id: 'secondary-10696' }
10:52:24.084 detox[16268] i ipc received event of : registerContext { id: 'secondary-10696' }
10:52:24.085 detox[16268] i ipc dispatching event to socket : registerContextDone {
testResults: [],
testSessionIndex: 0,
unsafe_earlyTeardown: undefined
}
10:52:24.087 detox[10696] i ipc ## received events ##
10:52:24.089 detox[10696] i ipc detected event registerContextDone { testResults: [], testSessionIndex: 0 }
10:52:24.245 detox[10696] B lifecycle e2e\welcomeScreen.test.js
10:52:24.270 detox[10696] B lifecycle set up environment
10:52:24.273 detox[10696] i ipc dispatching event to primary-16268 /tmp/detox.primary-16268 : registerWorker , { workerId: 'w1' }
10:52:24.274 detox[16268] i ipc received event of : registerWorker { workerId: 'w1' }
RUNS e2e/welcomeScreen.test.js
10:52:24.274 detox[16268] i ipc dispatching event to socket : registerWorkerDone { workersCount: 1 }
10:52:24.275 detox[10696] i ipc ## received events ## all known sockets listening to \\.\pipe\tmp-detox.primary-16268 : sessionStateUpd
10:52:24.276 detox[10696] i ipc detected event registerWorkerDone { workersCount: 1 }
10:52:24.497 detox[10696] i ipc ## received events ##
10:52:24.500 detox[10696] i ipc detected event sessionStateUpdate { workersCount: 1 }
10:52:24.512 detox[10696] i ws-client opened web socket to: ws://localhost:50900
10:52:24.519 detox[10696] i ws-client send message
data: {"type":"login","params":{"sessionId":"187f239b-5bcd-63d0-ac29-7279306bc25e","role":"tester"},"messageId":0}
RUNS e2e/welcomeScreen.test.js
10:52:24.522 detox[16268] i ws-server@50902 get
data: {"type":"login","params":{"sessionId":"187f239b-5bcd-63d0-ac29-7279306bc25e","role":"tester"},"messageId":0}
10:52:24.523 detox[16268] i ws-server created session 187f239b-5bcd-63d0-ac29-7279306bc25e
10:52:24.524 detox[16268] i ws-server@50902 send
data: {
"type": "loginSuccess",
"params": {
"testerConnected": true,
"appConnected": false
},
"messageId": 0
10:52:24.528 detox[10696] i ws-client get message
data: {"type":"loginSuccess","params":{"testerConnected":true,"appConnected":false},"messageId":0}
10:52:24.621 detox[10696] i ipc dispatching event to primary-16268 /tmp/detox.primary-16268 : allocateDevice , {
deviceConfig: {
type: 'android.emulator',
device: { avdName: 'Pixel_3a_API_30_x86' }
}
}
RUNS e2e/welcomeScreen.test.js
10:52:24.622 detox[16268] i ipc received event of : allocateDevice {
deviceConfig: {
type: 'android.emulator',
device: { avdName: 'Pixel_3a_API_30_x86' }
}
}
10:52:24.685 detox[16268] B device init
args: ()
10:52:24.689 detox[16268] E device init
10:52:24.690 detox[16268] B device@0 allocate
data: {
"type": "android.emulator",
"device": {
"avdName": "Pixel_3a_API_30_x86"
}
}
10:52:24.691 detox[16268] i child-process:EXEC_CMD "C:\Users\ricar\AppData\Local\Android\Sdk\emulator\emulator.EXE" -list-avds --verbose
10:52:24.739 detox[16268] i child-process:EXEC_SUCCESS INFO | Storing crashdata in: C:\Users\ricar\AppData\Local\Temp\\AndroidEmulator\emu-crash-34.1.20.db, detection is enabled for process: 5004
Pixel_3a_API_30_x86
10:52:24.740 detox[16268] i child-process:EXEC_CMD "C:\Users\ricar\AppData\Local\Android\Sdk\emulator\emulator.EXE" -version
10:52:24.938 detox[16268] i child-process:EXEC_SUCCESS INFO | Storing crashdata in: C:\Users\ricar\AppData\Local\Temp\\AndroidEmulator\emu-crash-34.1.20.db, detection is enabled for process: 9112
INFO | Duplicate loglines will be removed, if you wish to see each individual line launch with the -log-nofilter flag.
Android emulator version 34.1.20.0 (build_id 11610631) (CL:N/A)
Copyright (C) 2006-2017 The Android Open Source Project and many others.
This program is a derivative of the QEMU CPU emulator (www.qemu.org).
This software is licensed under the terms of the GNU General Public
License version 2, as published by the Free Software Foundation, and
may be copied, distributed, and modified under those terms.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
INFO | Storing crashdata in: C:\Users\ricar\AppData\Local\Temp\\AndroidEmulator\emu-crash-34.1.20.db, detection is enabled for process: 11180
INFO | Android emulator version 34.1.20.0 (build_id 11610631) (CL:N/A)
10:52:24.941 detox[16268] i device Detected emulator binary version { major: 34, minor: 1, patch: 20, toString: [Function: toString] }
10:52:24.942 detox[16268] i child-process:EXEC_CMD "C:\Users\ricar\AppData\Local\Android\Sdk\platform-tools\adb.EXE" devices
10:52:24.975 detox[16268] i child-process:EXEC_SUCCESS List of devices attached
emulator-12070 device
RUNS e2e/welcomeScreen.test.js
10:52:26.494 detox[16268] i device:TELNET_TIMEOUT
10:52:26.496 detox[16268] E device@0 allocate
error: Error: response not received
at Timeout._onTimeout (C:\Users\ricar\Documents\GitHub\T-ESP-900-esp902-56260-CopiPet-4\CopiPet\node_modules\telnet-client\lib\index.js:169:20)
at listOnTimeout (node:internal/timers:569:17)
at process.processTimers (node:internal/timers:512:7)
10:52:26.498 detox[16268] i ipc dispatching event to socket : allocateDeviceDone {
error: {
name: 'Error',
message: 'response not received',
stack: 'Error: response not received\n' +
' at Timeout._onTimeout (C:\\Users\\ricar\\Documents\\GitHub\\T-ESP-900-esp902-56260-CopiPet-4\\CopiPet\\node_modules\\telnet-client\\lib\\index.js:169:20)\n' +
' at listOnTimeout (node:internal/timers:569:17)\n' +
' at process.processTimers (node:internal/timers:512:7)'
10:52:26.500 detox[10696] i ipc ## received events ##
10:52:26.501 detox[10696] i ipc detected event allocateDeviceDone {
error: {
name: 'Error',
message: 'response not received',
stack: 'Error: response not received\n' +
' at Timeout._onTimeout (C:\\Users\\ricar\\Documents\\GitHub\\T-ESP-900-esp902-56260-CopiPet-4\\CopiPet\\node_modules\\telnet-client\\lib\\index.js:169:20)\n' +
' at listOnTimeout (node:internal/timers:569:17)\n' +
' at process.processTimers (node:internal/timers:512:7)'
}
}
10:52:26.504 detox[10696] E lifecycle set up environment
error: Error: response not received
at Timeout._onTimeout (C:\Users\ricar\Documents\GitHub\T-ESP-900-esp902-56260-CopiPet-4\CopiPet\node_modules\telnet-client\lib\index.js:169:20)
at listOnTimeout (node:internal/timers:569:17)
at process.processTimers (node:internal/timers:512:7)
10:52:26.506 detox[10696] B lifecycle tear down environment
10:52:26.507 detox[10696] B artifacts-manager onBeforeCleanup
args: ()
10:52:26.511 detox[10696] E artifacts-manager onBeforeCleanup
10:52:26.515 detox[10696] E lifecycle tear down environment
10:52:26.515 detox[16268] E ws-server@50902 connection :50900<->:50902
10:52:26.516 detox[10696] E lifecycle e2e\welcomeScreen.test.js
FAIL e2e/welcomeScreen.test.js
● Test suite failed to run
response not received
at Timeout._onTimeout (node_modules/telnet-client/lib/index.js:169:20)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 2.42 s
Ran all test suites.
10:52:26.538 detox[10696] i ipc dispatching event to primary-16268 /tmp/detox.primary-16268 : reportTestResults , {
testResults: [
{
success: false,
testFilePath: 'C:\\Users\\ricar\\Documents\\GitHub\\T-ESP-900-esp902-56260-CopiPet-4\\CopiPet\\e2e\\welcomeScreen.test.js',
testExecError: {
name: 'Error',
message: 'response not received',
stack: 'Error: response not received\n' +
' at Timeout._onTimeout (C:\\Users\\ricar\\Documents\\GitHub\\T-ESP-900-esp902-56260-CopiPet-4\\CopiPet\\node_modules\\telnet-client\\lib\\index.js:169:20)\n' +
' at listOnTimeout (node:internal/timers:569:17)\n' +
' at process.processTimers (node:internal/timers:512:7)'
},
isPermanentFailure: false
}
]
}
10:52:26.541 detox[16268] i ipc received event of : reportTestResults {
testResults: [
{
success: false,
testFilePath: 'C:\\Users\\ricar\\Documents\\GitHub\\T-ESP-900-esp902-56260-CopiPet-4\\CopiPet\\e2e\\welcomeScreen.test.js',
testExecError: {
name: 'Error',
message: 'response not received',
stack: 'Error: response not received\n' +
' at Timeout._onTimeout (C:\\Users\\ricar\\Documents\\GitHub\\T-ESP-900-esp902-56260-CopiPet-4\\CopiPet\\node_modules\\telnet-client\\lib\\index.js:169:20)\n' +
' at listOnTimeout (node:internal/timers:569:17)\n' +
' at process.processTimers (node:internal/timers:512:7)'
},
isPermanentFailure: false
}
]
}
10:52:26.543 detox[16268] i ipc dispatching event to socket : reportTestResultsDone {
testResults: [
{
success: false,
testFilePath: 'C:\\Users\\ricar\\Documents\\GitHub\\T-ESP-900-esp902-56260-CopiPet-4\\CopiPet\\e2e\\welcomeScreen.test.js',
testExecError: {
name: 'Error',
message: 'response not received',
stack: 'Error: response not received\n' +
' at Timeout._onTimeout (C:\\Users\\ricar\\Documents\\GitHub\\T-ESP-900-esp902-56260-CopiPet-4\\CopiPet\\node_modules\\telnet-client\\lib\\index.js:169:20)\n' +
' at listOnTimeout (node:internal/timers:569:17)\n' +
' at process.processTimers (node:internal/timers:512:7)'
},
isPermanentFailure: false
}
]
}
10:52:26.545 detox[10696] i ipc ## received events ##
10:52:26.545 detox[16268] i ipc broadcasting event to all known sockets listening to \\.\pipe\tmp-detox.primary-16268 : sessionStateUpdate {
testResults: [
{
success: false,
testFilePath: 'C:\\Users\\ricar\\Documents\\GitHub\\T-ESP-900-esp902-56260-CopiPet-4\\CopiPet\\e2e\\welcomeScreen.test.js',
testExecError: {
name: 'Error',
message: 'response not received',
stack: 'Error: response not received\n' +
' at Timeout._onTimeout (C:\\Users\\ricar\\Documents\\GitHub\\T-ESP-900-esp902-56260-CopiPet-4\\CopiPet\\node_modules\\telnet-client\\lib\\index.js:169:20)\n' +
' at listOnTimeout (node:internal/timers:569:17)\n' +
' at process.processTimers (node:internal/timers:512:7)'
},
isPermanentFailure: false
}
]
}
10:52:26.547 detox[10696] i ipc detected event reportTestResultsDone {
testResults: [
{
success: false,
testFilePath: 'C:\\Users\\ricar\\Documents\\GitHub\\T-ESP-900-esp902-56260-CopiPet-4\\CopiPet\\e2e\\welcomeScreen.test.js',
testExecError: {
name: 'Error',
message: 'response not received',
stack: 'Error: response not received\n' +
' at Timeout._onTimeout (C:\\Users\\ricar\\Documents\\GitHub\\T-ESP-900-esp902-56260-CopiPet-4\\CopiPet\\node_modules\\telnet-client\\lib\\index.js:169:20)\n' +
' at listOnTimeout (node:internal/timers:569:17)\n' +
' at process.processTimers (node:internal/timers:512:7)'
},
isPermanentFailure: false
}
]
}
10:52:26.553 detox[10696] i ipc connection closed primary-16268 /tmp/detox.primary-16268 0 tries remaining of 0
10:52:26.552 detox[16268] i ipc socket disconnected secondary-10696
10:52:26.553 detox[10696] i ipc secondary-10696 exceeded connection rety amount of or stopRetrying flag set.
10:52:26.664 detox[16268] E lifecycle Command failed with exit code = 1:
jest --config e2e/jest.config.js
10:52:26.665 detox[16268] B device cleanup
args: ()
10:52:26.667 detox[16268] E device cleanup
10:52:26.668 detox[16268] i ws-server Detox server has been closed gracefully
10:52:26.670 detox[16268] E lifecycle node_modules\detox\local-cli\cli.js test --configuration android.emu.debug --loglevel trace
它帮助了我:
rm ~/.emulator_console_auth_token