9

Getting error running detox test

Below is my Package.json

{
  "name": "TDD",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest tests/**/*.spec.js"
  },
  "dependencies": {
    "react": "16.8.3",
    "react-native": "0.59.9"
  },
  "devDependencies": {
    "@babel/core": "^7.4.5",
    "@babel/runtime": "^7.4.5",
    "babel-jest": "^24.8.0",
    "detox": "^12.11.1",
    "enzyme": "^3.10.0",
    "enzyme-adapter-react-16": "^1.14.0",
    "jest": "^24.8.0",
    "metro-react-native-babel-preset": "^0.54.1",
    "react-test-renderer": "16.8.3"
  },
  "jest": {
    "preset": "react-native",
    "setupFiles": [
      "./tests/setup.js"
    ]
  },
  "detox": {
    "test-runner": "jest",
    "configurations": {
      "ios.sim.debug": {
        "binaryPath": "ios/build/Build/Products/Debug-iphonesimulator/TDD.app",
        "build": "xcodebuild -project ios/TDD.xcodeproj -scheme TDD -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build",
        "type": "ios.simulator",
        "name": "iPhone X"
      }
    }
  }
}

Getting below error:

detox[11148] INFO:  [test.js] configuration="ios.sim.debug" artifactsLocation="artifacts/ios.sim.debug.
2019-06-16 12-34-53Z" recordLogs="none" takeScreenshots="manual" recordVideos="none" recordPerformance=
"none" reportSpecs=true node_modules/.bin/jest --config=e2e/config.json --maxWorkers=1 '--testNamePatte
rn=^((?!:android:).)*$' "e2e"

detox[11149] INFO:  [DetoxServer.js] server listening on localhost:50040...

detox[11149] ERROR: [index.js/DETOX_INIT_ERROR] 

Error: app binary not found at ‘/path/TDD/ios/build/Build/Products/Debug-iphonesimulator/TDD.app', did you build it?
    at Device._getAbsolutePath (/path/TDD/node_modules/detox/src/devices/Device.js:249:13)
    at Device.prepare (/path/TDD/node_modules/detox/src/devices/Device.js:18:29)
    at Detox.init (/path/TDD/node_modules/detox/src/Detox.js:70:23)
    at process._tickCallback (internal/process/next_tick.js:68:7)
Example: should show the welcome message
Example: should show the welcome message [FAIL]

 FAIL  e2e/firstTest.spec.js
  Example
    ✕ should show the welcome message (3ms)

  ● Example › should show the welcome message

    app binary not found at ‘/path/TDD/ios/build/Build/Products/Debug-iphonesimulator/TDD.app', did you build it?

      at Device._getAbsolutePath (../node_modules/detox/src/devices/Device.js:249:13)
      at Device.prepare (../node_modules/detox/src/devices/Device.js:18:29)
      at Detox.init (../node_modules/detox/src/Detox.js:70:23)

  ● Example › should show the welcome message

    ReferenceError: device is not defined

      1 | describe('Example', () => {
      2 |   beforeEach(async () => {
    > 3 |     await device.reloadReactNative();
        |           ^
      4 |   });
      5 | 
      6 |   it('should show the welcome message', async () => {

      at device (firstTest.spec.js:3:11)
      at tryCatch (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:45:40)
      at Generator.invoke [as _invoke] (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:271:22)
      at Generator.prototype.(anonymous function) [as next] (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:97:21)
      at tryCatch (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:45:40)
      at invoke (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:135:20)
      at ../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:170:11
      at callInvokeWithMethodAndArg (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:169:16)
      at AsyncIterator.enqueue (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:192:13)
      at AsyncIterator.prototype.(anonymous function) [as next] (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:97:21)
      at Object.<anonymous>.exports.async (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:216:14)
      at Object._callee (firstTest.spec.js:2:14)

  ● Example › should show the welcome message

    ReferenceError: element is not defined

      4 |   });
      5 | 
    > 6 |   it('should show the welcome message', async () => {
        |                                         ^
      7 |     await expect(element(by.id('welcome'))).toBeVisible();
      8 |   });
      9 | });

      at _callee2$ (firstTest.spec.js:6:41)
      at tryCatch (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:45:40)
      at Generator.invoke [as _invoke] (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:271:22)
      at Generator.prototype.(anonymous function) [as next] (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:97:21)
      at tryCatch (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:45:40)
      at invoke (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:135:20)
      at ../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:170:11
      at callInvokeWithMethodAndArg (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:169:16)
      at AsyncIterator.enqueue (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:192:13)
      at AsyncIterator.prototype.(anonymous function) [as next] (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:97:21)
      at Object.<anonymous>.exports.async (../node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:216:14)
      at Object._callee2 (firstTest.spec.js:6:41)

detox[11148] ERROR: [cli.js] Error: Command failed: node_modules/.bin/jest --config=e2e/config.json --m
axWorkers=1 '--testNamePattern=^((?!:android:).)*$' "e2e"

e2e -> init.js

const detox = require('detox');
const config = require('../package.json').detox;
const adapter = require('detox/runners/jest/adapter');
const specReporter = require('detox/runners/jest/specReporter');

// Set the default timeout
jest.setTimeout(120000);
jasmine.getEnv().addReporter(adapter);

// This takes care of generating status logs on a per-spec basis. By default, jest only reports at file-level.
// This is strictly optional.
jasmine.getEnv().addReporter(specReporter);

beforeAll(async () => {
  await detox.init(config);
});

beforeEach(async () => {
  await adapter.beforeEach();
});

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

firstTest.Spec.js

describe('Example', () => {
  beforeEach(async () => {
    await device.reloadReactNative();
  });

  it('should show the welcome message', async () => {
    await expect(element(by.id('welcome'))).toBeVisible();
  });
});
JiteshW
  • 2,195
  • 4
  • 32
  • 61

1 Answers1

0

If you can successfully run detox build then try to do this:

  1. Check that your build's output binary is in the directory you specify in binaryPath in package.json
  2. Change display name of your app in Xcode and change it accordingly in binaryPath
  3. Run detox build and detox test
  4. Change your app's display name back in Xcode and in package.json
  5. Run detox build and detox test

It worked for me

Makar
  • 83
  • 2
  • 11