Class BrowserActions
java.lang.Object
com.shaft.driver.internal.FluentWebDriverAction
com.shaft.gui.browser.BrowserActions
Provides a fluent API for performing browser-level actions such as navigation, window management,
cookie handling, network interception, and accessibility validation. Instances are typically
obtained via
driver.browser() on a SHAFT.GUI.WebDriver instance.
Example usage:
SHAFT.GUI.WebDriver driver = new SHAFT.GUI.WebDriver();
driver.browser()
.navigateToURL("https://example.com")
.and().maximizeWindow();
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a newBrowserActionsinstance and initializes the underlying driver using the framework's default driver factory configuration.BrowserActions(DriverFactoryHelper helper) Creates a newBrowserActionsinstance backed by an existingDriverFactoryHelper.BrowserActions(org.openqa.selenium.WebDriver driver) Creates a newBrowserActionsinstance wrapping the providedWebDriver.BrowserActions(org.openqa.selenium.WebDriver driver, boolean isSilent) Creates a newBrowserActionsinstance wrapping the providedWebDriver, with control over whether reporting output is suppressed. -
Method Summary
Modifier and TypeMethodDescriptionProvides access to accessibility testing actions for the current browser session.Adds a cookie to the current browsing context.and()Returns this instance to allow fluent (method-chaining) syntax between successive actions.Opens a hard-assertion builder scoped to the current browser state.Attempts to capture a page snapshot archive in the format of a .mht file Works only for Chromium based driver instances For other driver types attempts to attach the current page source (for web) or accessibility tree (for mobile)Use this action to return a full page screenshot.captureScreenshot(Screenshots type) Use this action to return a page screenshot.Use this action to return a page snapshot.voidCloses the current browser windowDeletes all the cookies of the current browsing context.deleteCookie(String cookieName) Deletes the cookie data matching with the provided cookie name for the current browsing context.Resize the window to fill the current screenvoidGenerates a Google Lighthouse performance report for the currently open page.Set<org.openqa.selenium.Cookie> Gets all cookies for the current browsing context.Returns the handle for currently active context.Returns a list of unique handles for all the currently open contexts.org.openqa.selenium.CookieGets a cookie with a given name.getCookieDomain(String cookieName) Gets the cookie domain.getCookiePath(String cookieName) Gets the cookie path.getCookieValue(String cookieName) Gets the cookie value.Gets the current page URL and returns it as a stringGets the current window title and returns it as a stringGets the current page source and returns it as a stringGets the current window handle and returns it as a stringReturns a list of unique handles for all the currently open windows.Gets the current window size and returns it as a stringGets the current window position and returns it as a stringGets the current window size and returns it as a stringGets the current window size and returns it as a stringintercept(Predicate<org.openqa.selenium.remote.http.HttpRequest> requestPredicate, org.openqa.selenium.remote.http.HttpResponse mockedResponse) Intercepts outgoing HTTP requests matching the given predicate and substitutes the real network response with the providedHttpResponse.Maximizes current window size based on screen size minus 5%mock(Predicate<org.openqa.selenium.remote.http.HttpRequest> requestPredicate, org.openqa.selenium.remote.http.HttpResponse mockedResponse) Intercepts outgoing HTTP requests matching the given predicate and replaces the actual network response with the providedHttpResponse.Navigates one step back from the browsers historyNavigates one step forward from the browsers historynavigateToURL(String targetUrl) Navigates to targetUrl in case the current URL is different, else refreshes the current pagenavigateToURL(String targetUrl, String targetUrlAfterRedirection) Navigates to targetUrl in case the current URL is different, else refreshes the current page.navigateToURL(String targetUrl, org.openqa.selenium.WindowType windowType) Navigates to the specified URL by opening it in a new browser tab or a new browser window, depending on the providedWindowType.navigateToURLWithBasicAuthentication(String targetUrl, String username, String password, String targetUrlAfterAuthentication) Navigates to targetUrl using basic authentication in case the current URL is different, else refreshes the current page.Attempts to refresh the current pagesetContext(String context) Switches focus to another contextsetWindowSize(int width, int height) Resizes the current window size based on the provided width and heightswitchToWindow(String nameOrHandle) Switches focus to another windowOpens a soft-assertion (verification) builder scoped to the current browser state.Waits for the page to finish lazy-loading by polling JavaScript readiness conditions.waitUntilNumberOfWindowsToBe(int expectedNumberOfWindows) Deprecated, for removal: This API element is subject to removal in a future version.waitUntilTitleContains(String title) Deprecated, for removal: This API element is subject to removal in a future version.waitUntilTitleIs(String title) Deprecated, for removal: This API element is subject to removal in a future version.waitUntilTitleNotContains(String title) Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, for removal: This API element is subject to removal in a future version.waitUntilUrlMatches(String urlRegex) Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, for removal: This API element is subject to removal in a future version.waitUntilUrlToBe(String url) Deprecated, for removal: This API element is subject to removal in a future version.Methods inherited from class FluentWebDriverAction
alert, browser, element, initialize, initialize, initialize, initialize, performAlertAction, performBrowserAction, performElementAction, performTouchAction, touch
-
Constructor Details
-
BrowserActions
public BrowserActions()Creates a newBrowserActionsinstance and initializes the underlying driver using the framework's default driver factory configuration. -
BrowserActions
public BrowserActions(org.openqa.selenium.WebDriver driver) Creates a newBrowserActionsinstance wrapping the providedWebDriver.- Parameters:
driver- theWebDriverinstance to use for browser actions
-
BrowserActions
public BrowserActions(org.openqa.selenium.WebDriver driver, boolean isSilent) Creates a newBrowserActionsinstance wrapping the providedWebDriver, with control over whether reporting output is suppressed.- Parameters:
driver- theWebDriverinstance to use for browser actionsisSilent- whentrue, step reporting is suppressed for this instance
-
BrowserActions
Creates a newBrowserActionsinstance backed by an existingDriverFactoryHelper. Use this constructor when integrating with the internal driver lifecycle management.- Parameters:
helper- theDriverFactoryHelperthat manages the underlying driver instance
-
-
Method Details
-
and
Description copied from class:FluentWebDriverActionReturns this instance to allow fluent (method-chaining) syntax between successive actions. Using.and()improves readability by making multi-step test sequences read like natural language.Example:
driver.element().type(searchBox, "query") .and().browser().captureScreenshot();- Overrides:
andin classFluentWebDriverAction- Returns:
- this
FluentWebDriverActioninstance, enabling continued method chaining
-
assertThat
Opens a hard-assertion builder scoped to the current browser state. Any assertion failure immediately stops the test.Example:
driver.browser().assertThat().title().contains("Dashboard");- Returns:
- a
WebDriverBrowserValidationsBuilderfor chaining browser assertions
-
verifyThat
Opens a soft-assertion (verification) builder scoped to the current browser state. Failures are collected and reported at the end of the test rather than stopping it immediately.Example:
driver.browser().verifyThat().title().contains("Dashboard");- Returns:
- a
WebDriverBrowserValidationsBuilderfor chaining browser verifications
-
capturePageSnapshot
Attempts to capture a page snapshot archive in the format of a .mht file Works only for Chromium based driver instances For other driver types attempts to attach the current page source (for web) or accessibility tree (for mobile)- Returns:
- a self-reference to be used to chain actions
-
getCurrentURL
Gets the current page URL and returns it as a string- Returns:
- the URL that's currently open in the current page
-
getCurrentWindowTitle
Gets the current window title and returns it as a string- Returns:
- the title of the current window
-
getPageSource
Gets the current page source and returns it as a string- Returns:
- the source of the current page
-
getWindowHandle
Gets the current window handle and returns it as a string- Returns:
- the window handle for the current window
-
getWindowPosition
Gets the current window position and returns it as a string- Returns:
- the position of the current window
-
getWindowSize
Gets the current window size and returns it as a string- Returns:
- the size of the current window
-
getWindowHeight
Gets the current window size and returns it as a string- Returns:
- the height of the current window
-
getWindowWidth
Gets the current window size and returns it as a string- Returns:
- the width of the current window
-
refreshCurrentPage
Attempts to refresh the current page- Returns:
- a self-reference to be used to chain actions
-
closeCurrentWindow
public void closeCurrentWindow()Closes the current browser window -
maximizeWindow
Maximizes current window size based on screen size minus 5%- Returns:
- a self-reference to be used to chain actions
-
setWindowSize
Resizes the current window size based on the provided width and height- Parameters:
width- the desired new width of the target windowheight- the desired new height of the target window- Returns:
- a self-reference to be used to chain actions
-
mock
@Step("Mock HTTP Request") public BrowserActions mock(Predicate<org.openqa.selenium.remote.http.HttpRequest> requestPredicate, org.openqa.selenium.remote.http.HttpResponse mockedResponse) Intercepts outgoing HTTP requests matching the given predicate and replaces the actual network response with the providedHttpResponse. Only supported for drivers that implementHasDevTools.Example:
HttpResponse mocked = new HttpResponse(); mocked.setStatus(200); driver.browser().mock(req -> req.getUri().contains("/api/user"), mocked);- Parameters:
requestPredicate- aPredicatethat identifies which requests should be interceptedmockedResponse- theHttpResponseto return instead of the real network response- Returns:
- a self-reference to be used to chain actions
-
intercept
@Step("Intercept HTTP Request") public BrowserActions intercept(Predicate<org.openqa.selenium.remote.http.HttpRequest> requestPredicate, org.openqa.selenium.remote.http.HttpResponse mockedResponse) Intercepts outgoing HTTP requests matching the given predicate and substitutes the real network response with the providedHttpResponse. Functionally equivalent tomock(Predicate, HttpResponse)but semantically named for interception use-cases. Only supported for drivers that implementHasDevTools.Example:
HttpResponse stubbed = new HttpResponse(); stubbed.setStatus(503); driver.browser().intercept(req -> req.getUri().contains("/api/search"), stubbed);- Parameters:
requestPredicate- aPredicatethat identifies which requests should be interceptedmockedResponse- theHttpResponseto return instead of the real network response- Returns:
- a self-reference to be used to chain actions
-
fullScreenWindow
Resize the window to fill the current screen- Returns:
- a self-reference to be used to chain actions
-
switchToWindow
Switches focus to another window- Parameters:
nameOrHandle- The name of the window or the handle as returned by ElementActions.getWindowHandle(WebDriver driver)- Returns:
- a self-reference to be used to chain actions
-
addCookie
Adds a cookie to the current browsing context.- Parameters:
key- The cookie's namevalue- The cookie's name- Returns:
- a self-reference to be used to chain actions
-
getCookie
Gets a cookie with a given name.- Parameters:
cookieName- The cookie's name.- Returns:
- the cookie.
-
getAllCookies
Gets all cookies for the current browsing context.- Returns:
- A Set of cookies for the current browsing context.
-
getCookieDomain
-
getCookieValue
-
getCookiePath
-
deleteCookie
Deletes the cookie data matching with the provided cookie name for the current browsing context.- Parameters:
cookieName- The name of the cookie to delete.- Returns:
- a self-reference to be used to chain actions.
-
deleteAllCookies
Deletes all the cookies of the current browsing context.- Returns:
- a self-reference to be used to chain actions.
-
captureScreenshot
Use this action to return a full page screenshot. This is a synonym tocaptureScreenshot(Screenshots type)if you pass `Screenshots.FULL`- Returns:
- a self-reference for chainable actions
-
captureScreenshot
Use this action to return a page screenshot. If you want to capture a screenshot then use this method instead- Parameters:
type- can either be `Screenshots.FULL`, or `Screenshots.VIEWPORT`- Returns:
- a self-reference for chainable actions
-
captureSnapshot
Use this action to return a page snapshot. A page snapshot is a single .mht file that contains the full page DOM and any related assets to help you view the page as a whole. If you want to capture a screenshot then use this method instead @see FluentBrowserActions#captureScreenshot()- Returns:
- a self-reference for chainable actions
-
generateLightHouseReport
public void generateLightHouseReport()Generates a Google Lighthouse performance report for the currently open page. The report is attached to the Allure test report for review after the test run.Example:
driver.browser().navigateToURL("https://example.com") .and().generateLightHouseReport(); -
waitForLazyLoading
Waits for the page to finish lazy-loading by polling JavaScript readiness conditions. Use this after actions that trigger dynamic content loading (e.g., infinite scrolling or deferred script execution).Example:
driver.browser().navigateToURL("https://example.com") .and().waitForLazyLoading();- Returns:
- a self-reference to be used to chain actions
-
waitUntilTitleIs
Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, instead you should useActions.waitUntil(Function, Duration)orActions.waitUntil(Function)Use this action to wait until the page title is exactly as provided
- Parameters:
title- the expected title- Returns:
- a self-reference for chainable actions
-
waitUntilTitleContains
Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, instead you should useActions.waitUntil(Function, Duration)orActions.waitUntil(Function)Use this action to wait until the page title contains the provided text
- Parameters:
title- the expected title- Returns:
- a self-reference for chainable actions
-
waitUntilTitleNotContains
Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, instead you should useActions.waitUntil(Function, Duration)orActions.waitUntil(Function)Use this action to wait until the page title does not contain the provided text
- Parameters:
title- the expected title- Returns:
- a self-reference for chainable actions
-
waitUntilUrlContains
Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, instead you should useActions.waitUntil(Function, Duration)orActions.waitUntil(Function)Use this action to wait until the current URL contains the provided text- Parameters:
url- the expected URL- Returns:
- a self-reference for chainable actions
-
waitUntilUrlNotContains
Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, instead you should useActions.waitUntil(Function, Duration)orActions.waitUntil(Function)Use this action to wait until the current URL does not contain the provided text- Parameters:
url- the expected URL- Returns:
- a self-reference for chainable actions
-
waitUntilUrlToBe
Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, instead you should useActions.waitUntil(Function, Duration)orActions.waitUntil(Function)Use this action to wait until the current URL is exactly as provided- Parameters:
url- the expected URL- Returns:
- a self-reference for chainable actions
-
waitUntilUrlNotToBe
Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, instead you should useActions.waitUntil(Function, Duration)orActions.waitUntil(Function)Use this action to wait until the current URL is not the provided text- Parameters:
url- the expected URL- Returns:
- a self-reference for chainable actions
-
waitUntilUrlMatches
Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, instead you should useActions.waitUntil(Function, Duration)orActions.waitUntil(Function)Use this action to wait until the current URL matches the provided regex- Parameters:
urlRegex- the expected URL regex- Returns:
- a self-reference for chainable actions
-
waitUntilNumberOfWindowsToBe
@Deprecated(forRemoval=true) public BrowserActions waitUntilNumberOfWindowsToBe(int expectedNumberOfWindows) Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, instead you should useActions.waitUntil(Function, Duration)orActions.waitUntil(Function)Use this action to wait until the number of currently open windows matches the expected number- Parameters:
expectedNumberOfWindows- the expected number of open windows- Returns:
- a self-reference for chainable actions
-
getContext
Returns the handle for currently active context. This can be used to switch to this context at a later time.- Returns:
- The current context handle
-
setContext
Switches focus to another context- Parameters:
context- The name of the context or the handle as returned by ElementActions.getContext(WebDriver driver)- Returns:
- a self-reference to be used to chain actions
-
getWindowHandles
-
getContextHandles
-
accessibility
Provides access to accessibility testing actions for the current browser session.This method returns an
AccessibilityActionsinstance that can be used to perform automated accessibility checks and generate reports for the current page.Example usage:
AccessibilityActions actions = browserActions.accessibility(); actions.analyzePageAccessibility("HomePage");- Returns:
- an
AccessibilityActionsobject tied to the current browser session
-