-1

This is my appium java code, after starting the test its stopping in app login method and says java.lang.NullPointerException. I tried all my possible solutions, but its not at all working please help to solve this problem

public class FirstAutomate {
private WebDriver driver;

@Test

public void setup() throws Exception {


   File app = new File("C:\\sdk\\platform-tools\\Myapp.apk");
    DesiredCapabilities capabilities = new DesiredCapabilities();
    //capabilities.setCapability("BROWSER_NAME", "Android");
    capabilities.setCapability("VERSION", "5.0.2"); 
    capabilities.setCapability("deviceName","G3 Beat");
    capabilities.setCapability("appPackage", "com.skooly.app");
    capabilities.setCapability("appActivity","com.skooly.app.screens.prehomescreens.activities.SplashScreen");
    capabilities.setCapability("platformName","Android");

    capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME,MobilePlatform.ANDROID);
    capabilities.setCapability("app", app.getAbsolutePath());
    try{
        driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

    }catch(MalformedURLException e)
    {
        e.printStackTrace();

    }

   // TODO Auto-generated method stub

}
 @Test

    public void AppLogin() throws InterruptedException {
    //Tapping  button
     driver.findElement(By.id("loginButtonTextView")).click();
}
}
ragesh-ragav 1993
  • 515
  • 1
  • 5
  • 11
  • I don't know appium, but I would not assume that `setup()` is called before your `AppLogin()` on the same instance of your test. – JimmyB Nov 02 '16 at 12:18
  • Try `@Before public void setup() throws Exception { ...` or something like that. – JimmyB Nov 02 '16 at 12:19
  • can you add the stack trace ? – Shree Naath Nov 02 '16 at 12:20
  • What testing framework are you using to run your appium tests? – JimmyB Nov 02 '16 at 12:22
  • @JimmyB I'm using Junit, thanks it worked for me great :-) – ragesh-ragav 1993 Nov 02 '16 at 12:28
  • @JimmyB After adding "@Before", AppLogin() works perfectly, but the button click happens in milliseconds, i cannot able to see the splash screen which contain the "Login" button. It is directly going to login screen. Implicitwait is also not working, also i doesn't know where i need to add implicit wait exactly. – ragesh-ragav 1993 Nov 02 '16 at 13:01

1 Answers1

2

With JUnit, each of your tests, annotated with @Test, is run independently from any other. That's why you cannot set up some data ("driver") in one @Test and expect it to be there in another @Test.

To do initialization work before each test, use the @Before annotation, as in

@Before public void setup() throws Exception { ...

This will make setup() run and set up your driver before every actual test, i.e. AppLogin() in your case. See for instance JUnit before and test.

Community
  • 1
  • 1
JimmyB
  • 12,101
  • 2
  • 28
  • 44