当我尝试以testng的身份运行此错误
java.lang.NullPointerException
at java.util.Hashtable.put(Unknown Source)
at java.util.Properties.setProperty(Unknown Source)
at java.lang.System.setProperty(Unknown Source)
at com.w2a.base.TestBase.setUp(TestBase.java:38)
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.invokeConfigurationMethod(Invoker.java:523)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:224)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:146)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:326)
at org.testng.SuiteRunner.run(SuiteRunner.java:289)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1226)
at org.testng.TestNG.runSuites(TestNG.java:1144)
at org.testng.TestNG.run(TestNG.java:1115)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
某些软件包可能是旧的,但是我指的是旧教程,是否是由于我使用的是旧软件包?
这是我的TestBase类
public class TestBase {
public static WebDriver driver;
public static Properties config = new Properties();
public static Properties OR = new Properties();
public static FileInputStream fis;
@BeforeSuite
public void setUp() throws IOException {
if(driver == null) {
FileInputStream fis = new FileInputStream("C:\\Users\\acer\\eclipse-workspace\\DataDrivenFramework\\src\\test\\resources\\properties\\Config.properties");
config.load(fis);
System.out.println(config.getProperty("browser"));
fis = new FileInputStream("C:\\Users\\acer\\eclipse-workspace\\DataDrivenFramework\\src\\test\\resources\\properties\\OR.properties");
OR.load(fis);
}
if(config.getProperty("browser").equals("chrome")) {
System.out.println("You won");
System.setProperty("webdriver.chrome.driver",System.getProperty("C:\\Users\\acer\\eclipse-workspace\\DataDrivenFramework\\src\\test\\resources\\executables\\chromedriver.exe"));
driver = new ChromeDriver();
}
System.out.println("You won");
driver.get(config.getProperty("testsiteurl"));
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(Integer.parseInt(config.getProperty("implicit.wait")), TimeUnit.SECONDS);
//}
}
@AfterSuite
public void tearDown() {
if(driver != null)
driver.quit();
}
}
为什么这个testng测试用例失败?
我正在使用chromedriver.exe 2.28。
答案 0 :(得分:2)
您必须在System.setProperty
中输入值:
System.setProperty("webdriver.chrome.driver","C:\\Users\\acer\\eclipse-workspace\\DataDrivenFramework\\src\\test\\resources\\executables\\chromedriver.exe");