How to tap on Allow button on permission pop up

江枫思渺然 提交于 2020-01-29 08:41:32

问题


I am trying to click on the Allow button using Detox.

I have tried the following:

Detox: iOS Simulator how to confirm alert message

I have also tried targeting the "Allow" button by element(by.label('Allow')).tap() and also by.text

I do not want to set location permissions upon app launch. I would like to simulate a user allowing and not allowing location permissions.


回答1:


In your init.js file you can allow the permissions:

beforeAll(async () => {
  await detox.init(config, { launchApp: false });
  await device.launchApp({newInstance: true, permissions: {notifications: 'YES'}});
});

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

You can check the documentation here: https://github.com/wix/detox/blob/master/detox/test/e2e/13.permissions.test.js




回答2:


This is not possible using Detox. The alert is presented from a different process, while Detox operates strictly in the app's process realm.




回答3:


To "Allow" I have used this with success:

element(by.type('_UIAlertControllerActionView')).atIndex(1);

And for "Don't Allow", this should work:

return element(by.type('_UIAlertControllerActionView')).atIndex(0);


来源:https://stackoverflow.com/questions/56351127/how-to-tap-on-allow-button-on-permission-pop-up

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!