Class DriverFactoryHelper
java.lang.Object
com.shaft.driver.internal.DriverFactory.DriverFactoryHelper
Internal helper responsible for initializing, managing, and closing WebDriver sessions.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates 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 TypeMethodDescriptionvoidClears browser network interception rules for the active WebDriver session.voidCloses the currently attached driver session and clears the local driver reference.voidcloseDriver(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.static org.openqa.selenium.WebDriverReturns the WebDriver currently owned by this thread, when SHAFT created or attached one.static booleanhasBlockingBrowserNetworkInterceptionRules(org.openqa.selenium.WebDriver driver) Reports whetherdriveralready has aBrowserNetworkInterceptorwith active mock/validate rules registered, meaning a caller must not install its own competing DevTools network filter on this driver: doing so would silently replace Selenium's single-slot network filter and break those rules with no warning.voidInitializes a driver using the currently configured target browser/mobile settings.voidinitializeDriver(@NonNull DriverFactory.DriverType driverType) Initializes a driver using the supplied driver type and default options.voidinitializeDriver(@NonNull DriverFactory.DriverType driverType, org.openqa.selenium.MutableCapabilities customDriverOptions) Initializes a driver using an explicit driver type and optional custom capabilities.voidinitializeDriver(@NonNull org.openqa.selenium.WebDriver driver) Attaches the helper to an already initialized native WebDriver session.voidinitializeDriver(org.openqa.selenium.MutableCapabilities customDriverOptions) Initializes a driver using configured browser name and custom capabilities.static voidInitializes and normalizes system-level execution properties before driver creation.static booleanChecks to see if the execution is a mobile-native executionstatic booleanChecks to see if the execution is a mobile-web executionstatic booleanChecks to see if the execution is a web-based executionstatic booleanChecks to see if the execution is a Windows desktop Appium execution.static voidPerforms configured Selenium Grid preflight during framework suite startup.voidRegisters a browser network interception rule for the active WebDriver session.static booleanreleaseBrowserNetworkObservationForHandoff(org.openqa.selenium.WebDriver driver) Hands off sole ownership ofdriver's DevTools network filter away from anyBrowserNetworkInterceptorthis helper started for trace/HAR observation, so a caller that is about to install its ownNetworkInterceptoron the same driver (for example a dedicated API-capture recorder) does not silently race with and replace it.voidsetDriver(org.openqa.selenium.WebDriver driver) Stores the helper driver and exposes it to thread-local lifecycle reporters.booleanStarts passive browser network observation for trace or contract capture.
-
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
-
getActiveDriver
public static org.openqa.selenium.WebDriver getActiveDriver()Returns the WebDriver currently owned by this thread, when SHAFT created or attached one.- Returns:
- the active WebDriver for the current thread, or
null
-
setDriver
public void setDriver(org.openqa.selenium.WebDriver driver) Stores the helper driver and exposes it to thread-local lifecycle reporters.- Parameters:
driver- the current WebDriver, ornullto clear the thread state
-
registerBrowserNetworkInterceptionRule
Registers a browser network interception rule for the active WebDriver session.- Parameters:
rule- the rule to activate
-
clearBrowserNetworkInterceptors
public void clearBrowserNetworkInterceptors()Clears browser network interception rules for the active WebDriver session. -
startBrowserNetworkObservation
public boolean startBrowserNetworkObservation()Starts passive browser network observation for trace or contract capture.- Returns:
truewhen observation started
-
releaseBrowserNetworkObservationForHandoff
public static boolean releaseBrowserNetworkObservationForHandoff(org.openqa.selenium.WebDriver driver) Hands off sole ownership ofdriver's DevTools network filter away from anyBrowserNetworkInterceptorthis helper started for trace/HAR observation, so a caller that is about to install its ownNetworkInterceptoron the same driver (for example a dedicated API-capture recorder) does not silently race with and replace it.Selenium's
NetworkInterceptorregistration is a single-slot replace, not a compose/stack: whichever interceptor registers last on a given driver silently wins, and the other's filter goes dead with no warning. Callers that are about to become the sole DevTools-network-filter owner fordrivershould call this first.Does nothing (and returns
false) when this helper's interceptor has active mock/validate rules registered: replacing that filter would silently drop the caller's expected mocking/validation behavior, so ownership is not released in that case and the caller must not double-register either.- Parameters:
driver- the WebDriver session the caller is about to attach its own network filter to- Returns:
truewhen passive trace/HAR observation was active and has been released so the caller is safe to become the sole interceptor owner;falsewhen there was nothing to hand off, or when active interception rules block a safe handoff
-
hasBlockingBrowserNetworkInterceptionRules
public static boolean hasBlockingBrowserNetworkInterceptionRules(org.openqa.selenium.WebDriver driver) Reports whetherdriveralready has aBrowserNetworkInterceptorwith active mock/validate rules registered, meaning a caller must not install its own competing DevTools network filter on this driver: doing so would silently replace Selenium's single-slot network filter and break those rules with no warning.- Parameters:
driver- the WebDriver session a caller is considering attaching its own network filter to- Returns:
truewhen this helper's interceptor fordriverhas active rules that block another owner from safely taking over the DevTools network filter
-
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
-
isWindowsAppiumExecution
public static boolean isWindowsAppiumExecution()Checks to see if the execution is a Windows desktop Appium execution.- Returns:
- true if it's a Windows desktop Appium execution
-
initializeSystemProperties
public static void initializeSystemProperties()Initializes and normalizes system-level execution properties before driver creation. -
preflightRemoteGridIfConfigured
public static void preflightRemoteGridIfConfigured()Performs configured Selenium Grid preflight during framework suite startup. -
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
nulldriver — logs an informational message and returns- Exceptions during
close()orquit()— caught and logged so the remaining teardown (log attachment, state cleanup) still executes
- Parameters:
driver- the WebDriver instance to close; ifnull, the method is a no-op
-
initializeDriver
public void initializeDriver()Initializes a driver using the currently configured target browser/mobile settings. -
initializeDriver
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 typecustomDriverOptions- 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
-