Class BrowserActions
java.lang.Object
com.shaft.gui.playwright.browser.BrowserActions
- All Implemented Interfaces:
BrowserActionsContract
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAccepts the current browser alert, confirm, or prompt dialog.and()assertContract(String contractFilePath, String... urlContains) Starts hard-assert validation of live Playwright responses against an HTTP contract.captureScreenshot(Screenshots type) voiddeleteCookie(String cookieName) Dismisses the current browser alert, confirm, or prompt dialog.voidGets the current browser alert, confirm, or prompt dialog text.Set<org.openqa.selenium.Cookie> org.openqa.selenium.CookiegetCookieDomain(String cookieName) getCookiePath(String cookieName) getCookieValue(String cookieName) com.microsoft.playwright.BrowserContextcom.microsoft.playwright.Pageintercept(Predicate<org.openqa.selenium.remote.http.HttpRequest> requestPredicate, org.openqa.selenium.remote.http.HttpResponse mockedResponse) booleanChecks whether a browser alert, confirm, or prompt dialog is currently present.loadStorageState(String filePath) Loads browser cookies,localStorage, andsessionStoragefrom a JSON file.com.microsoft.playwright.Locatormock(Predicate<org.openqa.selenium.remote.http.HttpRequest> requestPredicate, org.openqa.selenium.remote.http.HttpResponse mockedResponse) navigateToURL(String targetUrl) navigateToURL(String targetUrl, String targetUrlAfterRedirection) navigateToURL(String targetUrl, org.openqa.selenium.WindowType windowType) navigateToURLWithBasicAuthentication(String targetUrl, String username, String password, String targetUrlAfterAuthentication) openNewTab(String targetUrl) Opens the target URL in a new browser tab and switches focus to it.openNewWindow(String targetUrl) Opens the target URL in a new browser window and switches focus to it.registerNetworkInterceptionRule(BrowserNetworkInterceptionRule rule, String successMessage) replayContract(String contractFilePath) Replays recorded contract responses through the Playwright network interceptor.routeFromHar(String harFilePath) Replays recorded HAR (HTTP Archive) responses through the Playwright network interceptor.saveStorageState(String filePath) Saves the current browser cookies,localStorage, andsessionStorageto a JSON file.setContext(String context) setWindowSize(int width, int height) startContractRecording(String contractFilePath, String... urlContains) Starts recording selected Playwright browser traffic into an HTTP contract.switchToWindow(String nameOrHandle) typeIntoPromptAlert(String text) Types text into the current browser prompt dialog.verifyContract(String contractFilePath, String... urlContains) Starts soft-verify validation of live Playwright responses against an HTTP contract.Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface BrowserActionsContract
scrollToLoadAll
-
Constructor Details
-
BrowserActions
-
-
Method Details
-
and
- Specified by:
andin interfaceBrowserActionsContract
-
assertThat
- Specified by:
assertThatin interfaceBrowserActionsContract
-
verifyThat
- Specified by:
verifyThatin interfaceBrowserActionsContract
-
capturePageSnapshot
- Specified by:
capturePageSnapshotin interfaceBrowserActionsContract
-
getCurrentURL
- Specified by:
getCurrentURLin interfaceBrowserActionsContract
-
getCurrentWindowTitle
- Specified by:
getCurrentWindowTitlein interfaceBrowserActionsContract
-
getPageSource
- Specified by:
getPageSourcein interfaceBrowserActionsContract
-
getWindowHandle
- Specified by:
getWindowHandlein interfaceBrowserActionsContract
-
getWindowPosition
- Specified by:
getWindowPositionin interfaceBrowserActionsContract
-
getWindowSize
- Specified by:
getWindowSizein interfaceBrowserActionsContract
-
getWindowHeight
- Specified by:
getWindowHeightin interfaceBrowserActionsContract
-
getWindowWidth
- Specified by:
getWindowWidthin interfaceBrowserActionsContract
-
openNewTab
Opens the target URL in a new browser tab and switches focus to it.- Specified by:
openNewTabin interfaceBrowserActionsContract- Parameters:
targetUrl- target URL to open- Returns:
- a self-reference to be used to chain actions
-
openNewWindow
Opens the target URL in a new browser window and switches focus to it.- Specified by:
openNewWindowin interfaceBrowserActionsContract- Parameters:
targetUrl- target URL to open- Returns:
- a self-reference to be used to chain actions
-
refreshCurrentPage
- Specified by:
refreshCurrentPagein interfaceBrowserActionsContract
-
closeCurrentWindow
public void closeCurrentWindow()- Specified by:
closeCurrentWindowin interfaceBrowserActionsContract
-
maximizeWindow
- Specified by:
maximizeWindowin interfaceBrowserActionsContract
-
setWindowSize
- Specified by:
setWindowSizein interfaceBrowserActionsContract
-
mock
public BrowserActions mock(Predicate<org.openqa.selenium.remote.http.HttpRequest> requestPredicate, org.openqa.selenium.remote.http.HttpResponse mockedResponse) - Specified by:
mockin interfaceBrowserActionsContract
-
interceptRequest
- Specified by:
interceptRequestin interfaceBrowserActionsContract
-
startContractRecording
Starts recording selected Playwright browser traffic into an HTTP contract.- Specified by:
startContractRecordingin interfaceBrowserActionsContract- Parameters:
contractFilePath- destination JSON contract pathurlContains- optional URL fragments used to select recorded traffic- Returns:
- a self-reference to be used to chain actions
-
assertContract
Starts hard-assert validation of live Playwright responses against an HTTP contract.- Specified by:
assertContractin interfaceBrowserActionsContract- Parameters:
contractFilePath- source JSON contract pathurlContains- optional URL fragments used to select validated traffic- Returns:
- a self-reference to be used to chain actions
-
verifyContract
Starts soft-verify validation of live Playwright responses against an HTTP contract.- Specified by:
verifyContractin interfaceBrowserActionsContract- Parameters:
contractFilePath- source JSON contract pathurlContains- optional URL fragments used to select validated traffic- Returns:
- a self-reference to be used to chain actions
-
replayContract
Replays recorded contract responses through the Playwright network interceptor.Example:
driver.browser().replayContract("src/test/resources/contracts/checkout.json"); driver.browser().navigateToURL("https://shop.example/checkout");- Specified by:
replayContractin interfaceBrowserActionsContract- Parameters:
contractFilePath- source JSON contract path- Returns:
- a self-reference to be used to chain actions
-
routeFromHar
Replays recorded HAR (HTTP Archive) responses through the Playwright network interceptor.Example:
driver.browser().routeFromHar("src/test/resources/har/checkout.har"); driver.browser().navigateToURL("https://shop.example/checkout");- Specified by:
routeFromHarin interfaceBrowserActionsContract- Parameters:
harFilePath- path to a HAR 1.2 JSON file- Returns:
- a self-reference to be used to chain actions
-
intercept
public BrowserActions intercept(Predicate<org.openqa.selenium.remote.http.HttpRequest> requestPredicate, org.openqa.selenium.remote.http.HttpResponse mockedResponse) - Specified by:
interceptin interfaceBrowserActionsContract
-
clearNetworkInterceptors
- Specified by:
clearNetworkInterceptorsin interfaceBrowserActionsContract
-
fullScreenWindow
- Specified by:
fullScreenWindowin interfaceBrowserActionsContract
-
switchToWindow
- Specified by:
switchToWindowin interfaceBrowserActionsContract
-
isAlertPresent
public boolean isAlertPresent()Checks whether a browser alert, confirm, or prompt dialog is currently present.- Specified by:
isAlertPresentin interfaceBrowserActionsContract- Returns:
truewhen an alert is present; otherwisefalse
-
acceptAlert
Accepts the current browser alert, confirm, or prompt dialog.- Specified by:
acceptAlertin interfaceBrowserActionsContract- Returns:
- a self-reference to be used to chain actions
-
dismissAlert
Dismisses the current browser alert, confirm, or prompt dialog.- Specified by:
dismissAlertin interfaceBrowserActionsContract- Returns:
- a self-reference to be used to chain actions
-
getAlertText
Gets the current browser alert, confirm, or prompt dialog text.- Specified by:
getAlertTextin interfaceBrowserActionsContract- Returns:
- the alert text
-
typeIntoPromptAlert
Types text into the current browser prompt dialog.- Specified by:
typeIntoPromptAlertin interfaceBrowserActionsContract- Parameters:
text- text to type into the prompt- Returns:
- a self-reference to be used to chain actions
-
addCookie
- Specified by:
addCookiein interfaceBrowserActionsContract
-
getCookie
- Specified by:
getCookiein interfaceBrowserActionsContract
-
getAllCookies
- Specified by:
getAllCookiesin interfaceBrowserActionsContract
-
getCookieDomain
- Specified by:
getCookieDomainin interfaceBrowserActionsContract
-
getCookieValue
- Specified by:
getCookieValuein interfaceBrowserActionsContract
-
getCookiePath
- Specified by:
getCookiePathin interfaceBrowserActionsContract
-
deleteCookie
- Specified by:
deleteCookiein interfaceBrowserActionsContract
-
deleteAllCookies
- Specified by:
deleteAllCookiesin interfaceBrowserActionsContract
-
saveStorageState
Saves the current browser cookies,localStorage, andsessionStorageto a JSON file.Produces the same JSON schema as the WebDriver backend's
saveStorageState, so files are interchangeable between backends. Example:driver.browser().saveStorageState("target/auth-state.json");- Parameters:
filePath- target JSON file path- Returns:
- a self-reference to be used to chain actions
-
loadStorageState
Loads browser cookies,localStorage, andsessionStoragefrom a JSON file.Navigate to the target origin before loading storage so browser cookie domain rules can apply. Reads the same JSON schema as the WebDriver backend's
loadStorageState. Example:driver.browser() .navigateToURL("https://example.com") .and().loadStorageState("target/auth-state.json");- Parameters:
filePath- source JSON file path- Returns:
- a self-reference to be used to chain actions
-
captureScreenshot
- Specified by:
captureScreenshotin interfaceBrowserActionsContract
-
captureScreenshot
- Specified by:
captureScreenshotin interfaceBrowserActionsContract
-
captureSnapshot
- Specified by:
captureSnapshotin interfaceBrowserActionsContract
-
generateLightHouseReport
public void generateLightHouseReport()- Specified by:
generateLightHouseReportin interfaceBrowserActionsContract
-
waitForLazyLoading
- Specified by:
waitForLazyLoadingin interfaceBrowserActionsContract
-
getContext
- Specified by:
getContextin interfaceBrowserActionsContract
-
setContext
- Specified by:
setContextin interfaceBrowserActionsContract
-
getWindowHandles
- Specified by:
getWindowHandlesin interfaceBrowserActionsContract
-
getContextHandles
- Specified by:
getContextHandlesin interfaceBrowserActionsContract
-
accessibility
- Specified by:
accessibilityin interfaceBrowserActionsContract
-
getNativeContext
public com.microsoft.playwright.BrowserContext getNativeContext() -
getNativePage
public com.microsoft.playwright.Page getNativePage() -
locator
-
registerNetworkInterceptionRule
public BrowserActions registerNetworkInterceptionRule(BrowserNetworkInterceptionRule rule, String successMessage)
-