1   package com.atlassian.selenium;
2   
3   import org.junit.runner.notification.RunNotifier;
4   import org.junit.runners.BlockJUnit4ClassRunner;
5   import org.junit.runners.model.InitializationError;
6   
7   /**
8    * A test runner that registers a listener {@link it.com.atlassian.applinks.CaptureScreenshotListener}
9    * to capture screenshots if a test fails.
10   *
11   * @since 2.0
12   */
13  public class SeleniumJUnit4ClassRunner extends BlockJUnit4ClassRunner
14  {
15      /**
16       * Creates a BlockJUnit4ClassRunner to run {@code klass}
17       *
18       * @throws org.junit.runners.model.InitializationError if the test class is malformed.
19       */
20      public SeleniumJUnit4ClassRunner(Class<?> klass) throws InitializationError
21      {
22          super(klass);
23      }
24  
25      @Override
26      public void run(final RunNotifier notifier)
27      {
28          CaptureScreenshotListener listener = new CaptureScreenshotListener();
29          notifier.addListener(listener);
30          super.run(notifier);
31          notifier.removeListener(listener);
32      }
33  }