Class DriverFactoryHelper

java.lang.Object
com.shaft.driver.internal.DriverFactory.DriverFactoryHelper

public class DriverFactoryHelper extends Object
Internal helper responsible for initializing, managing, and closing WebDriver sessions.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a helper instance without an attached WebDriver.
    DriverFactoryHelper(org.openqa.selenium.WebDriver driver)
    Creates a helper instance attached to an existing WebDriver session.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes the currently attached driver session and clears the local driver reference.
    void
    closeDriver(org.openqa.selenium.WebDriver driver)
    Closes the given WebDriver session and performs all associated teardown tasks: attaches video recording (if scope is DriverSession), collects WebDriver logs, handles dockerized driver cleanup, and removes the WebDriverManager reference.
    void
    Initializes a driver using the currently configured target browser/mobile settings.
    void
    Initializes a driver using the supplied driver type and default options.
    void
    initializeDriver(@NonNull DriverFactory.DriverType driverType, org.openqa.selenium.MutableCapabilities customDriverOptions)
    Initializes a driver using an explicit driver type and optional custom capabilities.
    void
    initializeDriver(@NonNull org.openqa.selenium.WebDriver driver)
    Attaches the helper to an already initialized native WebDriver session.
    void
    initializeDriver(org.openqa.selenium.MutableCapabilities customDriverOptions)
    Initializes a driver using configured browser name and custom capabilities.
    static void
    Initializes and normalizes system-level execution properties before driver creation.
    static boolean
    Checks to see if the execution is a mobile-native execution
    static boolean
    Checks to see if the execution is a mobile-web execution
    static boolean
    Checks to see if the execution is a web-based execution

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DriverFactoryHelper

      public DriverFactoryHelper()
      Creates a helper instance without an attached WebDriver.
    • DriverFactoryHelper

      public DriverFactoryHelper(org.openqa.selenium.WebDriver driver)
      Creates a helper instance attached to an existing WebDriver session.
      Parameters:
      driver - the active WebDriver session
  • Method Details

    • isMobileNativeExecution

      public static boolean isMobileNativeExecution()
      Checks to see if the execution is a mobile-native execution
      Returns:
      true if it's a mobile mobile-native execution
    • isMobileWebExecution

      public static boolean isMobileWebExecution()
      Checks to see if the execution is a mobile-web execution
      Returns:
      true if it's a mobile mobile-web execution
    • isNotMobileExecution

      public static boolean isNotMobileExecution()
      Checks to see if the execution is a web-based execution
      Returns:
      true if it's a web-based execution
    • initializeSystemProperties

      public static void initializeSystemProperties()
      Initializes and normalizes system-level execution properties before driver creation.
    • closeDriver

      public void closeDriver()
      Closes the currently attached driver session and clears the local driver reference.
    • closeDriver

      @Step("Close Driver Session") public void closeDriver(org.openqa.selenium.WebDriver driver)
      Closes the given WebDriver session and performs all associated teardown tasks: attaches video recording (if scope is DriverSession), collects WebDriver logs, handles dockerized driver cleanup, and removes the WebDriverManager reference.

      The method handles the following edge cases gracefully:

      • Driver already closed — logs at DEBUG level and continues
      • null driver — logs an informational message and returns
      • Exceptions during close() or quit() — caught and logged so the remaining teardown (log attachment, state cleanup) still executes
      Parameters:
      driver - the WebDriver instance to close; if null, the method is a no-op
    • initializeDriver

      public void initializeDriver()
      Initializes a driver using the currently configured target browser/mobile settings.
    • initializeDriver

      public void initializeDriver(@NonNull @NonNull DriverFactory.DriverType driverType)
      Initializes a driver using the supplied driver type and default options.
      Parameters:
      driverType - the desired driver type
    • initializeDriver

      public void initializeDriver(org.openqa.selenium.MutableCapabilities customDriverOptions)
      Initializes a driver using configured browser name and custom capabilities.
      Parameters:
      customDriverOptions - custom capabilities to merge into default options
    • initializeDriver

      public void initializeDriver(@NonNull @NonNull DriverFactory.DriverType driverType, org.openqa.selenium.MutableCapabilities customDriverOptions)
      Initializes a driver using an explicit driver type and optional custom capabilities.
      Parameters:
      driverType - the desired driver type
      customDriverOptions - custom capabilities to merge into default options
    • initializeDriver

      public void initializeDriver(@NonNull @NonNull org.openqa.selenium.WebDriver driver)
      Attaches the helper to an already initialized native WebDriver session.
      Parameters:
      driver - existing WebDriver instance