title: TestNG. Need to run specific method before all tests and specifiic test after all tests
body: <p>Used Selenium + TestNG + Maven. </p>
  
  <p>I want to automate testing vulnerabilities using OWASP ZAP. For this I need to start ZAProxyScanner before all tests - execute method before all tests.</p>
  
  <pre><code>public void initZap(){
          zapScanner = new ZAProxyScanner(ZAP_PROXYHOST,ZAP_PROXYPORT,ZAP_APIKEY);
          zapScanner.clear(); //Start a new session
          zapSpider = (Spider)zapScanner;
  }
  </code></pre>
  
  <p>and when all functional tests were executed - run test for searching vulnerabilities</p>
  
  <pre><code>@Test
  public void scanning() throws ClientApiException{
      spiderWithZap();
      setAlertAndAttackStrength();
      zapScanner.setEnablePassiveScan(true);
      scanWithZap();
  }
  </code></pre>
  
  <p>Method and test located in one class, e.g. <code>public class TestSecurity</code></p>
  
  <p>Here is sample of my testng.xml with packages containing functional tests</p>
  
  <pre><code>&lt;suite name="Chrome" thread-count="1" parallel="tests" configfailurepolicy="continue"&gt;
  &lt;test name="chrome"&gt;
      &lt;parameter name="browser" value="chrome"/&gt;
      &lt;packages&gt;
          &lt;package name="tests.suiteLogIn"&gt;&lt;/package&gt;
          &lt;package name="tests.suiteSettings"&gt;&lt;/package&gt;
          &lt;package name="tests.suiteSearch"&gt;&lt;/package&gt;
      &lt;/packages&gt;    
  &lt;/test&gt;
  </code></pre>
  
  <p></p>
  
  <p>UPD. post modified code with AfterTest in it.
  I use only Before/AfterMethod annotations</p>
  
  <pre><code>    @BeforeMethod(alwaysRun=true)
  @Parameters({"browser", "environment"})
  public void setUp(@Optional ("firefox") String browser, @Optional ("local") String environment, Method method) throws IOException {
      System.out.println("Test name: " + method.getName());  
      WebDriver driver = getMyDriver(browser, environment);
      System.setProperty(ESCAPE_PROPERTY, "false");
  }
  
  @AfterMethod(alwaysRun=true)
  @Parameters("browser")
  public void tearDown(@Optional ("firefox") String browser){
      DriverMaster.stopDriver();
  }
  
  @BeforeSuite
  @Parameters("browser")
  public void startZap(@Optional ("firefox") String browser){
      if(browser.equals("firefox")){
          sec.initZap();
      }
  }
  
  @AfterSuite
  @Parameters("browser")
  public void scanZap(@Optional ("firefox") String browser) throws ClientApiException{
      if(browser.equals("firefox")){
          LoginPage lp = new LoginPage(getDriverInstance()).load();
          lp.login("name", "pass");
          sec.scanning();
      }
  }
  </code></pre>