How to Handle permission popups in Real Devices with Appium PHP on LambdaTest cloud?

How to Handle permission popups in Real Devices with Appium PHP on LambdaTest cloud?

Hey Tom,

While performing app automation testing with PHP Appium Testing on LambdaTest Grid, you may face a scenario where you would like to automatically handle permission pop-ups. You may choose to either accept all permission pop-ups or dismiss all of them. You can handle the case as mentioned below separately for Android or iOS apps.

        require __dir__.'/vendor/autoload.php';
        use Facebook\WebDriver\Remote\DesiredCapabilities;
        use Facebook\WebDriver\Remote\RemoteWebDriver;
        use Facebook\WebDriver\WebDriverBy;
        $caps = array(
            "app"=>"lt://", //Enter app_url here
            "deviceName" => "Galaxy S20",
            "platformName" => "Android",
            "platformVersion" => "10",
            "isRealMobile" => TRUE,
            "visual" => TRUE,
            "video" => TRUE,
            "name" => "Php - Android test",
            "build" => "Php Vanilla - Android",
            //GRANT PERMISSIONS FOR ANDROID
            "autoGrantPermissions" => TRUE,
            //ACCEPT ALERTS FOR IOS
            "autoDismissAlerts" => TRUE,
            //DISMISS ALERTS FOR IOS
            "autoAcceptAlerts" => TRUE
        );
        $username = getenv("LT_USERNAME") ? getenv("LT_USERNAME") : "username"; //Enter username here
        $accesskey = getenv("LT_ACCESS_KEY") ? getenv("LT_ACCESS_KEY") : "accesskey"; //Enter accesskey here
        $driver = RemoteWebDriver::create("https://$username:$accesskey@mobile-hub.lambdatest.com/wd/hub",$caps);
     try{
        $color_element = $driver->findElement(WebDriverBy::id('color'));
        $color_element->click();
        $text_element = $driver->findElement(WebDriverBy::id('Text'));
        $text_element->click();
        $toast_element = $driver->findElement(WebDriverBy::id('toast'));
        $toast_element->click();
        $notification_element = $driver->findElement(WebDriverBy::id('notification'));
        $notification_element->click();
        $driver->quit();
     } finally {
        $driver->quit();
     }

Here’s the GitHub repo for the same: https://github.com/saanvisavlani/appium-php-permissions