title: Variable outside local scope is not defined for test case
body: <p>I wish to access outside variables for a test function that I am writing, in Groovy. </p>
  
  <p>However, it doesn't seem that I can. </p>
  
  <p>My code is like this: </p>
  
  <pre><code>Map&lt;String, String&gt; originalTableRowState = new HashMap&lt;String, String&gt;(),
      newTableRowState
  
  // if there is table data to get, and do actions on
  def WebDriver driver = DriverFactory.getWebDriver()
  def List&lt;WebElement&gt; dataRows = driver.findElements(
      By.cssSelector('div.tab-pane.active .dataTables_scrollBody tbody tr:not(.dataTables_empty)'))   
  
  'if there\'s table data, this test should run'
  if (dataRows.size() &gt; 0) {
  
      WebUI.comment('populate the tableRowState with the data from the first table row')
      fetchFirstRowDataInto(originalTableRowState)    
  
  }
  
  
  void fetchFirstRowDataInto(Map&lt;String, String&gt; tableRowState) { 
      List&lt;WebElement&gt; tableHeadings = driver.findElements(
          By.cssSelector('div.tab-pane.active .dataTables_scrollHead th'))
      WebElement firstRow = dataRows.get(0)
      List&lt;WebElement&gt; dataCells = firstRow.findElements(
          By.xpath('//td[not(@class="dataTables_empty") and not(*)]'))
      for (int i = 0; i &lt; dataCells.size(); i++) {
          // save data to originalTableRowState with the table header text as the key
          tableRowState.put(tableHeadings.get(i), dataCells.get(i))
      }
  }
  </code></pre>
  
  <p>and when I run it, it greets me with the error saying that <code>Variable 'driver' is not defined outside test case</code>. I just added the <code>def</code> keywords to the <code>driver</code>,<code>dataRows</code> definintions. </p>
  
  <p>How to make <code>driver</code>,<code>dataRows</code> accessible inside functions, without passing them in as parameters?</p>