16 | * It is also responsible for setting the driver variable to DriverManager which handles the thread safety for the webdriver instance.
17 | *
18 | * @author Administrator
19 | */
20 | @NoArgsConstructor(access = AccessLevel.PRIVATE)
21 | public final class Driver {
22 |
23 | public static void initDriver(BrowserType browser) {
24 | DriverData driverData = DriverData.builder()
25 | .browserType(browser)
26 | .browserRemoteModeType(ConfigFactory.getConfig().remote_mode())
27 | .build();
28 |
29 | if (Objects.isNull(DriverManager.getDriver())) {
30 | DriverManager.setDriver(DriverFactory
31 | .getDriver(ConfigFactory.getConfig().run_mode())
32 | .getDriver(driverData));
33 | }
34 | DriverManager.getDriver().get(ConfigFactory.getConfig().url());
35 | DriverManager.getDriver().manage().window().maximize();
36 | }
37 |
38 | public static void quitDriver() {
39 | if (Objects.nonNull(DriverManager.getDriver())) {
40 | DriverManager.getDriver().quit();
41 | DriverManager.unload();
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/com/automation/driver/abstraction/IDriver.java:
--------------------------------------------------------------------------------
1 | package com.automation.driver.abstraction;
2 |
3 | import com.automation.driver.entity.DriverData;
4 | import org.openqa.selenium.WebDriver;
5 |
6 | public interface IDriver {
7 |
8 | WebDriver getDriver(DriverData driverData);
9 | }
10 |
--------------------------------------------------------------------------------
/src/main/java/com/automation/driver/entity/DriverData.java:
--------------------------------------------------------------------------------
1 | package com.automation.driver.entity;
2 |
3 | import com.automation.enums.BrowserRemoteModeType;
4 | import com.automation.enums.BrowserType;
5 | import lombok.Builder;
6 | import lombok.Getter;
7 |
8 | /**
9 | * Builder pattern helps in creating immutable classes with a large set of state attributes
10 | *
11 | */
12 | @Builder
13 | @Getter
14 | public class DriverData {
15 |
16 | private BrowserType browserType;
17 | private BrowserRemoteModeType browserRemoteModeType;
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/com/automation/driver/factory/DriverFactory.java:
--------------------------------------------------------------------------------
1 | package com.automation.driver.factory;
2 |
3 | import com.automation.driver.abstraction.IDriver;
4 | import com.automation.driver.factory.local.LocalDriverImpl;
5 | import com.automation.driver.factory.remote.RemoteDriverImpl;
6 | import com.automation.enums.RunType;
7 | import lombok.AccessLevel;
8 | import lombok.NoArgsConstructor;
9 |
10 | import java.util.EnumMap;
11 | import java.util.Map;
12 | import java.util.function.Supplier;
13 |
14 | @NoArgsConstructor(access = AccessLevel.PRIVATE)
15 | public final class DriverFactory {
16 |
17 | private static final Map