Issue in POM | Selenium Forum
M
Posted on 12/09/2015
Iam trying to create a POM project.
Simple login to flipkart.
But as soon as I run I get Null point exception.
Somebody please help :
Here's my project class files details:


1)package pagelog;

import flipkart.base.Page;
import pageinbox.LandingPage;

public class loginPage extends Page {


public LandingPage dologin (String UserName , String Password){
System.out.println("xxxx1");


driver.get(Prop.getProperty("testSiteLandingPageURL"));
System.out.println("xxxx1");

System.out.println("xxxx3");
click ("LOGIN_LINK");
input ("EMAIL" ,UserName);
input ("PASSWORD" , Password);
click("LOGIN_BUTTON");
return new LandingPage();

}}


2)package flipkart.base;

import java.io.FileInputStream;
import java.util.Properties;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Page {
public static WebDriver driver = null;
public static Properties Prop = null;
public static Properties OR = null ;

public Page (){
/* System.out.println("xxxx1");
if (driver == null)
System.out.println("xxxx1");
String ab = System.getProperty("user.dir");

System.out.println("xxxvvx1"+ab);



{*/
Prop = new Properties ();
try {
FileInputStream f = new FileInputStream(System.getProperty("user.dir")+"\\src\\Properties\\config.properties");
Prop.load(f);
FileInputStream fs = new FileInputStream(System.getProperty("user.dir")+"\\src\\Properties\\OR.properties");
OR.load(fs);
}
catch (Exception e)
{
return;
}
// }
System.out.println("xxxxm");



if (Prop.getProperty("browser").equals("Mozilla"))
this.driver= new FirefoxDriver ();
else if (Prop.getProperty("browser").equals("Chrome"))
{ this.driver= new ChromeDriver();

}
}



public void click (String xpath) {
try {driver.findElement(By.xpath(xpath)).click();
}
catch (Exception e)
{
System.out.println("error");
}

}
public void input (String xpath , String text) {
try {driver.findElement(By.xpath(xpath)).sendKeys("text");
}
catch (Exception e)
{
System.out.println("error");
}

}
}

3)package test;

import pageinbox.LandingPage;
import pagelog.loginPage;

public class test {
public static void main (String args[]){
loginPage l = new loginPage ();
LandingPage LP = l.dologin("unnati.swami@gmail.com" ,"8861645276");
System.out.println("xxxx5");


}

}


4)testSiteLandingPageURL = http://www.flipkart.com/
default UserName = 8861645276
default Password = 8861645276
browser = Mozilla

M
Replied on 14/09/2015

[quote:1j93gmfn]Null point exception.[/quote:1j93gmfn]

it is caused by trying ti use a variable which has null value.

ex
int i=null;
int j=i+4;//null pointer exception.