java - Java黄瓜Selenium:NullPointerException for scenario.write for the first scenario on before tag
问题描述
执行以下代码时,我收到 NullPointerException。请注意,仅在执行的第一个黄瓜场景中收到异常。第二种情况也不例外。我实际上是在尝试在每个场景开始之前插入时间戳。请告知如何解决此问题。任何帮助将不胜感激。
@Before //cucumber.api.java
public void beforeScenario(Scenario scenario1)
{
this.scenario=scenario1; //I would need this for a later use.
scenario1.write("Start Time:"+new Date()); //Nullpointerexception
}
我也试过这个,但同样的错误。
@Before //cucumber.api.java
public void beforeScenario(Scenario scenario)
{
this.scenario=scenario; //wont matter if i have this or not
scenario1.write("Start Time:"+new Date()); //Nullpointerexception
}
解决方案
该方法不应该是静态的。
推荐阅读
- sql - 如何在元数据库的 LIKE 查询中使用变量?
- python - 错误:标签 [0] 不在 [index] 中
- python - IOError:[Errno 2] 没有这样的文件或目录:(Python:即使文件确实存在,我也会遇到此错误)
- java - 当我使用 Apache Storm 运行我的 JAR 时,为什么会引发 java.lang.NoClassDefFoundError ?(org/apache/storm/kafka/spout/KafkaSpoutConfig)
- vector - 如何将两个 Rust 向量按三个块交错成一个新向量?
- laravel - 从 laravel 的视图中传递值和调用控制器
- docker - 在 Docker-Compose 和 GitLab-CI 之间共享环境变量
- vba - Office 365 更新后清除办公室剪贴板不起作用
- python - 关于寻找最短距离 Picode
- edi - 如何使用 EDI.Net 解析包含多个项目的 EDIfact 文件?