How to avoid AUTO_ACCEPT_ALERTS for some pop-up in specific tests

I have auto-accept Permission capabilities set in Android and iOS. When I am running the tests if any POP-Up or Permission is coming it is accepting it. But I want in some of the tests to manually accept permission or Pop-up. Seems like capabilities.setCapability to accept alert works faster than finding element and making a click in a Test method. Can anyone suggest any workaround with this problem in Appium to avoid this race condition?

@Test
public void acceptAlertManually()
{
App().Pages().HomePage().clickRandomTab();
App().Pages().CommonPageElements().clickDiscardChanges();}

Is there any solution to click on the pop-up to select the option of my choice like the above example? I have AUTO_ACCEPT_ALERTS to be true in both Android and iOS.

why you not disable for these some tests capability to accept permissions?

Please share the code snippet to disable it for some test if that is possbile?
I am using these capabilities for iOS and Android.

capabilities.setCapability(IOSMobileCapabilityType.AUTO_ACCEPT_ALERTS, true);
capabilities.setCapability(AndroidMobileCapabilityType.AUTO_GRANT_PERMISSIONS, true);

just set them false or do not add these lines. by default they false. and you need RESET permissions before this test also as far as in previous tests you accepted them.

If I am. adding RESET permission before the test, as in the below example,

the app is asking to do fresh login which I don’t want to do.

Secondly, if I just set the below lines false or do not add these lines, then in all other tests it will not be able to accept permission automatically.

capabilities.setCapability(IOSMobileCapabilityType.AUTO_ACCEPT_ALERTS, true);
capabilities.setCapability(AndroidMobileCapabilityType.AUTO_GRANT_PERMISSIONS, true);

Any other workaround to remove this race condition?

it is just a problem in your code. e.g. with java and testNG you can easily configure override capabilities with any test needed.

possible workaround for you is look at grant permissions functionality. i did not use it and cant suggest anything how to use it: