title: How to get at test field from TestNG IInvokedMethodListener?
body: <p>I'm using TestNG 6.8 + Selenium WebDriver 2.32 to test the GUI of a web app. In cases of failed tests I would like to take a screenshot of application GUI.</p>
  
  <p>What I have: </p>
  
  <ul>
  <li>I can detect test failure by implementing testng's <code>IInvokedMethodListener</code></li>
  <li>I also know how to use a webdriver to take a screenshot</li>
  </ul>
  
  <p>What I need:</p>
  
  <ul>
  <li>to get at my WebDriver instance declared in my AbstractGuiTest class to take a screenshot.</li>
  </ul>
  
  <p>Here's a skeleton of my code:</p>
  
  <pre><code>import org.testng.annotations.Listeners;
  ...
  @Listeners(GuiTestListener.class)
  public abstract class AbstractGuiTest {
      protected WebDriver driver; //Used by all tests
      ...
  }
  </code></pre>
  
  <p>And here's my test listener class, that reacts to failed tests:</p>
  
  <pre><code>public class GuiTestListener implements IInvokedMethodListener {
      @Override
      public void afterInvocation(IInvokedMethod method, ITestResult itr) {
          if (method.isTestMethod() &amp;&amp; !itr.isSuccess()) {
              //Take a screenshot here. But how do I get at the intance of WebDriver declared in the AbstractGuiTest?
          }
      }
  }
  </code></pre>
  
  <p>Can you please suggest a way how to get at the instance of WebDriver declared in the AbstractGuitTest, so that I can use it to take a screenshot in the GuiTestListener class?</p>