目前正在学习自动化测试,我无法理解我的代码有什么问题。我正在尝试从 .properties 文件中获取信息并将其用作变量。我收到一个错误:
java.io.FileNotFoundException: ..\resources\config.properties (The system cannot find the path specified)
但是,我确信我的道路是正确的。尝试了不同的变体,例如//resources//config...甚至使用\\,仍然是相同的问题。
这是我尝试从 config.properties 文件中获取信息的代码:
@Test
public void myFirstTest() {
LoginPage log = new LoginPage();
try(FileReader reader = new FileReader("../resources/config.properties")) {
Properties properties = new Properties();
properties.load(reader);
String username = (String) properties.get("username");
String password = (String) properties.get("password");
System.out.println("h" + username);
log.insertUsername(username);
log.insertPassword(password);
} catch(Exception e) {
e.printStackTrace();
}
}
这就是我的样子config.properties
username = myUserName1
password = myTestPass1
这是我的文件的架构:
PS我正在尝试从测试中获取源文件->LabelsAndFoldersTest.java
