gpt4 book ai didi

java - 异常 Selenium Webdriver TestNg

转载 作者:行者123 更新时间:2023-11-29 05:06:48 25 4
gpt4 key购买 nike

<分区>

试图创建属性文件并从中检索信息,但我得到了一个 java.lang.NullPointerException,也尝试了 try 和 catch,因为我对编码很陌生,任何人都可以告诉我为什么会得到空指针异常。

package ObjectRepository;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Properties;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;

public class PropertiesGuru99Bank {
WebDriver driver;
@Test
public void f() {
File file=new File("E:\\selenium\\Rahul\\Project\\src\\ObjectRepository\\object.properties");
FileInputStream f=null;
try {
f=new FileInputStream(file);
} catch (Exception e) {
// TODO: handle exception
System.out.println(e.getStackTrace());
}
Properties prop=new Properties();
try {
prop.load(f);
} catch (Exception e) {
// TODO: handle exception
System.out.println(e.getStackTrace());
}
driver.get(prop.getProperty("url"));
driver.findElement(By.id(prop.getProperty("id"))).sendKeys("rahul");
}
@BeforeTest
public void beforeTest() {
System.setProperty("webdriver.chrome.driver", "E:\\selenium\\lib\\chromedriver_win32\\chromedriver.exe");
new ChromeDriver();
}
@AfterTest
public void afterTest() {
}
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com