Skip to main content

Cucumber Before Suite

Like TestNG, we don't have any BeforeSuite hook in JUNIT 4. Consider a case when you have to clean extent report screenshot directory or allure report result directory before running your suite. To perform such BeforeSuite or BeforeAll operations you can use below code.

private static boolean bsuite = false;

public void bf0(Scenario scenario) 
        FileUtils.cleanDirectory(new File(screenshotdir));
        FileUtils.cleanDirectory(new File(allureResults));
        bsuite = true;

Here we have declared a static boolean variable bsuite and set its default value to false. Then inside our @Before hook we are checking if bsuite is true then clean screenshot and allure result directory. During next run of @Before hook bsuite value will be true; and if condition will be false therefore clean directory operations will not be executed.

Submitted by tgoswami on October 22, 2020

Tarun has 11+ years of experience in Quality Assurance in different domains like Banking, E-commerce, Health and Education.


At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.