ECLIPSE - 对象存储库程序 - 显示NullPointerException错误

时间:2017-08-10 02:43:38

标签: java eclipse selenium

enter image description here

使用对象存储库库文件下面的Selenium程序,但同样失败并显示java.lang.NullPointerException。已将特定语法行注释为“错误”。此处还附加了错误屏幕截图和config.property files.enter图像说明。试图找出原因但不能。请澄清失败的原因和错误消息。 enter image description here

package objectrepository;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.WebDriver;
import org.testng.annotations.Test;
import objectrepository.Lib_ChromeDriver;

public class OBRClass_2 {

@Test
public void launch_chrome() throws Exception{

Lib_ChromeDriver LCD = new Lib_ChromeDriver();// Lib_ChromeDriver is the Object Repository Library File 

System.setProperty("webdriver.chrome.driver", LCD.Path());// error shown

WebDriver Snap = new ChromeDriver();

Snap.get(LCD.AppURL());


}
}

// a Java Class containing Constructor & method and is saved as Library file.
// Constructor has will call the ObjectRepository File and 
// method will call the Call the ChromeDriver Location to Launch the same
// this Library Class can be called in Selenium program to launch the Chrome Driver 

package objectrepository;

import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;
import org.testng.annotations.Test;

public class Lib_ChromeDriver {

Properties Prop;

@Test
public void Lib_ChromeDriver() throws Exception{// Constructor calling the Object Repository File

File OB_File = new File("./Config/Config.property");
FileInputStream OB_FIS = new FileInputStream(OB_File);
Prop = new Properties();
Prop.load(OB_FIS);
}

public String Path() throws Exception{// method calling the ChromeDriver Path to Launch the same

String ChromePath = Prop.getProperty("ChromeDriver"); // error shown
return ChromePath;
}

public String AppURL() throws Exception{

String AppURL = Prop.getProperty("URL");
return AppURL;
}
}

1 个答案:

答案 0 :(得分:0)

变化

public void Lib_ChromeDriver()   // not a constructor

public Lib_ChromeDriver()       // is a constructor

您调用的代码不在构造函数中,而是在名为Lib_ChromeDriver

的方法中

在这种情况下,您的代码正在调用其中没有任何代码的default构造函数 - 因此永远不会设置变量Props