1   package com.atlassian.selenium;
2   
3   import com.atlassian.performance.junit.PerformanceListener;
4   import com.atlassian.performance.PerformanceReporter;
5   import junit.framework.*;
6   
7   import java.io.File;
8   import java.io.IOException;
9   
10  /**
11   * A skeleton test suite for Selenium tests. The run method starts the selenium server (if the
12   * selenium configuration class has been set to allow this.
13   *
14   * @since v3.12
15   */
16  public abstract class SeleniumTestSuite extends TestSuite
17  {
18  
19      /**
20       * To be implemented by users of this class.
21       * @return an implementation of the SeleniumConfiguration interface containing the appropriate
22       * selenium configuration information.
23       */
24      protected abstract SeleniumConfiguration getSeleniumConfiguration();
25  
26  
27      /**
28       * A special run methods that, depending on the SeleniumConfiguration, will start the selenium
29       * server and client.
30       * @param testResult Test results class to be passed to parent
31       */
32      public final void run(TestResult testResult)
33      {
34          SeleniumConfiguration config = getSeleniumConfiguration();
35  
36          SeleniumStarter.getInstance().start(config);
37          SeleniumStarter.getInstance().setManual(false);
38  
39          PerformanceReporter reporter = new PerformanceReporter();
40  
41          testResult.addListener(new PerformanceListener(reporter));
42  
43          super.run(testResult);
44  
45          SeleniumStarter.getInstance().stop();
46  
47          if(config.getPerformanceReportLocation() != null)
48          {
49              System.out.println("SeleniumTestSuite.run log file = " + config.getPerformanceReportLocation());
50              File reportFile = new File(config.getPerformanceReportLocation());
51              try
52              {
53                  reporter.writeReport(reportFile, config.getShowAutoGeneratedPerformanceEvents());
54              }
55              catch(IOException ioe)
56              {
57                  throw new RuntimeException("Unable to write performance log file: " + reportFile, ioe);
58              }
59          }
60  
61      }
62  
63  
64  }