0

I am facing this issue while i am trying to make use of abstraction concepts for my tests.

My SignIn page class:

public class SigninPage {

protected AndroidDriver driver;

String app_package_name = "com.xyz.abc:id/";
By signInBtn = By.id(app_package_name + "btn_sign_in");
By enterEmail = By.id(app_package_name + "et_email");
By enterPassword = By.id(app_package_name + "et_password");

public void signInProcess(String username, String password) {
    System.out.println("Clicking on Sign in button");
    driver.findElement(signInBtn).click();
    System.out.println("Enter valid Email");
    driver.findElement(enterEmail).sendKeys(username);
    System.out.println("Enter password");
    driver.findElement(enterPassword).sendKeys(password);
    System.out.println("SignIn");
    driver.findElement(signInBtn).click();
  }
}

My Test Class:

 public class SignIn extends LaunchEmulatorAndDeployAPK {
 SigninPage sp = new SigninPage();

@Test
public void signInByRegisteredUser() throws Exception {
    sp.signInProcess("xyz@test.com", "testpassword");
    //Launch Page
    Thread.sleep(3000);
    By successMessage = By.id("testpath");
    Thread.sleep(3000);
    boolean result = driver.findElement(successMessage).isDisplayed();
    System.out.println("The success message is displayed: " + result);
    String text = driver.findElement(successMessage).getText();
    System.out.println("The success message text is : " + text);
   }
}

My Base Class:

  public class LaunchEmulatorAndDeployAPK {
  protected AndroidDriver driver;

@BeforeTest
protected void prepareAndroidForAppium() throws MalformedURLException {
    File appDir = new File("E://path");
    File app = new File(appDir, "test.apk");
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("device", "emulator-5554");

    // mandatory capabilities
    capabilities.setCapability("deviceName", "emulator-5554");
    capabilities.setCapability("platformName", "Android");

    // other caps
    capabilities.setCapability("app", app.getAbsolutePath());
    driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}

@AfterTest
public void teardown() {
    driver.quit();
  }
}

I am getting nullpointer exception while running my test class

Clicking on Sign in button
FAILED: signInByRegisteredUser
java.lang.NullPointerException
at com.xyz.abc.pages.SigninPage.signInProcess(SigninPage.java:20)
at com.xyz.abc.scenarios.SignIn.signInByRegisteredUser(SignIn.java:17)
Prasan Shetty
  • 49
  • 3
  • 15
  • `SigninPage.driver` is not initialized. – shmosel Mar 22 '17 at 04:14
  • Probably your driver returns null on some of the lookup calls. Simply check the results of those lookup calls before making calls on them. – GhostCat Mar 22 '17 at 04:14
  • @shmosel i think i am initializing it in my Testclass – Prasan Shetty Mar 22 '17 at 04:37
  • `LaunchEmulatorAndDeployAPK.driver` has no relationship to `SigninPage.driver`. They're just defined identically. – shmosel Mar 22 '17 at 04:38
  • @shmosel i see. i actually tried it by extending the SigninPage class from base class and removing 'protected AndroidDriver driver;' from SigninPage class, but still getting same exception. – Prasan Shetty Mar 22 '17 at 04:43

0 Answers0