I have created 2 classes in 2 packages under one project and calling one method of class A into class B by creating object of class but it is giving me null pointer exception below is the code can any one help on this:
package Login;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import Repository.Objects;
// import Repository.Objects;
public class Loginasa {
public static WebDriver driver;
String baseUrl;
@BeforeSuite
public void setUp() throws Exception
{
System.setProperty("webdriver.chrome.driver","E:\\chromedriver_win32\\chromedriver.exe");
driver =new ChromeDriver();
baseUrl= "http://10.7.30.135:9090/xGLinear/login.html";
driver.get(baseUrl);
driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
}
@Test
public void Newlogin() throws Exception
{
// driver.get(baseUrl);
driver.findElement(By.id(Objects.Username)).clear();
driver.findElement(By.id(Objects.Username)).sendKeys("ASA");
driver.findElement(By.id(Objects.Password)).clear();
driver.findElement(By.id(Objects.Password)).sendKeys("Abcd1234");
driver.findElement(By.id(Objects.loginbtn)).click();
Thread.sleep(20000);
}
@AfterTest
public void tearDown() throws Exception
{
driver.quit();
System.out.println("Browser Launch");
}
}
Another is:
package Commonmethods;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import Login.Loginasa;
public class CreateOrderline {
public static WebDriver driver;
String baseUrl;
@BeforeTest
public void setUp() throws Exception
{
System.setProperty("webdriver.chrome.driver","E:\\chromedriver_win32\\chromedriver.exe");
driver =new ChromeDriver();
baseUrl= "http://10.7.30.135:9090/xGLinear/login.html";
driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
}
@Test
public void Orderline () throws Exception
{
driver.get(baseUrl);
Loginasa ASA= new Loginasa();
System.out.println("Browser Launch");
ASA.Newlogin();
}
@AfterTest
public void tearDown() throws Exception
{
driver.quit();
System.out.println("Browser Launch");
}
}
Giving Error: NULL Pointer Exception............