Detox: Cannot get location using Detox (works without)

What happened?

I cannot get the location when running Detox. It works when using launching it normally. I am using expo. I think it might be related to #1371.

I’ve tried lots of different ways of implementing this (idb, applesimutils, set-simulator-location). Right now I’m running idb set-location --udid ${device._deviceId} ${coordinates.latitude} ${coordinates.longitude}. That works for changing location when launching without Detox. However, when I use it with Detox, it just loads forever.

What was the expected behaviour?

No response

Was it tested on latest Detox?

  • I have tested this issue on the latest Detox release and it still reproduces.

Did your test throw out a timeout?

Help us reproduce this issue!

No response

In what environment did this happen?

package.json
  "dependencies": {
    "@bugsnag/expo": "^7.16.1",
    "@expo-google-fonts/red-hat-display": "^0.2.0",
    "@expo/react-native-action-sheet": "^3.13.0",
    "@expo/vector-icons": "^12.0.0",
    "@fortawesome/fontawesome-svg-core": "^1.3.0-beta3",
    "@fortawesome/pro-light-svg-icons": "^6.0.0-beta3",
    "@fortawesome/pro-solid-svg-icons": "^6.0.0-beta3",
    "@fortawesome/react-fontawesome": "^0.1.16",
    "@fortawesome/react-native-fontawesome": "^0.2.7",
    "@gorhom/bottom-sheet": "^4",
    "@hookstate/core": "^3.0.13",
    "@react-native-async-storage/async-storage": "~1.15.0",
    "@react-native-community/datetimepicker": "4.0.0",
    "@react-native-community/eslint-config": "^3.0.1",
    "@react-native-community/netinfo": "7.1.3",
    "@react-native-community/picker": "^1.8.1",
    "@react-navigation/bottom-tabs": "^6.0.5",
    "@react-navigation/native": "^6.0.8",
    "@react-navigation/stack": "^6.1.1",
    "@typescript-eslint/eslint-plugin": "^5.7.0",
    "add": "^2.0.6",
    "axios": "^0.24.0",
    "cron-parser": "^4.2.1",
    "date-fns": "^2.27.0",
    "eslint": "^7.32",
    "expo": "^44.0.0",
    "expo-app-loading": "~1.3.0",
    "expo-apple-authentication": "~4.1.0",
    "expo-application": "~4.0.1",
    "expo-asset": "~8.4.6",
    "expo-auth-session": "~3.5.0",
    "expo-av": "~10.2.0",
    "expo-calendar": "~10.1.0",
    "expo-constants": "~13.0.1",
    "expo-device": "~4.1.0",
    "expo-facebook": "~12.1.0",
    "expo-font": "~10.0.4",
    "expo-haptics": "~11.1.0",
    "expo-image-picker": "~12.0.1",
    "expo-linear-gradient": "~11.0.3",
    "expo-linking": "~3.0.0",
    "expo-localization": "~12.0.0",
    "expo-location": "~14.0.1",
    "expo-notifications": "~0.14.0",
    "expo-random": "~12.1.1",
    "expo-secure-store": "~11.1.0",
    "expo-speech": "~10.1.0",
    "expo-splash-screen": "~0.14.1",
    "expo-status-bar": "~1.2.0",
    "expo-task-manager": "~10.1.0",
    "expo-updates": "~0.11.6",
    "expo-web-browser": "~10.1.0",
    "geolib": "^3.3.3",
    "i18next": "^21.6.7",
    "install": "^0.13.0",
    "laravel-echo": "^1.11.3",
    "lottie-react-native": "5.0.1",
    "object-to-formdata": "^4.4.1",
    "patch-package": "^6.4.7",
    "prettier": "^2.5.1",
    "pusher-js": "^7.0.6",
    "react": "17.0.1",
    "react-dom": "17.0.1",
    "react-native": "0.64.3",
    "react-native-chart-kit": "^6.11.0",
    "react-native-gesture-handler": "~2.1.0",
    "react-native-maps": "0.29.4",
    "react-native-modal": "^13.0.0",
    "react-native-open-maps": "^0.4.0",
    "react-native-reanimated": "~2.3.1",
    "react-native-safe-area-context": "3.3.2",
    "react-native-screens": "~3.10.1",
    "react-native-segment-control": "^1.0.5",
    "react-native-svg": "12.1.1",
    "react-native-swiper": "^1.6.0-rc.3",
    "react-native-toast-message": "^2.1.1",
    "react-native-uuid": "^2.0.1",
    "react-native-web": "0.17.1",
    "react-navigation-transitions": "^1.0.12",
    "rn-placeholder": "^3.0.3",
    "search-params": "^4.0.1",
    "tailwind-rn": "^3.0.1",
    "tailwindcss": "^2.0.6",
    "use-debounce": "^7.0.1",
    "yarn": "^1.22.17"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9",
    "@testing-library/react-hooks": "^7.0.2",
    "@types/jest": "^27.4.0",
    "@types/react": "~17.0.21",
    "@types/react-native": "~0.64.12",
    "detox": "^18",
    "detox-expo-helpers": "github:fschoenfeldt/detox-expo-helpers#0.7.1",
    "expo-detox-hook": "^1.0.10",
    "jest": "^26.6.3",
    "jest-circus": "^27.5.1",
    "jest-expo": "^44.0.0",
    "postinstall-postinstall": "^2.1.0",
    "react-native-bundle-visualizer": "^3.1.1",
    "react-test-renderer": "^17.0.2",
    "standard-version": "^7.1.0",
    "standard-version-expo": "^1.0.3",
    "ts-jest": "^26.5.6",
    "typescript": "~4.3.5"
  },

Detox logs

No response

Device logs

No response

More data, please!

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 30 (3 by maintainers)

Most upvoted comments

Thanks for the report @Livijn, we are indeed aware of the issues with set-location… I wonder if there’s a way to make this work on Detox with idb. I will investigate this soon.

I ended up using simctl, so I wouldn’t have to install idb or any other deps.

const {exec} = require("child_process")
const {log, device} = require("detox")

module.exports.setLocation = async function (lat, lon) {
  if (device.getPlatform() === "ios") {
    const coords = lat + "," + lon
    exec("xcrun simctl location booted set " + coords, (err, stdout, stderr) => {
      log.info("simctl location " + coords, err, stdout, stderr)
    })
  } else {
    await device.setLocation(lat, lon)
  }
}

This worked for me

const { exec } = require('child_process');

const setLocation = async () => {
      log.info('setLocation **');
      if (device.getPlatform() === 'ios') {
        exec(
          "idb list-targets | grep -n 'Booted'",
          (err: any, stdout: any, stderr: any) => {
            log.info('idb list-targets - ', err, stdout, stderr);
            log.info(
              'Execute Command to set Location for iOS **',
              'idb set-location --udid ' + device.id + ' 25.2769 55.2962',
            );
            exec(
              'idb set-location --udid ' + device.id + ' 25.2769 55.2962',
              (err: any, stdout: any, stderr: any) => {
                log.info('setLocation - ', err, stdout, stderr);
              },
            );
          },
        );
      } else {
        await device.setLocation(25.2769, 55.2962);
      }
    };