问题
虽然我的 detox 在 iOS 上运行良好,但我的 react-native android detox build 在通过 detox cli 打开时会启动一个空白屏幕。
在这种状态下可能不值得一提cmd + m
或重新加载。rr
包.json
"react-native": "0.51.0",
...
"detox": "^7.0.0-alpha.0",
...
"android.emu.debug": {
"binaryPath": "android/app/build/outputs/apk/debug/app-debug.apk",
"build": "cd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug && cd ..",
"type": "android.emulator",
"name": "Nexus_5X_API_26"
},
故障排除
跑步时
detox test -c android.emu.debug --loglevel verbose
android apk 安装,启动,但卡在空白屏幕。
排毒日志
detox info 15:26:02: server listening on localhost:63324...
detox verb ws onOpen [object Object]
detox verb ws send: {"type":"login","params":{"sessionId":"300068b9-c44f-8b8a-81cb-73f8c66b0752","role":"tester"},"messageId":0}
detox verb ws onMessage: {"type":"loginSuccess","params":{"sessionId":"300068b9-c44f-8b8a-81cb-73f8c66b0752","role":"tester"},"messageId":0}
detox verb ws
detox verb 1: /Users/me/Library/Android/sdk/tools/emulator -list-avds --verbose
detox verb 1: stdout: Nexus_5X_API_26
detox verb 1: stdout:
detox verb /Users/me/Library/Android/sdk/tools/emulator -verbose -gpu host -no-audio @Nexus_5X_API_26
detox verb 2: /Users/me/Library/Android/sdk/platform-tools/adb devices
detox verb 2: stdout: List of devices attached
detox verb 2: stdout: emulator-5554 device
detox verb 2: stdout:
detox verb 2: stdout:
detox verb 3: /Users/me/Library/Android/sdk/platform-tools/adb -s emulator-5554 shell getprop dev.bootcomplete
detox verb 3: stdout: 1
detox verb 3: stdout:
detox verb 4: /Users/me/Library/Android/sdk/platform-tools/adb -s emulator-5554 shell input keyevent 82
detox verb adb -s emulator-5554 shell am instrument -w -r -e detoxServer ws://localhost:63324 -e detoxSessionId 300068b9-c44f-8b8a-81cb-73f8c66b0752 -e debug false com.mypackage.mobile.test/android.support.test.runner.AndroidJUnitRunner
detox verb Instrumentation spawned, childProcess.pid: 24565
detox verb ws send: {"type":"isReady","params":{},"messageId":-1000}
detox verb Instrumentation stdout: INSTRUMENTATION_STATUS: numtests=1
detox verb Instrumentation stdout: INSTRUMENTATION_STATUS: stream=
detox verb Instrumentation stdout: com.mypackage.mobile.DetoxTest:
detox verb Instrumentation stdout: INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
detox verb Instrumentation stdout: INSTRUMENTATION_STATUS: test=runDetoxTests
detox verb Instrumentation stdout: INSTRUMENTATION_STATUS: class=com.mypackage.mobile.DetoxTest
detox verb Instrumentation stdout: INSTRUMENTATION_STATUS: current=1
detox verb Instrumentation stdout:
detox verb Instrumentation stdout: INSTRUMENTATION_STATUS_CODE: 1
detox verb Instrumentation stdout:
2分钟后
detox verb Instrumentation stdout: INSTRUMENTATION_CODE: 0
detox verb Instrumentation stdout:
detox verb instrumentationProcess terminated due to receipt of signal null
1) "before all" hook: _callee
0 passing (2m)
1 failing
1) "before all" hook: _callee:
Error: Timeout of 120000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
0 passing (2m)
1 failing
1) "before all" hook: _callee:
Error: Timeout of 120000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
安卓日志
从跑步开始react-native log-android
01-17 15:11:01.053 5248 5318 D ReactNative: Initializing React Xplat Bridge.
01-17 15:11:01.055 5248 5318 D ReactNative: Initializing React Xplat Bridge before initializeBridge
01-17 15:11:01.060 5248 5318 D ReactNative: Initializing React Xplat Bridge after initializeBridge
01-17 15:11:01.061 5248 5318 D ReactNative: CatalystInstanceImpl.runJSBundle()
01-17 15:11:01.061 5248 5323 D ReactNative: ReactInstanceManager.setupReactContext()
01-17 15:11:01.061 5248 5323 D ReactNative: CatalystInstanceImpl.initialize()
01-17 15:11:01.065 5248 5323 D ReactNative: ReactInstanceManager.attachRootViewToInstance()
模拟器行为
在上述日志之后的某个时间,应用程序将超时,所以我将其杀死。当我从模拟器启动相同的应用程序(由 detox 安装的相同 apk)时,它按预期工作!
react-native log-android
当 apk 按预期启动时,来自的日志有额外的行
01-17 15:24:10.207 6447 6530 I ReactNativeJS: Running application "MyApp" with appParams: {"rootTag":1}. __DEV__ === true, development-level warning are ON, performance optimizations are OFF
在这一点上,我知道 apk 很好,所以我尝试了--reuse
flag 但同样的问题。
排毒测试.java
package com.mypackage.mobile;
import android.support.test.filters.LargeTest;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import com.wix.detox.Detox;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
@LargeTest
public class DetoxTest {
@Rule
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(MainActivity.class, false, false);
@Test
public void runDetoxTests() throws InterruptedException {
Detox.runTests(mActivityRule);
}
}
问题
有谁知道如何解决它,以便在通过 detox cli 运行时,应用程序将按预期启动,而不是我得到的空白屏幕?如果没有,我可以采取什么好的下一步措施,将启动应用程序与 DetoxTest.java 隔离开来?