title: Geb Reporter / Extension to retrieve Test Status
body: <p>I am attempting to replace some custom java selenium extensions by utilizing <a href="http://www.gebish.org/" rel="nofollow">geb</a>. I have hit a bit of a brick wall when I attempt to utilize a grid in the cloud (i.e. <a href="https://saucelabs.com" rel="nofollow">SauceLabs</a>). When my tests complete, it'd be nice to send an update back to indicate whether or not the test has failed or succeeded. To utilize this, I need the sessionId from the RemoteWebDriver instance. This can be obtained in a custom <a href="http://www.gebish.org/manual/current/api/geb/report/Reporter.html" rel="nofollow">Reporter</a>, however I can't determine the success with this interface. Since I am extending the <a href="http://www.gebish.org/manual/current/api/geb/spock/GebReportingSpec.html" rel="nofollow">GebReportingSpec</a>, I attempted to create my own custom version, which had a custom Junit rule to track success or failure:</p>
  
  <pre><code>public class TestSuccess extends TestWatcher {
    boolean success;
    String message;
  
    @Override
    protected void starting(Description d) {
      message = d.getMethodName();
    }
  
    @Override
    protected void succeeded(final Description description) {
      System.out.println("Test Success [succeeded] " + description);
      this.success = true;
    }
  
    @Override
    protected void failed(final Throwable e, final Description description) {
      System.out.println("Test Success [failed] " + description);
      this.success = false;
    }
  
    public boolean isSuccess() {
      return success;
    }
  
    @Override
    public String toString() {
      return message + " success: &lt;" + success + "&gt;.";
    }
  }
  </code></pre>
  
  <p>I then added that to my CustomReportingSpec:</p>
  
  <pre><code>class CustomReportingSpec extends GebReportingSpec {
    /* I also tried creating this as a RuleChain with:
     * @Rule TestRule chain = RuleChain.outerRule(
               super._gebReportingSpecTestName).around(new TestSuccess());
     * however, this results in a NPE.  Placing the super rule in the around 
     * still results in a NPE.
     */
    @Rule public TestSuccess _gebTestSuccesswatcher = new TestSuccess();
  
    // I never see this called
    void report() {
      System.out.println("Custom Reporting Spec: " + _gebTestSuccesswatcher + "\t")
      super.report()
    }
  }
  </code></pre>
  
  <p>I have also attempted to set this up in a custom reporter:</p>
  
  <pre><code>public CustomReporter extends ScreenshotAndPageSourceReporter implements Reporter {
    @Rule
    public TestSuccess _gebTestSuccesswatcher = new TestSuccess();
  
    @Override
    public void writeReport(Browser browser, String label, File outputDir) {
      System.out.println("Custom Reporter: " + _gebTestSuccesswatcher);
      super.writeReport(browser, label, outputDir)
    }
  }
  </code></pre>
  
  <p>However, regardless of whether or not my test fails, the success method on the watcher seems to be called.  Here is my sample test:</p>
  
  <pre><code>class OneOff extends CustomReportingSpec {
    def "Check One off"() {
      when:
        go "http://www.google.com"
      then:
        1 == 2
    }
  }
  </code></pre>
  
  <p>And the output:</p>
  
  <pre><code>Custom Reporter: null success: &lt;false&gt;.
  Test Success [succeeded] Check One off(OneOff)
  </code></pre>
  
  <p>As you can see the success method is called upon completion of this failing test. If I modify the test to pass (i.e. 1 == 1), here is my output:</p>
  
  <pre><code>Custom Reporter: null success: &lt;false&gt;.
  Test Success [succeeded] Check One off(OneOff)
  </code></pre>
  
  <p>Is there any way for me to get this Rule to work properly in the Custom Reporter? Or is there a way to get the browser instance in an extension? I've followed <a href="http://ldaley.com/post/971946675/annotation-driven-extensions-with-spock" rel="nofollow">this guide</a> to create a custom annotation and listener, but I can't access the Browser object. I have attempted adding an @Shared onto the declaration of the browser, but it isn't pulling the one in the Geb Configuration.</p>