Detox icon indicating copy to clipboard operation
Detox copied to clipboard

Cannot get location using Detox (works without)

Open Livijn opened this issue 3 years ago • 20 comments
trafficstars

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?

  • [X] 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

Livijn avatar Mar 01 '22 00:03 Livijn

Have you tried this device.setLocation(lat, lon)?

MuckT avatar Mar 01 '22 02:03 MuckT

Yea, of course. But that is using the deprecated fbsimctl.

Livijn avatar Mar 01 '22 08:03 Livijn

I'll close this in favour of #3127

EDIT: Saw that the other issue was closed, so I reopened this one again.

Livijn avatar Mar 01 '22 09:03 Livijn

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.

asafkorem avatar Mar 01 '22 09:03 asafkorem

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe the issue is still relevant, please test on the latest Detox and report back.

Thank you for your contributions!

For more information on bots in this reporsitory, read this discussion.

stale[bot] avatar Mar 31 '22 18:03 stale[bot]

This is very much still relevant.

Livijn avatar Apr 01 '22 08:04 Livijn

@Livijn we've already removed fbsimctl from the project, and now use a custom impl. via AppleSimUtils. Have you tried this with a fairly up to date version of Detox?

d4vidi avatar Apr 10 '22 13:04 d4vidi

@d4vidi I upgraded to the latest version(19.6.5), but it still uses fbsimctl https://github.com/wix/Detox/blob/19.6.5/detox/src/devices/common/drivers/ios/tools/AppleSimUtils.js

hwjm avatar Apr 12 '22 04:04 hwjm

Yes, you are right. @asafkorem @noomorph do you recall why we've never integrated AppleSimUtil's? (in fact, the associated PR is closed - #2891)

d4vidi avatar Apr 12 '22 07:04 d4vidi

Any update on this?

Livijn avatar May 04 '22 09:05 Livijn

We had some issues with react-native-geolocation on CI, and locally. Probably because there's some incompatability issue with iOS 14: https://github.com/react-native-geolocation/react-native-geolocation/pull/168, this repo is not maintained so we may want to think about what can be done about it. Maybe there's already a fork 🤔

See https://github.com/wix/Detox/pull/2891#issuecomment-983363088

asafkorem avatar May 08 '22 07:05 asafkorem

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe the issue is still relevant, please test on the latest Detox and report back.

Thank you for your contributions!

For more information on bots in this reporsitory, read this discussion.

stale[bot] avatar Jun 10 '22 20:06 stale[bot]

Using react-native-background-geolocation here and the behaviour is the same. Unable to set location on an iOS simulator.

Have tried with applesimutils and idb without any luck, like here https://github.com/wix/Detox/issues/1371#issuecomment-942544570.

Looking to mock location instead now, as currently seems impossible to set location having read through all the threads.

jpbalo avatar Jul 12 '22 03:07 jpbalo

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe the issue is still relevant, please test on the latest Detox and report back.

Thank you for your contributions!

For more information on bots in this reporsitory, read this discussion.

stale[bot] avatar Aug 12 '22 12:08 stale[bot]

Bump

Livijn avatar Aug 15 '22 08:08 Livijn

@asafkorem can this be close in favor of #2736?

d4vidi avatar Aug 15 '22 08:08 d4vidi

is the fix here ready? https://github.com/wix/Detox/pull/3479

jpbalo avatar Aug 15 '22 08:08 jpbalo

+1

xhirazi avatar Aug 31 '22 07:08 xhirazi

No, we haven't had capacity for finalizing this. We would appreciate help, it is going to take a while before we reiterate back to this.

d4vidi avatar Sep 01 '22 08:09 d4vidi

I'm not sure if this is the right approach, but one way I could overcome the location issue is to mock the location module:

https://github.com/wix/Detox/blob/01ad250fe4168502a57339b8bcab0ec5a5c89e4b/docs/Guide.Mocking.md

After all the steps I just ran as follow:

RN_SRC_EXT=e2e.ts detox build --configuration ios

mathias5r avatar Sep 07 '22 14:09 mathias5r

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe the issue is still relevant, please test on the latest Detox and report back.

Thank you for your contributions!

For more information on bots in this repository, read this discussion.

stale[bot] avatar Oct 08 '22 09:10 stale[bot]

The issue has been closed for inactivity.

stale[bot] avatar Oct 16 '22 06:10 stale[bot]

+1

henriquechagasg avatar Jan 27 '23 11:01 henriquechagasg

+1 I have sill get this problem.

chellongCoder avatar Mar 24 '23 07:03 chellongCoder

@asafkorem need to reopen?

d4vidi avatar Mar 28 '23 14:03 d4vidi

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);
      }
    };

mushtaque87 avatar Jun 03 '23 09:06 mushtaque87

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)
  }
}

nixolas1 avatar Jul 12 '23 14:07 nixolas1

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

@nixolas1 Thanks for sharing! And this works for you during the test runs?

Because running xcrun simctl location booted set 60,24 works for me if I run it manually in a separate shell, but does not work if it is executed during the test with the help of child_process.exec(), like in your example. However, what did work for me during the test is running applesimutils --byId ${device.id} --setLocation "[${lat}, ${lng}]".

But still, I would like to understand why xcrun simctl does not work. I was suspecting the exec() having insufficient permissions, but that is not the case, as ls and applesimutils do work. Maybe someone can help me out here?

EDIT: I see, that @zacharyweidenbach had the exact same problem here, where running from a separate terminal did work for him, but not with child_process.exec().

riks1233 avatar Jul 28 '23 14:07 riks1233

Set location works reliably for me using simctl without needing to use a separate shell if I clear the location first:

  execSync(`xcrun simctl location ${device.id} clear`)
  execSync(`xcrun simctl location ${device.id} set ${lat},${long}`)

ken-prediction-strike avatar Jan 12 '24 17:01 ken-prediction-strike

Hey, in case you're still experiencing this issue, please upgrade Detox to v20.16. This version resolves set-location issues with Detox.

asafkorem avatar Jan 14 '24 10:01 asafkorem