Class BrowserActions


public class BrowserActions extends FluentWebDriverAction
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 Details

    • BrowserActions

      public BrowserActions()
      Creates a new BrowserActions instance and initializes the underlying driver using the framework's default driver factory configuration.
    • BrowserActions

      public BrowserActions(org.openqa.selenium.WebDriver driver)
      Creates a new BrowserActions instance wrapping the provided WebDriver.
      Parameters:
      driver - the WebDriver instance to use for browser actions
    • BrowserActions

      public BrowserActions(org.openqa.selenium.WebDriver driver, boolean isSilent)
      Creates a new BrowserActions instance wrapping the provided WebDriver, with control over whether reporting output is suppressed.
      Parameters:
      driver - the WebDriver instance to use for browser actions
      isSilent - when true, step reporting is suppressed for this instance
    • BrowserActions

      public BrowserActions(DriverFactoryHelper helper)
      Creates a new BrowserActions instance backed by an existing DriverFactoryHelper. Use this constructor when integrating with the internal driver lifecycle management.
      Parameters:
      helper - the DriverFactoryHelper that manages the underlying driver instance
  • Method Details

    • and

      public BrowserActions and()
      Description copied from class: FluentWebDriverAction
      Returns 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:
      and in class FluentWebDriverAction
      Returns:
      this FluentWebDriverAction instance, 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 WebDriverBrowserValidationsBuilder for 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 WebDriverBrowserValidationsBuilder for chaining browser verifications
    • capturePageSnapshot

      public BrowserActions 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

      public String getCurrentURL()
      Gets the current page URL and returns it as a string
      Returns:
      the URL that's currently open in the current page
    • getCurrentWindowTitle

      public String getCurrentWindowTitle()
      Gets the current window title and returns it as a string
      Returns:
      the title of the current window
    • getPageSource

      public String getPageSource()
      Gets the current page source and returns it as a string
      Returns:
      the source of the current page
    • getWindowHandle

      public String getWindowHandle()
      Gets the current window handle and returns it as a string
      Returns:
      the window handle for the current window
    • getWindowPosition

      public String getWindowPosition()
      Gets the current window position and returns it as a string
      Returns:
      the position of the current window
    • getWindowSize

      public String getWindowSize()
      Gets the current window size and returns it as a string
      Returns:
      the size of the current window
    • getWindowHeight

      public String getWindowHeight()
      Gets the current window size and returns it as a string
      Returns:
      the height of the current window
    • getWindowWidth

      public String getWindowWidth()
      Gets the current window size and returns it as a string
      Returns:
      the width of the current window
    • refreshCurrentPage

      public BrowserActions 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

      public BrowserActions maximizeWindow()
      Maximizes current window size based on screen size minus 5%
      Returns:
      a self-reference to be used to chain actions
    • setWindowSize

      public BrowserActions setWindowSize(int width, int height)
      Resizes the current window size based on the provided width and height
      Parameters:
      width - the desired new width of the target window
      height - 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 provided HttpResponse. Only supported for drivers that implement HasDevTools.

      Example:

      HttpResponse mocked = new HttpResponse();
      mocked.setStatus(200);
      driver.browser().mock(req -> req.getUri().contains("/api/user"), mocked);
      
      Parameters:
      requestPredicate - a Predicate that identifies which requests should be intercepted
      mockedResponse - the HttpResponse to 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 provided HttpResponse. Functionally equivalent to mock(Predicate, HttpResponse) but semantically named for interception use-cases. Only supported for drivers that implement HasDevTools.

      Example:

      HttpResponse stubbed = new HttpResponse();
      stubbed.setStatus(503);
      driver.browser().intercept(req -> req.getUri().contains("/api/search"), stubbed);
      
      Parameters:
      requestPredicate - a Predicate that identifies which requests should be intercepted
      mockedResponse - the HttpResponse to return instead of the real network response
      Returns:
      a self-reference to be used to chain actions
    • fullScreenWindow

      public BrowserActions fullScreenWindow()
      Resize the window to fill the current screen
      Returns:
      a self-reference to be used to chain actions
    • switchToWindow

      public BrowserActions switchToWindow(String nameOrHandle)
      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

      public BrowserActions addCookie(String key, String value)
      Adds a cookie to the current browsing context.
      Parameters:
      key - The cookie's name
      value - The cookie's name
      Returns:
      a self-reference to be used to chain actions
    • getCookie

      public org.openqa.selenium.Cookie getCookie(String cookieName)
      Gets a cookie with a given name.
      Parameters:
      cookieName - The cookie's name.
      Returns:
      the cookie.
    • getAllCookies

      public Set<org.openqa.selenium.Cookie> getAllCookies()
      Gets all cookies for the current browsing context.
      Returns:
      A Set of cookies for the current browsing context.
    • getCookieDomain

      public String getCookieDomain(String cookieName)
      Gets the cookie domain.
      Parameters:
      cookieName - The cookie's name.
      Returns:
      te cookie domain;
    • getCookieValue

      public String getCookieValue(String cookieName)
      Gets the cookie value.
      Parameters:
      cookieName - The cookie's name.
      Returns:
      the cookie value;
    • getCookiePath

      public String getCookiePath(String cookieName)
      Gets the cookie path.
      Parameters:
      cookieName - The cookie's name.
      Returns:
      the cookie path;
    • deleteCookie

      public BrowserActions deleteCookie(String cookieName)
      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

      public BrowserActions deleteAllCookies()
      Deletes all the cookies of the current browsing context.
      Returns:
      a self-reference to be used to chain actions.
    • captureScreenshot

      public BrowserActions captureScreenshot()
      Use this action to return a full page screenshot. This is a synonym to captureScreenshot(Screenshots type) if you pass `Screenshots.FULL`
      Returns:
      a self-reference for chainable actions
    • captureScreenshot

      public BrowserActions captureScreenshot(Screenshots type)
      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

      public BrowserActions 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

      public BrowserActions 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(forRemoval=true) public BrowserActions waitUntilTitleIs(String title)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Deprecated, instead you should use Actions.waitUntil(Function, Duration) or Actions.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(forRemoval=true) public BrowserActions waitUntilTitleContains(String title)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Deprecated, instead you should use Actions.waitUntil(Function, Duration) or Actions.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(forRemoval=true) public BrowserActions waitUntilTitleNotContains(String title)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Deprecated, instead you should use Actions.waitUntil(Function, Duration) or Actions.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(forRemoval=true) public BrowserActions waitUntilUrlContains(String url)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Deprecated, instead you should use Actions.waitUntil(Function, Duration) or Actions.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(forRemoval=true) public BrowserActions waitUntilUrlNotContains(String url)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Deprecated, instead you should use Actions.waitUntil(Function, Duration) or Actions.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(forRemoval=true) public BrowserActions waitUntilUrlToBe(String url)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Deprecated, instead you should use Actions.waitUntil(Function, Duration) or Actions.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(forRemoval=true) public BrowserActions waitUntilUrlNotToBe(String url)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Deprecated, instead you should use Actions.waitUntil(Function, Duration) or Actions.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(forRemoval=true) public BrowserActions waitUntilUrlMatches(String urlRegex)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Deprecated, instead you should use Actions.waitUntil(Function, Duration) or Actions.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 use Actions.waitUntil(Function, Duration) or Actions.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

      public String 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

      public BrowserActions setContext(String context)
      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

      public List<String> getWindowHandles()
      Returns a list of unique handles for all the currently open windows. This can be used to switch to any of these windows at a later time.
      Returns:
      list of window handles
    • getContextHandles

      public List<String> getContextHandles()
      Returns a list of unique handles for all the currently open contexts. This can be used to switch to any of these contexts at a later time.
      Returns:
      list of context handles
    • accessibility

      public AccessibilityActions accessibility()
      Provides access to accessibility testing actions for the current browser session.

      This method returns an AccessibilityActions instance 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 AccessibilityActions object tied to the current browser session