|
1 | 1 | package com.frameworkium.config; |
2 | 2 |
|
3 | | -import org.openqa.selenium.WebDriver; |
4 | | -import org.openqa.selenium.remote.DesiredCapabilities; |
| 3 | +import com.frameworkium.config.browsers.*; |
| 4 | +import com.frameworkium.config.remotes.BrowserStack; |
| 5 | +import com.frameworkium.config.remotes.Sauce; |
| 6 | +import org.apache.logging.log4j.LogManager; |
| 7 | +import org.apache.logging.log4j.Logger; |
5 | 8 |
|
6 | | -public interface DriverSetup { |
| 9 | +import static com.frameworkium.config.SystemProperty.*; |
7 | 10 |
|
8 | | - WebDriver getWebDriverObject(DesiredCapabilities desiredCapabilities); |
| 11 | +public class DriverSetup { |
9 | 12 |
|
10 | | - DesiredCapabilities getDesiredCapabilities(); |
| 13 | + private static final SupportedBrowsers DEFAULT_BROWSER = SupportedBrowsers.FIREFOX; |
| 14 | + |
| 15 | + /** |
| 16 | + * List of supported browsers |
| 17 | + */ |
| 18 | + private static enum SupportedBrowsers { |
| 19 | + FIREFOX,CHROME,OPERA,IE,PHANTOMJS,SAFARI |
| 20 | + } |
| 21 | + |
| 22 | + /** |
| 23 | + * List of supported remote grids |
| 24 | + */ |
| 25 | + private static enum SupportedRemotes { |
| 26 | + SAUCE,BROWSERSTACK,GRID |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * List of supported platforms on remote grids |
| 31 | + */ |
| 32 | + public static enum SupportedPlatforms { |
| 33 | + IOS,ANDROID,BROWSER |
| 34 | + } |
| 35 | + |
| 36 | + protected final static Logger logger = LogManager.getLogger(DriverType.class); |
| 37 | + |
| 38 | + /** |
| 39 | + * Returns the driver type to the base test, which initialises it |
| 40 | + * |
| 41 | + * @return - Driver Type |
| 42 | + */ |
| 43 | + public static DriverType returnDesiredDriverType() { |
| 44 | + return initialiseDesiredDriverType(); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * Uses the paramaters given to determine which browser/remote/platform to use |
| 49 | + * |
| 50 | + * @return - The correct driver type based on parameters |
| 51 | + */ |
| 52 | + private static DriverType initialiseDesiredDriverType() { |
| 53 | + if (useRemoteDriver()) { |
| 54 | + SupportedPlatforms platform = returnPlatformType(); |
| 55 | + switch(returnRemoteType()) { |
| 56 | + case SAUCE: |
| 57 | + return new SauceImpl(platform); |
| 58 | + case BROWSERSTACK: |
| 59 | + return new BrowserStackImpl(platform); |
| 60 | + case GRID: |
| 61 | + return new GridImpl(); |
| 62 | + } |
| 63 | + } |
| 64 | + else { |
| 65 | + switch (returnBrowserType()) { |
| 66 | + case FIREFOX: |
| 67 | + return new FirefoxImpl(); |
| 68 | + case CHROME: |
| 69 | + return new ChromeImpl(); |
| 70 | + case OPERA: |
| 71 | + return new OperaImpl(); |
| 72 | + case IE: |
| 73 | + return new InternetExporerImpl(); |
| 74 | + case PHANTOMJS: |
| 75 | + return new PhantomJSImpl(); |
| 76 | + case SAFARI: |
| 77 | + return new SafariImpl(); |
| 78 | + } |
| 79 | + } |
| 80 | + return null; |
| 81 | + } |
| 82 | + |
| 83 | + /** |
| 84 | + * Checks whether a remote driver is wanting to be used |
| 85 | + * |
| 86 | + * @return - True/False to whether to use a remote driver |
| 87 | + */ |
| 88 | + public static boolean useRemoteDriver() { |
| 89 | + return GRID_URL.isSpecified() || Sauce.isDesired() || BrowserStack.isDesired(); |
| 90 | + } |
| 91 | + |
| 92 | + /** |
| 93 | + * Returns the platform type, if it's been given |
| 94 | + * |
| 95 | + * @return - Platform type |
| 96 | + */ |
| 97 | + private static SupportedPlatforms returnPlatformType() { |
| 98 | + return SupportedPlatforms.valueOf(SystemProperty.PLATFORM.getValue().toUpperCase()); |
| 99 | + } |
| 100 | + |
| 101 | + /** |
| 102 | + * Returns the browser type and returns default if not specified |
| 103 | + * |
| 104 | + * @return - Browser Type |
| 105 | + */ |
| 106 | + private static SupportedBrowsers returnBrowserType() { |
| 107 | + if (!SystemProperty.BROWSER.isSpecified()) { |
| 108 | + return DEFAULT_BROWSER; |
| 109 | + } |
| 110 | + else { |
| 111 | + return SupportedBrowsers.valueOf(SystemProperty.BROWSER.getValue().toUpperCase()); |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + /** |
| 116 | + * Returns what type of remote driver has been specified to be used |
| 117 | + * |
| 118 | + * @return - Remote Driver Type |
| 119 | + */ |
| 120 | + private static SupportedRemotes returnRemoteType() { |
| 121 | + if (Sauce.isDesired()) { |
| 122 | + return SupportedRemotes.SAUCE; |
| 123 | + } |
| 124 | + else if (BrowserStack.isDesired()) { |
| 125 | + return SupportedRemotes.BROWSERSTACK; |
| 126 | + } |
| 127 | + else { |
| 128 | + return SupportedRemotes.GRID; |
| 129 | + } |
| 130 | + } |
11 | 131 | } |
0 commit comments