0

I am not able to run my automation testing with Appium server using Eclipse with Selenium. The error I get is:

Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create a new remote session. Please check the server log for more details. 
java.lang.SecurityException: You need the android.permission.INSTALL_GRANT_RUNTIME_PERMISSIONS permission to use the PackageManager.INSTALL_GRANT_RUNTIME_PERMISSIONS

The code I am trying to run is:

package tests;

import java.net.MalformedURLException;

import java.net.URL;

import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.AppiumDriver;

import io.appium.java_client.MobileElement;

import io.appium.java_client.android.AndroidDriver;

public class StartChrome {

    public static void main(String[] args) {

        // Set the Desired Capabilities
        DesiredCapabilities caps = new DesiredCapabilities();
        caps.setCapability("deviceName", "My Phone");
        caps.setCapability("udid", "7970dc54"); // Give Device ID of your mobile phone
        caps.setCapability("platformName", "Android");
        caps.setCapability("platformVersion", "9 PKQ1.180904.001");
        caps.setCapability("appPackage", "com.android.vending");
        caps.setCapability("appActivity", "com.google.android.finsky.activities.MainActivity");
        caps.setCapability("noReset", "true");

        // Instantiate Appium Driver
        try {

            AppiumDriver<MobileElement> Driver = new AndroidDriver<MobileElement>(
                    new URL("http://0.0.0.0:4723/wd/hub"), caps);

        } catch (MalformedURLException e) {
            System.out.println(e.getMessage());
        }
    }

}
  • What setup steps have you followed on the phone? Is USB debugging enabled in developer options? Is the phone connected to the computer in file transfer mode (not charging mode)? – anonygoose Sep 20 at 15:30
  • Hi Rhaul, I've placed this on hold for now. Could you make this post less like a debug report and more like "Here's what I tried to do, here's what I expected to happen, here's how I tried to fix it, etc." – corsiKa Sep 20 at 17:42
  • @anonygoose yes USB debugging enabled in developer options, and also my phone was connected to the computer in as file transfer mode(not charging mode)....but i still unable to run this program please check below: – Rahul Kumar Sep 23 at 5:13
  • Hi @corsiKa i am using first time this site thats why dont know much more about that by the way i have edited my Problems once again please let me know and check if you need any kind of information further...please help me asap – Rahul Kumar Sep 23 at 5:35
  • @c32hedge i have edited my problem please check now and let me what should i have to do...... – Rahul Kumar Sep 23 at 5:37
1

I suspect your problem lies with the errors:

java.lang.SecurityException: You need the android.permission.INSTALL_GRANT_RUNTIME_PERMISSIONS permission to use the PackageManager.INSTALL_GRANT_RUNTIME_PERMISSIONS

This is saying that the phone does not have permission to run your software.

Because your code is setting the capability "noReset" to true, you can't set the capability "autoGrantPermissions" to true because it won't work. The two capability settings are incompatible.

This limits your options.

You could remove the "noReset" capability, if it is not essential that your device keeps the app running and the app data in local memory. That would then allow you to set "autoGrantPermissions" to 'true' and probably fix your problem. (http://appium.io/docs/en/writing-running-appium/other/reset-strategies/index.html has more information)

You could specifically install the permissions using adb - there is a Stack Overflow question here with more information. You should do this with your code, so you don't leave the device with an open security flaw.

You could probably also use the Java Appium API call from the package io.appium.java_client.android.appmanagement and the class AndroidInstallApplicationOptions myInstallOptions.withGrantPermissionsEnabled() which will grant all required permissions as soon as your code is installed.

I'd also suggest you take some time to review the Appium documentation.

  • Hi @Kate Paulk, thanks for the help... its working now i am very happy. but after sometime app got automatic disappear and in my Eclipse i have found this error again: Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils at io.appium.java_client.HasSessionDetails.lambda$0(HasSessionDetails.java:52) – Rahul Kumar Sep 23 at 13:15
  • @RahulKumar - NoClassDefFoundError usually means that the class it's referring to (org.apache.commons.lang3.StringUtils) is not in the Java classpath. You will need to configure this class to be included in the package you send to be run. javarevisited.blogspot.com/2011/06/… has a decent description of how to resolve the problem if you read far enough down the page – Kate Paulk Sep 23 at 13:54
  • Hi @Kate Paulk, now i add that in java class path. Thanks a lot for this. I want to inform you that now i got no any error but still after sometime app got close automatically. I want to know why this happened? is this any kind of error? Now in my eclipse console its showing: Sep 24, 2019 10:44:38 AM io.appium.java_client.remote.AppiumCommandExecutor$1 lambda$0 INFO: Detected dialect: W3C – Rahul Kumar Sep 24 at 5:24
  • @RahulKumar - what your console is showing is normal. The app closing after a time would most likely be normal cleanup. – Kate Paulk Sep 24 at 11:48
  • ok sir, i understood and now i am facing the issue with uiautomatorviewer also when i tried to run its give error : -djava.ext.dirs=..\lib\x86_64;..\lib is not supported. use -classpath instead. I think this is beacuse java version 12.0.2 is not suppprting this so can you give me some alternate for this, i dont want to install java 8.1 again and do setup. i need solution at this point of my work, please help me this also – Rahul Kumar Sep 24 at 12:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.