在 Expo React Native 托管应用程序中为 E2E 测试设置 Detox 的问题

问题描述 投票:0回答:0

我正在尝试将 E2E 测试与我的 Expo React Native 托管应用程序集成,但我还没有成功。我希望能够在本地运行 E2E 测试,这就是为什么我在本地构建应用程序,然后让 Detox 将它与测试运行器一起安装在我的 Android 设备(不是模拟器)上,但它不会启动。

安装应用程序和测试运行程序后出现以下错误:

Failed to run application on the device

    HINT: Most likely, your main activity has crashed prematurely.

    Native stacktrace dump:
    java.lang.RuntimeException: Could not launch intent Intent { act=android.intent.action.MAIN flg=0x14000000 cmp=com.nockwellness.dev/.MainActivity (has extras) } within 45000 milliseconds. Perhaps the main thread has not gone idle within a reasonable amount of time? There could be an animation or something constantly repainting the screen. Or the activity is doing network calls on creation? See the threaddump logs. For your reference the last time the event queue was idle before your activity launch request was 1683578221739 and now the last time the queue went idle was: 1683578221739. If these numbers are the same your activity might be hogging the event queue.

我的流程如下:

  1. 使用
    eas build -e test -p android --local
    构建应用程序。这会创建两个 .apk 文件,一个是实际的应用程序,另一个是我认为的测试运行程序。我在 eas.json 中为此配置文件设置的配置如下:
{
  ...
  "build": {
    ...
    "test": {
            "distribution": "internal",
            "channel": "staging",
            "android": {
                "gradleCommand": ":app:assembleRelease :app:assembleAndroidTest -DtestBuildType=release",
                "withoutCredentials": true
            },
            "ios": {
                "simulator": true
            },
            "env": {
                "CHANNEL": "staging"
            }
        },
    ...
    }
  ...
}
  1. 提取由上述命令生成的 tar.gz,这导致在我的项目根目录中将以下路径添加到提到的 .apk 文件中:a)

    androidTest/release/app-release-androidTest.apk
    ; b)
    release/app-release.apk
    .

  2. detox test --configuration android.attached.release
    。我使用的配置文件如下:

{
    logger: {
        level: process.env.CI ? 'debug' : undefined,
    },
    testRunner: {
        args: {
            $0: 'jest',
            config: 'e2e/jest.config.js',
        },
        jest: {
            setupTimeout: 120000,
        },
    },
    artifacts: {
        plugins: {
            log: process.env.CI ? 'failing' : undefined,
            screenshot: 'failing',
        },
    },
    apps: {
        'android.release': {
            type: 'android.apk',
            build: 'cd android && ./gradlew :app:assembleRelease :app:assembleAndroidTest -DtestBuildType=release && cd ..',
            binaryPath: 'release/app-release.apk',
            testBinaryPath: 'androidTest/release/app-release-androidTest.apk',
        },
    },
    devices: {
        attached: {
            type: 'android.attached',
            device: {
                adbName: '.*',
            },
        },
    },
    configurations: {
        'android.attached.release': {
            device: 'attached',
            app: 'android.release',
        },
    },
};

所有这些都会导致上面提到的“无法在设备上运行应用程序”错误。正如我所说,完成此过程后,应用程序实际上安装在我的设备上并正常运行,但 Detox 无法打开它,我不知道为什么。安装后,什么都没有发生,我的设备保持静止,当应用程序至少应该尝试启动时,就像什么都没有发生一样。

reactjs react-native expo e2e-testing detox
© www.soinside.com 2019 - 2024. All rights reserved.