<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>selenium-driver/src/com/yahoo/platform/yui/selenium/TestConfig.java</filename>
    </added>
    <added>
      <filename>selenium-driver/src/com/yahoo/platform/yui/selenium/TestConfigHandler.java</filename>
    </added>
    <added>
      <filename>selenium-driver/src/com/yahoo/platform/yui/selenium/TestPage.java</filename>
    </added>
    <added>
      <filename>selenium-driver/src/com/yahoo/platform/yui/selenium/TestPageGroup.java</filename>
    </added>
    <added>
      <filename>selenium-driver/src/com/yahoo/platform/yui/selenium/TestResult.java</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,6 +1,9 @@
 /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
+ * YUI Test Selenium Driver
+ * Author: Nicholas C. Zakas &lt;nzakas@yahoo-inc.com&gt;
+ * Copyright (c) 2009, Yahoo! Inc. All rights reserved.
+ * Code licensed under the BSD License:
+ *     http://developer.yahoo.net/yui/license.txt
  */
 
 package com.yahoo.platform.yui.selenium;
@@ -11,24 +14,51 @@ import java.io.OutputStreamWriter;
 import java.io.Writer;
 import java.text.SimpleDateFormat;
 import java.util.Date;
+import java.util.List;
 import java.util.Properties;
 
 /**
- *
- * @author nzakas
+ * Handles generating results files for a SeleniumDriver with the same set of
+ * properties.
+ * @author Nicholas C. Zakas
  */
 public class FileGenerator {
 
     private boolean verbose = false;
     private Properties properties = null;
 
-
     public FileGenerator(Properties properties, boolean verbose){
         this.properties = properties;
         this.verbose = verbose;
     }
 
-    public void generate(String name, String results, String type, String browser) throws Exception {
+    public void generateAll(List&lt;TestResult&gt; results, Date timestamp) throws Exception {
+        for (int i=0; i &lt; results.size(); i++){
+            generateAll(results.get(i), timestamp);
+        }
+    }
+
+    public void generateAll(TestResult[] results, Date timestamp) throws Exception {
+        for (int i=0; i &lt; results.length; i++){
+            generateAll(results[i], timestamp);
+        }
+    }
+
+    public void generateAll(TestResult result, Date timestamp) throws Exception {
+
+        //generate test results file
+        if (result.hasReport(&quot;results&quot;)){
+            generate(result, &quot;results&quot;, timestamp);
+        }
+
+        //generate test coverage file
+        if (result.hasReport(&quot;coverage&quot;)){
+            generate(result, &quot;coverage&quot;, timestamp);
+        }
+
+    }
+
+    private void generate(TestResult result, String type, Date timestamp) throws Exception {
         String dirname = properties.getProperty(type + &quot;.outputdir&quot;);
         String filenameFormat = properties.getProperty(type + &quot;.filename&quot;);
 
@@ -41,7 +71,7 @@ public class FileGenerator {
         }
 
         //format filename
-        String filename = filenameFormat.replace(&quot;{browser}&quot;, browser.replace(&quot;*&quot;, &quot;&quot;)).replace(&quot;{name}&quot;, name).trim();
+        String filename = filenameFormat.replace(&quot;{browser}&quot;, result.getBrowser().replace(&quot;*&quot;, &quot;&quot;)).replace(&quot;{name}&quot;, result.getName()).trim();
 
         int pos = filename.indexOf(&quot;{date:&quot;);
 
@@ -51,11 +81,10 @@ public class FileGenerator {
             String format = filename.substring(pos + 6, endpos);
 
             //get the format
-            Date now = new Date();
             SimpleDateFormat formatter = new SimpleDateFormat(format);
 
             //insert into filename
-            filename = filename.replace(&quot;{date:&quot; + format + &quot;}&quot;, formatter.format(now));
+            filename = filename.replace(&quot;{date:&quot; + format + &quot;}&quot;, formatter.format(timestamp));
         }
 
         filename = filename.replaceAll(&quot;[^a-zA-Z0-9\\.\\-]&quot;, &quot;_&quot;).replaceAll(&quot;_+&quot;, &quot;_&quot;);
@@ -66,7 +95,7 @@ public class FileGenerator {
 
         //output to file
         Writer out = new OutputStreamWriter(new FileOutputStream(dirname + File.separator + filename), &quot;UTF-8&quot;);
-        out.write(results);
+        out.write(result.getReport(type));
         out.close();
 
     }</diff>
      <filename>selenium-driver/src/com/yahoo/platform/yui/selenium/FileGenerator.java</filename>
    </modified>
    <modified>
      <diff>@@ -11,7 +11,10 @@ package com.yahoo.platform.yui.selenium;
 import com.thoughtworks.selenium.DefaultSelenium;
 import com.thoughtworks.selenium.Selenium;
 import com.thoughtworks.selenium.SeleniumException;
+import java.util.Date;
 import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
 import java.util.Properties;
 
 
@@ -99,13 +102,19 @@ public class SeleniumDriver {
     public void start() throws Exception{
         
         getURLsAndBrowsers();
-        
+
+        List&lt;TestResult&gt; results = new LinkedList&lt;TestResult&gt;();
+
+        //do the tests
         for(int i=0; i &lt; urls.length; i++){
             for (int j=0; j &lt; browsers.length; j++){
-                runTest(browsers[j], urls[i]);
+                results.add(runTest(browsers[j], urls[i]));
             }
         }
-        
+
+        //output the results
+        FileGenerator generator = new FileGenerator(properties, verbose);
+        generator.generateAll(results, new Date());        
     }
     
     /**
@@ -114,48 +123,67 @@ public class SeleniumDriver {
      * @param url The URL of the YUI Tests to run.
      * @throws java.lang.Exception
      */
-    private void runTest(String browser, String url) throws Exception {
-        
+    private TestResult runTest(String browser, String url) throws Exception {
+
+        Selenium selenium = null;
+
+        try {
+            selenium = new DefaultSelenium(properties.getProperty(SELENIUM_HOST),
+                    Integer.parseInt(properties.getProperty(SELENIUM_PORT)), browser, url);
+            
+            selenium.start();
+
+            return runTest(selenium, browser, url);
+
+        } catch (Exception ex){
+            //TODO: What should happen here? Default file generation?
+            throw ex;
+        } finally {
+            if (selenium != null){
+                selenium.stop();
+            }
+        }
+    }
+    
+    /**
+     * Runs a YUI Test url against a given browser.
+     * @param browser The Selenium browser to run against.
+     * @param url The URL of the YUI Tests to run.
+     * @throws java.lang.Exception
+     */
+    private TestResult runTest(Selenium selenium, String browser, String url) throws Exception {
+
         //basic YUI Test info
         String yuitestVersion = properties.getProperty(&quot;yuitest.version&quot;, &quot;2&quot;);
         String testRunner = jsWindow + &quot;.&quot; + testRunners.get(yuitestVersion);
         String testFormat = jsWindow + &quot;.&quot; + testFormats.get(yuitestVersion);
         String coverageFormat = jsWindow + &quot;.&quot; + coverageFormats.get(yuitestVersion);
-                
+
         //JS strings to use
         String testRunnerIsNotRunning = &quot;!&quot; + testRunner + &quot;.isRunning()&quot;;
-        String testResults = testRunner + &quot;.getResults(&quot; + testFormat + &quot;.&quot; + 
+        String testResults = testRunner + &quot;.getResults(&quot; + testFormat + &quot;.&quot; +
                 properties.getProperty(&quot;results.format&quot;, &quot;JUnitXML&quot;) +
-                &quot;);&quot;;    
-        String testCoverage = testRunner + &quot;.getCoverage(&quot; + coverageFormat + &quot;.&quot; + 
+                &quot;);&quot;;
+        String testCoverage = testRunner + &quot;.getCoverage(&quot; + coverageFormat + &quot;.&quot; +
                 properties.getProperty(&quot;coverage.format&quot;, &quot;JSON&quot;) +
                 &quot;);&quot;;
         String testName = testRunner + &quot;.getName();&quot;;
-        
-        if (verbose){
-            System.err.println(&quot;[INFO] Starting browser '&quot; + browser + &quot;'&quot;);
-        }
-        
-        Selenium selenium = null;
+
+        //extracted from page
         String results = &quot;&quot;;
         String coverage = &quot;&quot;;
         String name = &quot;&quot;;
-        
+
         //run the tests
         try {
-            //start up selenium
-            selenium = new DefaultSelenium(properties.getProperty(SELENIUM_HOST),
-                    Integer.parseInt(properties.getProperty(SELENIUM_PORT)), browser, url);
-            
-            selenium.start();
             selenium.open(url);
-            
+
             if (verbose){
                 System.err.println(&quot;[INFO] Navigating to '&quot; + url + &quot;'&quot;);
-            }            
+            }
 
             selenium.waitForPageToLoad(properties.getProperty(&quot;selenium.waitforload&quot;, &quot;10000&quot;));
-            
+
             if (verbose){
                 System.err.println(&quot;[INFO] Page is loaded.&quot;);
             }
@@ -163,43 +191,35 @@ public class SeleniumDriver {
             selenium.waitForCondition(testRunnerIsNotRunning, properties.getProperty(&quot;selenium.waitfordone&quot;, &quot;1000000&quot;));
 
             if (verbose){
-                System.err.println(&quot;[INFO] Tests are complete.&quot;);
-            }            
-            
+                System.err.println(&quot;[INFO] Test complete.&quot;);
+            }
+
             //get results
-            results = selenium.getEval(testResults);            
+            results = selenium.getEval(testResults);
+            if (results.equals(&quot;null&quot;)){
+                results = null;
+            }
+
             coverage = selenium.getEval(testCoverage);
+            if (coverage.equals(&quot;null&quot;)){
+                coverage = null;
+            }
+
             name = selenium.getEval(testName);
 
+            return new TestResult(name, browser, url, results, coverage);
+
         } catch (SeleniumException ex){
 
             //probably not a valid page
             throw new Exception(&quot;Selenium failed with message: &quot; + ex.getMessage() + &quot;. Check the test URL &quot; + url + &quot; to ensure it is valid.&quot;, ex);
 
         } catch (Exception ex){
-            //TODO: What should happen here? Default file generation?
             throw ex;
-        } finally {
-            if (selenium != null){
-                selenium.stop();
-            }
-        }
+        } 
+    }
+
 
-        //save the results
-        try {
-            FileGenerator generator = new FileGenerator(properties, verbose);
-            //output the reports
-            generator.generate(name, results, &quot;results&quot;, browser);
-            if (!coverage.equals(&quot;null&quot;)){
-                generator.generate(name, coverage, &quot;coverage&quot;, browser);
-            }
-            
-        } catch (Exception ex){
-            //what to do?
-            throw ex;
-        }
-    }        
-    
     private void getURLsAndBrowsers() throws Exception {
         
         //try to get list of URLs to hit
@@ -214,6 +234,10 @@ public class SeleniumDriver {
             throw new Exception(&quot;The configuration property 'selenium.browsers' is missing.&quot;);
         }
     }
+
+    private void outputResultsToConsole(){
+
+    }
             
 
 }</diff>
      <filename>selenium-driver/src/com/yahoo/platform/yui/selenium/SeleniumDriver.java</filename>
    </modified>
    <modified>
      <diff>@@ -114,6 +114,10 @@ public class YUITestSeleniumDriver {
             SeleniumDriver driver = new SeleniumDriver(properties, verbose);
             driver.start();
 
+            //TestConfig config = new TestConfig();
+            //config.load(new FileInputStream(&quot;../example/tests.xml&quot;));
+
+            
         } catch (CmdLineParser.OptionException e) {
 
             usage();
@@ -122,7 +126,7 @@ public class YUITestSeleniumDriver {
         } catch (Exception e) {
 
             System.err.println(&quot;[ERROR] &quot; + e.getMessage());
-            //e.printStackTrace();
+            e.printStackTrace();
             System.exit(1);
 
 //        } catch (Exception e) {</diff>
      <filename>selenium-driver/src/com/yahoo/platform/yui/selenium/YUITestSeleniumDriver.java</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>789d542c85849c80df4fd42f0812edc8dc25da56</id>
    </parent>
  </parents>
  <author>
    <name>Nicholas</name>
    <email>nzakas@yahoo-inc.com</email>
  </author>
  <url>http://github.com/nzakas/yuitest/commit/abf556c36917d183773a80d6450c5365c223216a</url>
  <id>abf556c36917d183773a80d6450c5365c223216a</id>
  <committed-date>2009-11-06T16:17:16-08:00</committed-date>
  <authored-date>2009-11-06T16:17:16-08:00</authored-date>
  <message>Added XML configuration file reading</message>
  <tree>6b6ef7618c16f4fa0b4d37167413569ebad91c6e</tree>
  <committer>
    <name>Nicholas</name>
    <email>nzakas@yahoo-inc.com</email>
  </committer>
</commit>
