Am getting null NullPointerException when running below code, i am just trying read excel path from properties file but getting error, please help me as I'd tried hard to resolve this problem
login script
public class Login1 {
public static Properties props;
public static WebDriver driver;
public InputStream propertiesFilePath = this.getClass().getClassLoader()
.getResourceAsStream("Config.properties");
public static void main(String [] arg){
}
public void Readproperties() throws IOException {
props = new Properties();
props.load(propertiesFilePath);
}
public static void getDriver(){
System.setProperty("webdriver.chrome.driver", "C:\\Users\\aroy\\Desktop\\Sele\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
}
public static void logintoapp(String acc, String passw){
driver.findElement(By.xpath("//input[@id='userName']")).sendKeys(acc);
driver.findElement(By.xpath("//input[@id='password']")).sendKeys(passw);
driver.findElement(By.xpath("//button[@id='loginBtn']")).click();
System.out.println("Login SuccessFully");
}
}
Tesstcase:
package AtExecution;
import java.io.IOException;
import org.testng.annotations.Test;
import BeoreExecution.Login1;
public class Testcase extends Login1 {
public static ExcelLib exel1;
@Test
public void login() throws IOException{
Login1 x = new Login1();
x.Readproperties();
exel1 = new ExcelLib(Login1.props.getProperty("TestDataPath"));
String siteurl = exel1.getCellData("Login_Credentials", "TestUrl", 2);
String acc = exel1.getCellData("Login_Credentials", "account", 2);
String passw=exel1.getCellData("Login_Credentials", "Password", 2);
Login1.getDriver();
driver.get(siteurl);
driver.manage().window().maximize();
Login1.logintoapp(acc, passw);
}
}
here is my log
[RemoteTestNG] detected TestNG version 6.12.0
FAILED: login
java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Unknown Source)
at java.util.Properties.load0(Unknown Source)
at java.util.Properties.load(Unknown Source)
at BeoreExecution.Login1.Readproperties(Login1.java:30)
at AtExecution.Testcase.login(Testcase.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:669)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:877)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1201)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:776)
at org.testng.TestRunner.run(TestRunner.java:634)
Please help me to solve this
my config file data is
TestDataPath=C:/Users/Testdata.xlsx
and below is my exelsheet data