Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/346.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 @After和@Before注释未执行第二个方法_Java_Cucumber_Junit4_Bdd - Fatal编程技术网

Java @After和@Before注释未执行第二个方法

Java @After和@Before注释未执行第二个方法,java,cucumber,junit4,bdd,Java,Cucumber,Junit4,Bdd,我在注释后声明了2个方法@after,但它只执行第一个方法,不允许执行第二个方法。请看下面的代码 我想每次执行1个方法退出浏览器。 我想对失败的测试用例执行第二种方法 @Before public void databaseLoading(Scenario scenario) { //System.out.println("Test Environment Set Up"); System.out.println("\n---------------

我在注释后声明了2个方法@after,但它只执行第一个方法,不允许执行第二个方法。请看下面的代码

我想每次执行1个方法退出浏览器。 我想对失败的测试用例执行第二种方法

@Before
public void databaseLoading(Scenario scenario) {
    //System.out.println("Test Environment Set Up");
    System.out.println("\n------------------------------------------------     TEST ENVIRONMENT SET UP      ------------------------------------------------------------------------------\n");
    System.out.println("Executing Scenario :-> " + scenario.getName());
}

@After
public void browserTearDown()
{
    System.out.println("End the browser");
    driver.close();
 }

public void Screenshot(Scenario scenario) {
    // take the screenshot at the end of every test
    String location = ".\\target\\TakeScreenshot";
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy hh-mm-ss", Locale.ENGLISH);
    Date date = new Date();
    File scrFile =
            ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
    // now save the screenshto to a file some place
    if (scenario.isFailed()) {
        try {
            FileUtils.copyFile(scrFile, new File(location + "\\" + dateFormat.format(date) + ".png"));
            System.out.println("Screenshot saved");
        } catch (IOException e) {
            System.out.println("Error in taking Screenshot --> " + e);
        }
    }
}

方法“Screenshot(cumber.api.Scenario)”从未使用过。此错误消息用于第二种方法。

您只标记了
browserTearDown()
方法

@After
标记添加到
屏幕截图()
方法,以及:

@After
public void browserTearDown()
{
    System.out.println("End the browser");
    driver.close();
}

@After
public void Screenshot(Scenario scenario) {
   ...

}

您的@before注释性方法在哪里?您要在测试之前或之后执行的方法必须分别标记为
@before
@after
<代码>屏幕截图(场景)没有标记,来自示例的代码也不会调用它。您可能希望将其改为
@Rule
。划掉规则建议,cucumber可能不支持规则。将撕裂方法提交给lastHi Mate,非常感谢您的帮助。它现在正在工作。