最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to tap on Allow button on permission pop up - Stack Overflow

programmeradmin4浏览0评论

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.

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.

Share Improve this question asked May 28, 2019 at 23:09 RonERonE 4346 silver badges18 bronze badges 1
  • Have you figure this out? – chenop Commented Dec 11, 2022 at 13:16
Add a comment  | 

4 Answers 4

Reset to default 16

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

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

It’s possible to do this with Detox 20. System APIs are only available on iOS. Android support is coming soon.

Don't Allow : 0

Allow: 1

async tapIosSystemButton(idx: number) {
    await system.element(by.system.type('button')).atIndex(idx).tap();
    console.log(`Perform iOS system action (tap) atIndex: ${idx}`);
  }

or you can tap with label (text).

https://wix.github.io/Detox/docs/api/system

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);
发布评论

评论列表(0)

  1. 暂无评论