Get permissions before start tests running

Hi. Few days I try to configure start my tests.
In each start I should manually allow permissions on my emulator (api 23).
So, question: how I can set permissions before tests start?
Please help me :slight_smile:

capabilities.setCapability(“autoAcceptAlerts”, true) , try this

Does not work. I tried. :frowning:

But I performed that by the next way:

caps.setCapability("autoLaunch", false);
Runtime.getRuntime().exec("adb install -g " + PropertyLoader.loadProperty("native.application.path"));       

It helped me but causes next problem. After success login, in a move to another activity, the app closes.

Also, I have tried next:
public class PermissionPopup extends Screen {

public PermissionPopup(final WebDriver appiumDriver) {
    super(appiumDriver);
}

@FindBy(how = How.ID, using = "permission_allow_button")
public WebElement buttonAllow;

public void allow(final Function<WebElement, Boolean> condition) throws FileNotFoundException {
    await()
            .ignoreExceptions()
            .pollDelay(2L, TimeUnit.SECONDS)
            .until(() -> {
                final boolean isVisible = condition.apply(buttonAllow);
                if (isVisible)
                    buttonAllow.click();
                return !isVisible;
            });
}

And TestBase.class:

@BeforeSuite
    @Parameters({"platformVersion", "mobileDeviceName"})
    public void setup(String platformVersion,
                      String mobileDeviceName)
            throws Exception {
        String timeout = PropertyLoader.loadProperty("timeout.implicit");
        appiumDriver = AppiumDriverFactory.getAppiumDriver(platformVersion, mobileDeviceName);
        appiumDriver.manage().timeouts().implicitlyWait(Integer.valueOf(timeout), TimeUnit.SECONDS);
        initialSetupSteps();
    }
    private void initialSetupSteps() throws FileNotFoundException, InterruptedException {
        PermissionPopup permPopUp = PageFactory.initElements(appiumDriver, PermissionPopup.class);
        permPopUp.allow(this::isFormIsVisible);
}

And after all manipulations test fails with:

org.awaitility.core.ConditionTimeoutException: Condition returned by method "allow" in class utility.PermissionPopup was not fulfilled within 10 seconds.

at org.awaitility.core.ConditionAwaiter.await(ConditionAwaiter.java:104)
at org.awaitility.core.CallableCondition.await(CallableCondition.java:79)
at org.awaitility.core.CallableCondition.await(CallableCondition.java:27)
at org.awaitility.core.ConditionFactory.until(ConditionFactory.java:809)
at org.awaitility.core.ConditionFactory.until(ConditionFactory.java:785)
at utility.PermissionPopup.allow(PermissionPopup.java:38)
at framework.TestBaseCRM.initialSetupSteps(TestBaseCRM.java:50)
at framework.TestBaseCRM.setup(TestBaseCRM.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:552)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:215)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:140)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:254)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:74)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:121)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)