testngbddqaf

Qaf BDD2 setup() and teardown ()


I am using QAF framework BDD2 for regression automation. I know how to setup setup() and teardown() webdriver in testNG but I am not sure do we have capability to set up the same QAF BDD2 setup() and teardown(). Kindly help with some examples.

I will provide a usecase which helps to understand exactly I am looking for:

  1. whenever I wanted to run the test suite, I want to create a custom downloads folder in c:/users/XXX. Where this folder contains all my test downloads.
  2. At setup() I want to implement createCustomFolder() method to create the custom folder before the test suite begins
  3. At the end of all tests in test suite. I want to implement teardown() methods where it contains delete files() deletes the files inside the custom folder and delete custom folder() delete the folder.

Solution

  • You can take benefit of testng listener and qaf listeners. For example, in above use case, implement testng suite listener and do the needful in before and after suite methods:

    public class MySuiteListener implements ISuiteListener{
    
       public void onStart(ISuite suite) {
         //create directory
       }
    
       public void onFinish(ISuite suite){
         //delete directory
       }
    
    }
    

    You can register TestNG listener thorough configuration file

    <suite name="MYAPP Tests">
      <listeners>
        <listener class-name="com.example.MySuiteListener" />
      </listeners>
    
      <test name="QAF-BDD-Test">
         <classes>
            <class name="com.qmetry.qaf.automation.step.client.text.BDDTestFactory2" />
         </classes>
    </test>