1   package com.atlassian.selenium;
2   
3   import com.atlassian.performance.junit.PerformanceTest;
4   import com.atlassian.performance.TimeRecorder;
5   import junit.framework.TestCase;
6   
7   /**
8    * A base class for selenium tests
9    *
10   * @since v3.12
11   */
12  public abstract class SeleniumTest extends TestCase implements PerformanceTest
13  {
14      protected SeleniumAssertions assertThat;
15      protected SeleniumClient client;
16      protected SeleniumConfiguration config;
17      protected TimeRecorder recorder;
18  
19      public abstract SeleniumConfiguration getSeleniumConfiguration();
20  
21      /**
22       * Calls overridden onSetup method before starting
23       * the selenium client and possibly server and initiating
24       * assertThat and interaction variables
25       */
26      public final void setUp() throws Exception
27      {
28          super.setUp();
29          config = getSeleniumConfiguration();
30  
31          if (SeleniumStarter.getInstance().isManual())
32          {
33              SeleniumStarter.getInstance().start(config);
34          }
35  
36          client = getSeleniumClient();
37          recorder = new TimeRecorder(this.getClass().getName());
38  
39          assertThat = new SeleniumAssertions(client, config, recorder);
40          onSetUp();
41      }
42  
43      /**
44       * Gets the SeleniumClient. Override this method if you would like to return your
45       * own implementation of {@link SeleniumClient}.
46       * @return New or current selenium client
47       */
48      protected SeleniumClient getSeleniumClient()
49      {
50          return SeleniumStarter.getInstance().getSeleniumClient(getSeleniumConfiguration());
51      }
52  
53      /**
54       * To be overridden in the case of test-specific setup activities
55       */
56      protected void onSetUp() throws Exception
57      {
58      }
59  
60      /**
61       * Calls overridden onTearDown method before shutting down
62       * the selenium client and possibly server
63       */
64      public final void tearDown() throws Exception
65      {
66          super.tearDown();
67          onTearDown();
68          
69          if (SeleniumStarter.getInstance().isManual())
70          {
71              SeleniumStarter.getInstance().stop();
72          }
73      }
74  
75      /**
76       * To be overridden in the case of test-specific tear-down activities
77       */
78      protected  void onTearDown() throws Exception
79      {
80      }
81  
82      public TimeRecorder getRecorder()
83      {
84          return recorder;
85      }
86  }