簡體   English   中英

DetoxRuntimeError:Detox 似乎無法連接到測試應用程序! - 僅限 Android

[英]DetoxRuntimeError: Detox can't seem to connect to the test app(s)! - Android only

我對裸 React Native 項目使用 Detox 自動化工具。 在 iOS 上一切正常,但是當我在 Android 上運行測試時,出現以下錯誤:

DetoxRuntimeError:Detox 似乎無法連接到測試應用程序:提示。 您是否忘記在測試開始時調用“device?launchApp()”,請參閱我們的故障排除指南:了解完整詳細信息: https://wix.github.io/Detox/docs/troubleshooting/running-tests#tests -執行掛起

DetoxRuntimeError:由於以下錯誤,未決請求 #9(“invoke”)已被拒絕:應用程序已意外斷開與 Detox 服務器的連接。

一些測試有綠色狀態。 測試在多個模擬器上並行運行。


以下是我的排毒配置:

/detoxrc.json

{
 "testRunner": "jest",
 "runnerConfig": "e2e/config.js",
 "skipLegacyWorkersInjection": true,
 "apps": {
  "ios": {
    "type": "ios.app",
    "binaryPath": "ios/build/Build/Products/Debug-iphonesimulator/ProjectName.app",
    "build": "RN_SRC_EXT=e2e.js xcodebuild -workspace ios/ProjectName.xcworkspace -scheme ProjectName -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build -UseModernBuildSystem=YES -destination 'platform=iOS Simulator,name=iPhone 11'"
  },
  "android": {
    "type": "android.apk",
    "binaryPath": "android/app/build/outputs/apk/release/app-release.apk",
    "testBinaryPath": "android/app/build/outputs/apk/androidTest/release/app-release-androidTest.apk",
    "build": "cd android && RN_SRC_EXT=e2e.js ./gradlew clean assembleRelease assembleAndroidTest -DtestBuildType=release && cd .."
  }
},
"devices": {
  "simulator": {
    "type": "ios.simulator",
    "device": {
      "type": "iPhone 11"
    }
  },
  "emulator": {
    "type": "android.emulator",
    "device": {
      "avdName": "Pixel_XL"
    }
  }
},
"configurations": {
  "ios": {
    "device": "simulator",
    "app": "ios"
  },
  "android": {
    "device": "emulator",
    "app": "android"
  }
 }
}

/e2e/config.js

module.exports = {
preset: 'react-native',
setupFilesAfterEnv: ["./init.js"],
setupFiles: [
  "<rootDir>/../node_modules/react-native/jest/setup.js",
],
testPathIgnorePatterns: ["/node_modules/"],
testMatch: [
  "<rootDir>/*.e2e.js"
],
transformIgnorePatterns: [
  'node_modules/(?!(jest-)?@react-native|react-native|@react-native-community|@react-navigation)'
  ],
 };

/e2e/init.js - 環境設置后運行的文件

import detox from 'detox';
import packageFile from '../package.json';
const detoxConfig = packageFile.detox;

jest.setTimeout(120000);

beforeAll(async () => {
   await detox.init(detoxConfig, { launchApp: false });
   await device.launchApp();
});

afterAll(async () => {
   await detox.cleanup();
});

beforeEach(async () => {
   await device.reloadReactNative();
});

和測試文件看起來類似於這個:

describe('some-screen-description', () => {
    beforeEach(async () => {
        await logInPage.tapLogInButton();
    });

   it('description', async () => {
        await nextScreen.performAction();
   });

});

/package.json

"detox": {
    "test-runner": "jest",
    "runner-config": "e2e/config.js"
  }

我使用以下版本的排毒: “排毒”:“^19.6.9”。

我使用帶有M1處理器的Macbook Pro 建議任何提示。

誰能確認安裝 APK 和測試 APK 可能有問題? 我不知道如何檢查兩者是否已安裝。

在你的beforeAll鈎子中的 init.js 中,第一行在做什么? 您是否嘗試刪除該行?

關於您正在安裝的 apk,如果它們沒有正確安裝,您會收到不同的錯誤消息(例如找不到 apk,您是否在它之前運行了 detox build? )。 並且還查看您的配置文件 + detox build 命令,我確定 apk 已構建並且它們位於正確的位置。 要仔細檢查,您可以 go 到您的 android 構建 output 目錄(請參閱排毒配置中的binaryPathtestBinaryPath中提到的路徑)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM