Detox: Detox device/element is not defined

Hello Team 😃

Description

My app work fine, but an error appear and say element/device is not defined i found many issues :

DETOX_INIT_ERROR isn’t throw

Steps to Reproduce

See the repository clone and read to reproduce 😃 https://github.com/GuillaumeSarfati/detox-expo-issue

Detox, Node, Device, Xcode and macOS Versions

Program Version
Node v8.11.3
React v16.3.1
React Native v0.53.0
Expo v29.0.0
ExpoKit v2.7.0
Detox v8.2.3
Xcode v9.4.1
MacOS v10.13.6

Device and verbose Detox logs


$ detox test --loglevel verbose

configuration="ios.sim.debug" loglevel="verbose" artifactsLocation="artifacts/ios.sim.debug.2018-08-30 08-23-23Z" node_modules/.bin/jest e2e --config=e2e/config.json --maxWorkers=1 '--testNamePattern=^((?!:android:).)*$'
detox[89428] INFO:  [DetoxServer.js] server listening on localhost:64943...
detox[89428] DEBUG: [AsyncWebSocket.js/WEBSOCKET_OPEN] opened web socket to: ws://localhost:64943
detox[89428] DEBUG: [DetoxServer.js/LOGIN] role=tester, sessionId=d6b7276b-92cb-e6c3-c7bf-ba5102d46761
detox[89428] DEBUG: [DetoxServer.js/LOGIN_SUCCESS] role=tester, sessionId=d6b7276b-92cb-e6c3-c7bf-ba5102d46761
detox[89428] DEBUG: [exec.js/EXEC_CMD, #0] /usr/bin/xcrun simctl list -j
detox[89428] DEBUG: [exec.js/EXEC_CMD, #1] applesimutils --list --byType "iPhone X" --byOS "11.4"
detox[89428] DEBUG: [exec.js/EXEC_TRY, #1] Searching for device matching iPhone X...
detox[89428] DEBUG: [exec.js/EXEC_CMD, #2] applesimutils --list --byId "86146F25-20FE-4DC4-AB16-2867F836F275"
detox[89428] DEBUG: [exec.js/EXEC_CMD, #3] /usr/bin/xcrun simctl uninstall 86146F25-20FE-4DC4-AB16-2867F836F275 com.detox.issue
detox[89428] DEBUG: [exec.js/EXEC_TRY, #3] Uninstalling com.detox.issue...
detox[89428] DEBUG: [exec.js/EXEC_SUCCESS, #3] com.detox.issue uninstalled
detox[89428] DEBUG: [exec.js/EXEC_CMD, #4] /usr/bin/xcrun simctl install 86146F25-20FE-4DC4-AB16-2867F836F275 "/Volumes/Guillaume/Projects/detox-expo-issue/ios/build/Build/Products/Debug-iphonesimulator/detox-expo-issue.app"
detox[89428] DEBUG: [exec.js/EXEC_TRY, #4] Installing /Volumes/Guillaume/Projects/detox-expo-issue/ios/build/Build/Products/Debug-iphonesimulator/detox-expo-issue.app...
detox[89428] DEBUG: [exec.js/EXEC_SUCCESS, #4] /Volumes/Guillaume/Projects/detox-expo-issue/ios/build/Build/Products/Debug-iphonesimulator/detox-expo-issue.app installed
detox[89428] DEBUG: [exec.js/EXEC_CMD, #5] /usr/bin/xcrun simctl terminate 86146F25-20FE-4DC4-AB16-2867F836F275 com.detox.issue
detox[89428] DEBUG: [exec.js/EXEC_TRY, #5] Terminating com.detox.issue...
detox[89428] DEBUG: [exec.js/EXEC_SUCCESS, #5] com.detox.issue terminated
detox[89428] DEBUG: [exec.js/EXEC_CMD, #6] /bin/cat /dev/null >/Users/guillaumesarfati/Library/Developer/CoreSimulator/Devices/86146F25-20FE-4DC4-AB16-2867F836F275/data/tmp/detox.last_launch_app_log.out 2>/Users/guillaumesarfati/Library/Developer/CoreSimulator/Devices/86146F25-20FE-4DC4-AB16-2867F836F275/data/tmp/detox.last_launch_app_log.err && SIMCTL_CHILD_DYLD_INSERT_LIBRARIES="/Users/guillaumesarfati/Library/Detox/ios/9b1cf119d6b7b0d2bb09a9e8c56ad526925d9c30/Detox.framework/Detox" /usr/bin/xcrun simctl launch --stdout=/tmp/detox.last_launch_app_log.out --stderr=/tmp/detox.last_launch_app_log.err 86146F25-20FE-4DC4-AB16-2867F836F275 com.detox.issue --args -detoxServer ws://localhost:64943 -detoxSessionId d6b7276b-92cb-e6c3-c7bf-ba5102d46761
detox[89428] DEBUG: [exec.js/EXEC_TRY, #6] Launching com.detox.issue...
detox[89428] DEBUG: [exec.js/EXEC_SUCCESS, #6] com.detox.issue launched. The stdout and stderr logs were recreated, you can watch them with:
        tail -F /Users/guillaumesarfati/Library/Developer/CoreSimulator/Devices/86146F25-20FE-4DC4-AB16-2867F836F275/data/tmp/detox.last_launch_app_log.{out,err}
detox[89428] DEBUG: [DetoxServer.js/CANNOT_FORWARD] role=testee not connected, cannot fw action (sessionId=d6b7276b-92cb-e6c3-c7bf-ba5102d46761)
detox[89428] DEBUG: [DetoxServer.js/LOGIN] role=testee, sessionId=d6b7276b-92cb-e6c3-c7bf-ba5102d46761
detox[89428] DEBUG: [DetoxServer.js/LOGIN_SUCCESS] role=testee, sessionId=d6b7276b-92cb-e6c3-c7bf-ba5102d46761
 FAIL  e2e/firstTest.spec.js (521.184s)
  Example
    ✕ should have welcome screen (9ms)
    ✕ should show hello screen after tap (2ms)
    ✕ should show world screen after tap (3ms)

  ● Example › should have welcome screen

    Timeout - Async callback was not invoked within the 520000ms timeout specified by jest.setTimeout.

      at mapper (../node_modules/jest-jasmine2/build/queue_runner.js:41:52)

  ● Example › should have welcome screen

    ReferenceError: device is not defined

      2 | describe('Example', () => {
      3 |   beforeEach(async () => {
    > 4 |     await device.reloadReactNative();
        |           ^
      5 |   });
      6 |
      7 |   it('should have welcome screen', async () => {

      at Object.device (firstTest.spec.js:4:11)
      at tryCatch (../node_modules/regenerator-runtime/runtime.js:62:40)
      at Generator.invoke [as _invoke] (../node_modules/regenerator-runtime/runtime.js:296:22)
      at Generator.prototype.(anonymous function) [as next] (../node_modules/regenerator-runtime/runtime.js:114:21)
      at tryCatch (../node_modules/regenerator-runtime/runtime.js:62:40)
      at invoke (../node_modules/regenerator-runtime/runtime.js:152:20)
      at ../node_modules/regenerator-runtime/runtime.js:195:11
      at callInvokeWithMethodAndArg (../node_modules/regenerator-runtime/runtime.js:194:16)
      at AsyncIterator.enqueue (../node_modules/regenerator-runtime/runtime.js:217:13)
      at AsyncIterator.prototype.(anonymous function) [as next] (../node_modules/regenerator-runtime/runtime.js:114:21)
      at Object.<anonymous>.runtime.async (../node_modules/regenerator-runtime/runtime.js:241:14)
      at Object._callee (firstTest.spec.js:3:14)

  ● Example › should have welcome screen

    ReferenceError: element is not defined

       5 |   });
       6 |
    >  7 |   it('should have welcome screen', async () => {
         |                                    ^
       8 |     await expect(element(by.id('welcome'))).toBeVisible();
       9 |   });
      10 |

      at Object._callee2$ (firstTest.spec.js:7:36)
      at tryCatch (../node_modules/regenerator-runtime/runtime.js:62:40)
      at Generator.invoke [as _invoke] (../node_modules/regenerator-runtime/runtime.js:296:22)
      at Generator.prototype.(anonymous function) [as next] (../node_modules/regenerator-runtime/runtime.js:114:21)
      at tryCatch (../node_modules/regenerator-runtime/runtime.js:62:40)
      at invoke (../node_modules/regenerator-runtime/runtime.js:152:20)
      at ../node_modules/regenerator-runtime/runtime.js:195:11
      at callInvokeWithMethodAndArg (../node_modules/regenerator-runtime/runtime.js:194:16)
      at AsyncIterator.enqueue (../node_modules/regenerator-runtime/runtime.js:217:13)
      at AsyncIterator.prototype.(anonymous function) [as next] (../node_modules/regenerator-runtime/runtime.js:114:21)
      at Object.<anonymous>.runtime.async (../node_modules/regenerator-runtime/runtime.js:241:14)
      at Object._callee2 (firstTest.spec.js:7:36)

  ● Example › should show hello screen after tap

    Timeout - Async callback was not invoked within the 520000ms timeout specified by jest.setTimeout.

      at mapper (../node_modules/jest-jasmine2/build/queue_runner.js:41:52)

  ● Example › should show hello screen after tap

    ReferenceError: device is not defined

      2 | describe('Example', () => {
      3 |   beforeEach(async () => {
    > 4 |     await device.reloadReactNative();
        |           ^
      5 |   });
      6 |
      7 |   it('should have welcome screen', async () => {

      at Object.device (firstTest.spec.js:4:11)
      at tryCatch (../node_modules/regenerator-runtime/runtime.js:62:40)
      at Generator.invoke [as _invoke] (../node_modules/regenerator-runtime/runtime.js:296:22)
      at Generator.prototype.(anonymous function) [as next] (../node_modules/regenerator-runtime/runtime.js:114:21)
      at tryCatch (../node_modules/regenerator-runtime/runtime.js:62:40)
      at invoke (../node_modules/regenerator-runtime/runtime.js:152:20)
      at ../node_modules/regenerator-runtime/runtime.js:195:11
      at callInvokeWithMethodAndArg (../node_modules/regenerator-runtime/runtime.js:194:16)
      at AsyncIterator.enqueue (../node_modules/regenerator-runtime/runtime.js:217:13)
      at AsyncIterator.prototype.(anonymous function) [as next] (../node_modules/regenerator-runtime/runtime.js:114:21)
      at Object.<anonymous>.runtime.async (../node_modules/regenerator-runtime/runtime.js:241:14)
      at Object._callee (firstTest.spec.js:3:14)

  ● Example › should show hello screen after tap

    ReferenceError: element is not defined

       9 |   });
      10 |
    > 11 |   it('should show hello screen after tap', async () => {
         |                                            ^
      12 |     await element(by.id('hello_button')).tap();
      13 |     await expect(element(by.text('Hello!!!'))).toBeVisible();
      14 |   });

      at Object._callee3$ (firstTest.spec.js:11:44)
      at tryCatch (../node_modules/regenerator-runtime/runtime.js:62:40)
      at Generator.invoke [as _invoke] (../node_modules/regenerator-runtime/runtime.js:296:22)
      at Generator.prototype.(anonymous function) [as next] (../node_modules/regenerator-runtime/runtime.js:114:21)
      at tryCatch (../node_modules/regenerator-runtime/runtime.js:62:40)
      at invoke (../node_modules/regenerator-runtime/runtime.js:152:20)
      at ../node_modules/regenerator-runtime/runtime.js:195:11
      at callInvokeWithMethodAndArg (../node_modules/regenerator-runtime/runtime.js:194:16)
      at AsyncIterator.enqueue (../node_modules/regenerator-runtime/runtime.js:217:13)
      at AsyncIterator.prototype.(anonymous function) [as next] (../node_modules/regenerator-runtime/runtime.js:114:21)
      at Object.<anonymous>.runtime.async (../node_modules/regenerator-runtime/runtime.js:241:14)
      at Object._callee3 (firstTest.spec.js:11:44)

  ● Example › should show world screen after tap

    Timeout - Async callback was not invoked within the 520000ms timeout specified by jest.setTimeout.

      at mapper (../node_modules/jest-jasmine2/build/queue_runner.js:41:52)

  ● Example › should show world screen after tap

    ReferenceError: device is not defined

      2 | describe('Example', () => {
      3 |   beforeEach(async () => {
    > 4 |     await device.reloadReactNative();
        |           ^
      5 |   });
      6 |
      7 |   it('should have welcome screen', async () => {

      at Object.device (firstTest.spec.js:4:11)
      at tryCatch (../node_modules/regenerator-runtime/runtime.js:62:40)
      at Generator.invoke [as _invoke] (../node_modules/regenerator-runtime/runtime.js:296:22)
      at Generator.prototype.(anonymous function) [as next] (../node_modules/regenerator-runtime/runtime.js:114:21)
      at tryCatch (../node_modules/regenerator-runtime/runtime.js:62:40)
      at invoke (../node_modules/regenerator-runtime/runtime.js:152:20)
      at ../node_modules/regenerator-runtime/runtime.js:195:11
      at callInvokeWithMethodAndArg (../node_modules/regenerator-runtime/runtime.js:194:16)
      at AsyncIterator.enqueue (../node_modules/regenerator-runtime/runtime.js:217:13)
      at AsyncIterator.prototype.(anonymous function) [as next] (../node_modules/regenerator-runtime/runtime.js:114:21)
      at Object.<anonymous>.runtime.async (../node_modules/regenerator-runtime/runtime.js:241:14)
      at Object._callee (firstTest.spec.js:3:14)

  ● Example › should show world screen after tap

    ReferenceError: element is not defined

      14 |   });
      15 |
    > 16 |   it('should show world screen after tap', async () => {
         |                                            ^
      17 |     await element(by.id('world_button')).tap();
      18 |     await expect(element(by.text('World!!!'))).toBeVisible();
      19 |   });

      at Object._callee4$ (firstTest.spec.js:16:44)
      at tryCatch (../node_modules/regenerator-runtime/runtime.js:62:40)
      at Generator.invoke [as _invoke] (../node_modules/regenerator-runtime/runtime.js:296:22)
      at Generator.prototype.(anonymous function) [as next] (../node_modules/regenerator-runtime/runtime.js:114:21)
      at tryCatch (../node_modules/regenerator-runtime/runtime.js:62:40)
      at invoke (../node_modules/regenerator-runtime/runtime.js:152:20)
      at ../node_modules/regenerator-runtime/runtime.js:195:11
      at callInvokeWithMethodAndArg (../node_modules/regenerator-runtime/runtime.js:194:16)
      at AsyncIterator.enqueue (../node_modules/regenerator-runtime/runtime.js:217:13)
      at AsyncIterator.prototype.(anonymous function) [as next] (../node_modules/regenerator-runtime/runtime.js:114:21)
      at Object.<anonymous>.runtime.async (../node_modules/regenerator-runtime/runtime.js:241:14)
      at Object._callee4 (firstTest.spec.js:16:44)

Test Suites: 1 failed, 1 total
Tests:       3 failed, 3 total
Snapshots:   0 total
Time:        521.24s
Ran all test suites matching /e2e/i with tests matching "^((?!:android:).)*$".
detox[89428] DEBUG: [DetoxServer.js/DISCONNECT] role=tester, sessionId=d6b7276b-92cb-e6c3-c7bf-ba5102d46761
detox[89428] DEBUG: [DetoxServer.js/DISCONNECT] role=testee, sessionId=d6b7276b-92cb-e6c3-c7bf-ba5102d46761
child_process.js:644
    throw err;
    ^

Error: Command failed: node_modules/.bin/jest e2e --config=e2e/config.json --maxWorkers=1 '--testNamePattern=^((?!:android:).)*$'
    at checkExecSyncError (child_process.js:601:13)
    at Object.execSync (child_process.js:641:13)
    at runJest (/Volumes/Guillaume/Projects/detox-expo-issue/node_modules/detox/local-cli/detox-test.js:154:6)
    at run (/Volumes/Guillaume/Projects/detox-expo-issue/node_modules/detox/local-cli/detox-test.js:85:7)
    at Object.<anonymous> (/Volumes/Guillaume/Projects/detox-expo-issue/node_modules/detox/local-cli/detox-test.js:217:1)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 13
  • Comments: 19 (2 by maintainers)

Most upvoted comments

I’ll do my best to look into this on the next week.

Yes, there is an issue with Xcode 10 install wrapper AFAIK. I’m aware and this is in the nearest plan’s to fix.

בתאריך יום ד׳, 26 בספט׳ 2018, 10:35, מאת yannDuval ‏< notifications@github.com>:

I have this issue with Xcode 10. Rolling back to version 9.4.1 seems to be enough for me. By the way, with Xcode 10, my first test file runs OK, it’s my second test file which triggers the ReferenceError: device is not defined . Good luck for the fix.

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/wix/detox/issues/911#issuecomment-424615925, or mute the thread https://github.com/notifications/unsubscribe-auth/AB3x5Twb9RvOz-ko8rxLwD_MGiLq5p_5ks5uey5HgaJpZM4WTGi4 .

Happened to me after upgrading to babel 7 and newest RN.

Fix for me was to kill all simulators and do a project clean in iOS. Once the simulator works again, then the detox tests will work as well.

Also needed the babel 7 core package (“babel-core”: “7.0.0-bridge.0”,) . https://jestjs.io/docs/en/getting-started.html#using-babel