1 package com.atlassian.webdriver.testing.rule;
2
3 import com.atlassian.webdriver.AtlassianWebDriver;
4 import com.atlassian.webdriver.browsers.WebDriverBrowserAutoInstall;
5 import com.google.common.base.Supplier;
6 import com.google.common.base.Suppliers;
7 import org.openqa.selenium.WebDriver;
8
9 import javax.annotation.Nonnull;
10
11 import static com.google.common.base.Preconditions.checkNotNull;
12
13
14
15
16
17
18
19
20
21
22
23 public final class WebDriverSupport<WD extends WebDriver>
24 {
25 public static WebDriverSupport<AtlassianWebDriver> fromAutoInstall()
26 {
27 return new WebDriverSupport<AtlassianWebDriver>(WebDriverBrowserAutoInstall.driverSupplier());
28 }
29
30 public static <VE extends WebDriver> WebDriverSupport<VE> forSupplier(Supplier<? extends VE> driverSupplier)
31 {
32 return new WebDriverSupport<VE>(driverSupplier);
33 }
34
35 public static <VE extends WebDriver> WebDriverSupport<VE> forInstance(VE webDriver)
36 {
37 return new WebDriverSupport<VE>(Suppliers.ofInstance(checkNotNull(webDriver, "webDriver")));
38 }
39
40 private final Supplier<? extends WD> driverSupplier;
41
42 private WebDriverSupport(@Nonnull Supplier<? extends WD> driverSupplier)
43 {
44 this.driverSupplier = Suppliers.memoize(checkNotNull(driverSupplier, "driverSupplier"));
45 }
46
47 @Nonnull
48 public final WD getDriver()
49 {
50 return driverSupplier.get();
51 }
52
53 }