Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle iOS permission dialogs #9

Closed
talkol opened this issue Aug 3, 2016 · 26 comments
Closed

Handle iOS permission dialogs #9

talkol opened this issue Aug 3, 2016 · 26 comments

Comments

@talkol
Copy link

talkol commented Aug 3, 2016

EarlGrey has a hard time dealing with them since they're external to the app

google/EarlGrey#55

this thread offers some interesting workarounds.. we can add them directly into detox

@talkol talkol added this to the Version 2 milestone Oct 6, 2016
@talkol
Copy link
Author

talkol commented Oct 6, 2016

@LeoNatan this is not urgent since it's not for Version 1 milestone

@DanielZlotin
Copy link
Contributor

Urgent. All tests fail once you get the dialog (for example notifications permissions usually happen on app launch or close to it)

@LeoNatan
Copy link
Contributor

LeoNatan commented Dec 1, 2016

@DanielZlotin This is a big problem in Earl Grey also, due to in-process architecture. There seem to be several workarounds, including setting a DB file in the simulator subsystem to automatically allow permissions.

@LeoNatan
Copy link
Contributor

LeoNatan commented Dec 1, 2016

@yedidyak
Copy link
Contributor

yedidyak commented Dec 1, 2016

If you can swizzle the permissions on demand at runtime, and have some JS API to mange it per test that would be best. If you could expect it that would be better. Something like:
expect(permission.photos).toBeRequested()
allowNextPermission()
rejectNextPermission()

@LeoNatan
Copy link
Contributor

LeoNatan commented Dec 5, 2016

@yedidyak This will be a big issue to fix which will take much time. In the meantime, do not stop working on tests. Instead, mock the permission API to return success or failure.

@yedidyak
Copy link
Contributor

yedidyak commented Dec 5, 2016

@LeoNatan That's possible in some cases, but in others the permission itself is necessary for the functionality.

@LeoNatan
Copy link
Contributor

LeoNatan commented Apr 4, 2017

I have decided to go against swizzling APIs. It just does not scale, as more and more APIs are added each year. Detox is a testing framework for native apps, not just the small subset of APIs wrapped in RN.

Instead, I have created applesimutils and DetoxHelper.

applesimutils allows setting permissions before a process is launched, and thus can be used together with relaunchApp API to set permissions.

DetoxHelper is not ready for prime time just yet, but it is intended to support switching of permissions on the fly. This requires investigation and I am not 100% if possible at all.

For now, let's integrate applesimutils with Detox.

@irrigator
Copy link

Kudos for this ! @LeoNatan Has applesimutils been integrated into Detox yet? If not, how can we use it to set permissions before Detox test?

@LeoNatan
Copy link
Contributor

@irrigator Unfortunately, integrating applesimutils with Detox is still not ready. In the mean time, you can indeed use applesimutils before running your Detox test. Just make sure to pass the same simulator name (or preferrably, unique identifier), and set the permissions as you need. You can read the usage in the readme for applesimutils; it should be simple and intuitive.

@LeoNatan LeoNatan removed this from the Version 2 milestone Jun 6, 2017
@mobinni
Copy link

mobinni commented Jun 7, 2017

@LeoNatan I used applesimutils in the following manner:

function setPermissions(permissions) {
  cp.execSync(
    `applesimutils \\
    --simulator "1991C14B-9892-44E8-BCEF-EA63F308972E" \\
    --bundle io.rangle.starter.app \\
    --setPermissions "${permissions.join()}"`,
    {
      stdio: 'inherit',
    },
  );
}


beforeAll(async () => {
  await detox.init(config);
  await setPermissions(['camera=YES']);
}, 25000);

It causes the simulator to refresh going black with a spinner then when the simulator is back on the app is closed and the tests fail. How would you suggest running it before the tests?

Update:

I figured out a way to do it by doing the following:

beforeAll(async () => {
  await detox.init(config);
  await setPermissions(['camera=YES']);
  await device.relaunchApp();
}, 25000);

@LeoNatan
Copy link
Contributor

LeoNatan commented Jun 7, 2017

Yes, you need to launch the app.
This is being developed now, and we will have an official support soon. Stay tuned.

@ptomasroos
Copy link

Great news @LeoNatan !

@DanielMSchmidt
Copy link
Contributor

@LeoNatan How far is this? As a current workaround I take the simulator ID from the global device object in the function mentioned by @mobinni but this approach feels a little hacky to me 👍

@LeoNatan
Copy link
Contributor

In development. Cannot comment on how long it will take, as I am not the one developing it, but it is in active development and is coming soon.

@LeoNatan
Copy link
Contributor

LeoNatan commented Jul 7, 2017

Guys, support has landed in Detox for this feature. As we have not yet updated the documentation yet, for now, you can see the syntax here

Currently supported permissions:

calendar=YES|NO
camera=YES|NO
contacts=YES|NO
health=YES|NO
homekit=YES|NO
location=always|inuse|never
medialibrary=YES|NO
microphone=YES|NO
motion=YES|NO
notifications=YES|NO
photos=YES|NO
reminders=YES|NO
siri=YES|NO

As described in the Getting Started document, you need to install applesimutils for this.

@LeoNatan LeoNatan closed this as completed Jul 7, 2017
@rotemmiz
Copy link
Member

rotemmiz commented Jul 8, 2017

@stereodenis
Copy link

@LeoNatan @rotemmiz how to initial run app with permissions?

@Monte9
Copy link
Contributor

Monte9 commented Sep 1, 2017

@LeoNatan Thanks a lot for adding this feature! 💯 It works perfectly and it's super simple to use as well!

@LeoNatan
Copy link
Contributor

LeoNatan commented Sep 1, 2017

@Monte9 Cheers, thanks for the kind words!

@yogeshthanvi
Copy link

Can anyone give me an example to approve location permission

@menasameh
Copy link

menasameh commented Apr 29, 2018

@yogeshthanvi it's now documented here
the options for the location permission are:

location=always|inuse|never

so you use it as the following

await device.launchApp({ permissions: { location: 'always' } })

@DanielMSchmidt
Copy link
Contributor

@yogeshthanvi Could you tell me where you have looked for this information? Might make sense to add this info right there to help the next person even faster 🤔

@yogeshthanvi
Copy link

@menasameh Thanks man , love you

@LeoNatan
Copy link
Contributor

Please make sure to read the documentation.

@suvodeep-pyne
Copy link

suvodeep-pyne commented Jul 10, 2018

For ease of other users:

describe(':ios: Permissions', () => {
  beforeAll(async () => {
    await device.launchApp({ permissions: { notifications: 'YES' } });
  });

  it('Permissions is granted', async () => {
    await device.launchApp({permissions: {calendar: 'YES'}});
    await element(by.text('Permissions')).tap();
    await expect(element(by.text('granted'))).toBeVisible();
  });

  it('Permissions denied', async () => {
    await device.launchApp({permissions: {calendar: 'NO'}});
    await element(by.text('Permissions')).tap();
    await expect(element(by.text('denied'))).toBeVisible();
  });
});

Quoting from https://github.com/wix/detox/blob/master/detox/test/e2e/13.permissions.test.js

@wix wix locked and limited conversation to collaborators Jul 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests