首页 > 解决方案 > 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

}

标签: javaseleniummavenintellij-ideacucumber

解决方案


该方法不应该是静态的。


推荐阅读