-2

I have ajava/serenity/appium project and currently my capabilites are set in a serenity properties file. Below I want to perform a scroll but I receive a null pointer exception error for my androidDriver. I am unsure on how to fix the null pointer exception.

public class ScrollingMethods extends PageObject {

        AndroidDriver androidDriver;


    public void scrollDown() {

        int pressX = androidDriver.manage().window().getSize().width / 2;

        int bottomY = androidDriver.manage().window().getSize().height * 4/5;

        int topY = androidDriver.manage().window().getSize().height / 8;

        scroll(pressX, bottomY, pressX, topY);
    }


    public void scroll(int fromX, int fromY, int toX, int toY) {
        TouchAction touchAction = new TouchAction(androidDriver);
        touchAction.longPress(fromX, fromY).moveTo(toX, toY).release().perform();
    }
}
BruceyBandit
  • 3,978
  • 19
  • 72
  • 144
  • yeah because your Android Driver is null ... – Pali Apr 15 '19 at 16:59
  • @Pali haha I get it's null but I am unsure how to not make it null. Usually they say new AndroidDriver (url,capabilities) and then have them set but this is in my serenity properties. I'm not an experience dev so not sure what other things I can do to fix it. – BruceyBandit Apr 15 '19 at 17:01

1 Answers1

0

I want to perform a scroll but I receive a null pointer exception error for my androidDriver

You receive NullPointerException because you are not initialising it. You MUST initialize it with those parameters you want to use as said on AndroidDriver documentation.

So, perhaps you want to use the EnvrionmentVariables, as this post says issue github. But for sure, you need to do something like :

androidDriver = new AndroidDriver(new URL("http://..."), capabilities)

And if you do this, it should remove this NPE.

Skizo-ozᴉʞS ツ
  • 19,464
  • 18
  • 81
  • 148