View Javadoc

1   package com.atlassian.webdriver.testing.rule;
2   
3   import com.google.inject.Inject;
4   import org.junit.rules.RuleChain;
5   import org.junit.rules.TestRule;
6   import org.junit.runner.Description;
7   import org.junit.runners.model.Statement;
8   
9   /**
10   * <p/>
11   * A version of default, recommended rules that is injectable into the test. Use together with
12   * {@link com.atlassian.webdriver.testing.runner.ProductContextRunner}.
13   *
14   * @since 2.1
15   */
16  public final class DefaultProductContextRules
17  {
18      private DefaultProductContextRules()
19      {
20          throw new AssertionError("Don't instantiate me");
21      }
22  
23      public final static class ForClass implements TestRule
24       {
25           private final RuleChain chain;
26  
27           @Inject
28           public ForClass(DriverCleanupRule driverCleanupRule)
29           {
30               this.chain = RuleChain.outerRule(driverCleanupRule);
31           }
32  
33           @Override
34           public Statement apply(Statement base, Description description)
35           {
36               return chain.apply(base, description);
37           }
38       }
39  
40      public final static class ForMethod implements TestRule
41      {
42          private final RuleChain chain;
43  
44          @Inject
45          public ForMethod(IgnoreBrowserRule ignoreBrowserRule,
46                           JavaScriptErrorsRule javaScriptErrorsRule,
47                           LogPageSourceRule logPageSourceRule,
48                           SessionCleanupRule sessionCleanupRule,
49                           WebDriverScreenshotRule webDriverScreenshotRule,
50                           WindowSizeRule windowSizeRule)
51          {
52              this.chain = RuleChain.outerRule(ignoreBrowserRule)
53                      .around(sessionCleanupRule)
54                      .around(windowSizeRule)
55                      .around(javaScriptErrorsRule)
56                      .around(webDriverScreenshotRule)
57                      .around(logPageSourceRule);
58          }
59  
60          @Override
61          public Statement apply(Statement base, Description description)
62          {
63              return chain.apply(base, description);
64          }
65      }
66  
67  }