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