title: Geb with spock and closing the browser window
body: <p>So I wrote my first Geb script which extends the GebReportingSpec. I have specified a def cleanup in which I do a driver.quit(). Now the browser does close but I am getting an error cause the screenshot utility cannot run cause I guess it runs after the browser is closed. I tried putting in a sleep to see if that was the problem but that did nothing</p>
  
  <hr>
  
  <pre><code>JUnit 4 Runner, Tests: 1, Failures: 1, Time: 25944Test Failure: Validate that the default time zone for store is set to America/New_York(groovy.manager.ReferenceStoreDefaultTimeZoneTests)org.openqa.selenium.remote.SessionNotFoundException: The FirefoxDriver cannot be used after quit() was called.Build info: version: '2.31.0', revision: '1bd294d185a80fa4206dfeab80ba773c04ac33c0', time: '2013-02-27 13:51:26'System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.8.3', java.
  version: '1.6.0_43'
  Driver info: driver.version: RemoteWebDriver
          at org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor.execute
  (FirefoxDriver.java:352)
          at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.ja
  va:527)
          at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.ja
  va:569)
          at org.openqa.selenium.remote.RemoteWebDriver.getPageSource(RemoteWebDri
  ver.java:414)
          at geb.report.PageSourceReporter.getPageSource(PageSourceReporter.groovy
  :39)
          at geb.report.PageSourceReporter.writePageSource(PageSourceReporter.groo
  vy:35)
          at geb.report.PageSourceReporter.writeReport(PageSourceReporter.groovy:2
  7)
          at geb.report.ScreenshotAndPageSourceReporter.writeReport(ScreenshotAndP
  ageSourceReporter.groovy:31)
          at geb.Browser.report(Browser.groovy:731)
          at geb.spock.GebReportingSpec.report(GebReportingSpec.groovy:43)
          at geb.spock.GebReportingSpec.cleanup(GebReportingSpec.groovy:39)
  </code></pre>
  
  <hr>
  
  <p>Thoughts?</p>
  
  <p>EDIT: </p>
  
  <p>The driver is getting created via the GebConfig file</p>
  
  <pre><code>@Grab(group='org.seleniumhq.selenium', module='selenium-firefox-driver', 
      version='2.31.0')
  @Grab(group='org.seleniumhq.selenium', module='selenium-chrome-driver', 
      version='2.31.0')
  @Grab(group='org.seleniumhq.selenium', module='selenium-htmlunit-driver', 
      version='2.31.0')
  @Grab("org.seleniumhq.selenium:selenium-support:2.28.0")
  
  import org.openqa.selenium.firefox.FirefoxDriver
  import org.openqa.selenium.chrome.ChromeDriver
  import org.openqa.selenium.htmlunit.HtmlUnitDriver
  
  reportsDir = "target/geb-reports"
  
  // default is to use firefox
  driver = {
      def driver = new FirefoxDriver()
      driver.manage().window().maximize()
      return driver
  }
  
  environments {
      'chrome' {
          def chromePath = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
          System.setProperty("webdriver.chrome.driver", chromePath)
  
          driver = {
              def driver = new ChromeDriver()
              return driver
          }
      }
  
      'firefox' {
          driver = {
              def driver = new FirefoxDriver()
              driver.manage().window().maximize()
              return driver
          }   
      }
  
      'htmlunit' {
          driver = {
              def driver = new HtmlUnitDriver()
              driver.javascriptEnabled = true
              return driver
          }   
      }
  }
  </code></pre>
  
  <p>Here is the script that is being executed</p>
  
  <pre><code>package groovy.manager
  
  @Grab( 'org.spockframework:spock-core:0.7-groovy-2.0' )
  @Grab(group='org.gebish', module='geb-core', version='0.9.0-RC-1')
  @Grab(group='org.gebish', module='geb-spock', version='0.9.0-RC-1')
  @Grab(group='org.seleniumhq.selenium', module='selenium-firefox-driver', 
      version='2.31.0')
  
  import geb.spock.GebReportingSpec
  import org.openqa.selenium.firefox.FirefoxDriver
  import groovy.manager.pages.LoginPage
  import groovy.manager.pages.org.OrganizationHomePage
  import groovy.manager.pages.org.OrganizationProfilePage
  
  class ReferenceStoreDefaultTimeZoneSpec extends GebReportingSpec {
  
      def "Validate that the default time zone is set to America/New_York"() {
          given: "You have the admin username and password"
              def username = "admin"
              def password = "test"
  
          when: "Navigate to Manager"
              to LoginPage
  
          and: "Log intoManager"
              usernameInput().value username
              passwordInput().value password
              submitBtn().click()
  
          then:
              assert at (OrganizationHomePage)
  
          and:
              assert ( {$("a[value='America/New York']")} )
  
          when: "Navigate to the organization profile"
              timeZoneLink().click()
  
          then:
              assert at (OrganizationProfilePage)
  
          and: "Verify America New York is selected"
              assert ( $("span", text: contains("America/New York")) )
      }
  }
  </code></pre>