0

I'm getting NullPointerException on checking if App is installed on the device, I want to check if the app is install inside setCapabilities() method. The app is installed on the emulator and i am running the below code to check if the App is available or not. If the App is available use APP_PACKAGE and APP_ACTIVITY if not use APP:

   public class AndroidDrive extends AppiumBase implements ConnectionHandler {

        public static AndroidDriver getAndroidDriver() {
            return (AndroidDriver) getDriver();
        }


        private DesiredCapabilities setCapabilities(Device device) {
            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, device.getPlatformName());
            capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, device.getDeviceName());
            capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, device.getPlatformVersion());

            System.out.println(getDriver().isAppInstalled(readConfigProperty("androidPackageName")));
            if(getAndroidDriver().isAppInstalled(readConfigProperty("androidPackageName"))){
                capabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, device.getAndroidAppPackage());
                capabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, device.getAndroidAppActivity());
            }else{
                capabilities.setCapability(MobileCapabilityType.APP, device.getApp());
            }
            return capabilities;
        }

        /**
         * Load Android Driver using default device
         *
         * @return
         */
        @Override
        public AndroidDriver load() {
            Device device = JSONReader.getDevice(deviceInfo().get("DEFAULT_ANDROID_DEVICE".toLowerCase()),
                    deviceInfo().get("DEFAULT_OS").toLowerCase());
            return load(device);
        }

        /**
         * Load Android Driver using device parameter
         *
         * @param device
         * @return
         */
        public AndroidDriver load(Device device) {
            AndroidDriver driver = null;
            try {
                if (isRemote()) {
                    driver = new AndroidDriver(new URL(readConfigProperty("remoteUrl")), setCapabilities(device));
                } else {
                    driver = new AndroidDriver(new URL(readConfigProperty("localUrl")), setCapabilities(device));
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            return driver;
        }

    }

The problem is the driver is null.

rhowell
  • 830
  • 5
  • 19

0 Answers0