Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何解决:cucumber.runtime.CucumberException:未能实例化类com.philips.rs.ui.stepdefs.LoginSteps_Java_Exception_Junit_Constructor_Cucumber - Fatal编程技术网

Java 如何解决:cucumber.runtime.CucumberException:未能实例化类com.philips.rs.ui.stepdefs.LoginSteps

Java 如何解决:cucumber.runtime.CucumberException:未能实例化类com.philips.rs.ui.stepdefs.LoginSteps,java,exception,junit,constructor,cucumber,Java,Exception,Junit,Constructor,Cucumber,我正在开发一个页面对象模型框架,但我面临无法实例化类的异常 请检查我的方法 按照这种方法,我将面临无法实例化的异常,但这种异常不会在第一个场景中出现,从第二个场景开始,驱动器不会启动。请告诉我哪里出了问题 我在ScenarioCleanUp类中有@After,其中webDriver已关闭 public class ScenarioCleanUp { public static final Logger logger = Logger.getLogger(BrowserTest.cla

我正在开发一个页面对象模型框架,但我面临无法实例化类的异常

请检查我的方法

按照这种方法,我将面临无法实例化的异常,但这种异常不会在第一个场景中出现,从第二个场景开始,驱动器不会启动。请告诉我哪里出了问题

我在ScenarioCleanUp类中有@After,其中webDriver已关闭

public class ScenarioCleanUp  {

    public static final Logger logger = Logger.getLogger(BrowserTest.class);
    public WebDriver driver = UITestUtils.driver;

    @After()
    public void tearDown(Scenario scenario) throws Exception {
        System.out.println("---------Closing the Sceanrio-----------------");
        if (scenario.isFailed())
        {
            System.out.println("Came Inside Scenario Failed");
            DateFormat df = new SimpleDateFormat("ddMMyyHHmmss");
            Date dateobj = new Date();
            logger.info("CurrentDate used for concating the sceenshot: " + df.format(dateobj));

            logger.error("The Scenario is failed: " + scenario.getName());
            scenario.write("Current Page URL is " + driver.getCurrentUrl());

            String filename = scenario.getName();
            filename = filename.replaceAll("\"", "");
            filename = filename.replaceAll("\\s+", "_");
            filename = filename + df.format(dateobj) + ".jpg";

            new UITestUtils().takeSnapShot(driver,filename);
        }
        if(driver!= null)
        {
        System.out.println("Driver is not null");
        driver.close();
        }

    }
}


这是因为UITestUtils构造函数仅在第一个场景中调用,并且在第二个场景中关闭浏览器。对于第二个或更多场景,将不调用此构造。有两种解决方案

  • 在后一种情况下,不要关闭浏览器。或
  • 将构造函数UITestUtils设为方法,并像hook之前一样添加它。这样每次浏览器都会打开,并保持after scenario钩子的原样