You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TestNG监听器报NullPointerException,如何通过ChromeDriver版本适配解决?

解决TestNGListener onTestFailure方法中的空指针异常

问题现象

在TestNGListener的onTestFailure方法中,执行ValidateUserAbleToDownloadFileOnPartnerConfigurationPage测试方法时出现以下空指针异常:

  • 无法调用org.openqa.selenium.WebDriver.manage(),因为driver对象为空;
  • 无法调用com.im.apac.wrapper.api.IHTMLWebDriver.logFailureAndTakeScreensot(String),因为hDriver对象为空。

完整异常堆栈

Exception in thread "TestNG-test=Test-1" java.lang.NullPointerException: Cannot invoke "com.im.apac.wrapper.api.IHTMLWebDriver.logFailureAndTakeScreensot(String)" because "hDriver" is null
at com.im.apac.utility.listener.TestngListener.onTestFailure(TestngListener.java:130)
at org.testng.internal.TestListenerHelper.runTestListeners(TestListenerHelper.java:67)
at org.testng.internal.Invoker.runTestListeners(Invoker.java:1389)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1042)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:833)

解决方案

若当前使用的ChromeDriver版本为111.0.5563.65,将其降级至110.0.5481版本即可解决该问题。

内容的提问来源于stack exchange,提问作者lalit dhend

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 05:13:18