Package io.karatelabs.driver
Interface CoreDriver
- All Known Subinterfaces:
Driver
public interface CoreDriver
Core driver interface defining the primitive operations.
All driver operations reduce to a small set of primitives, with eval(js)
being THE foundational primitive. This interface documents the minimal set of
methods that require backend-specific implementation (CDP, WebDriver, etc.).
Tier 1: Essential Primitives
eval(String)- Execute JavaScript (Runtime.evaluate) - THE core primitivenavigate(String)- Navigate to URL (Page.navigate)keys()- Keyboard input (Input.dispatchKeyEvent)screenshot()- Capture screenshot (Page.captureScreenshot)frame(Object)- Switch frames (Page.getFrameTree + createIsolatedWorld)dialog(boolean, String)- Handle JS dialogs (Page.handleJavaScriptDialog)
Tier 2: Extended Primitives
mouse()- Mouse input (Input.dispatchMouseEvent)pdf(Map)- Generate PDF (Page.printToPDF)cookie(String),cookie(Map)- Cookie operations (Network.*)intercept(List, InterceptHandler)- Request interception (Fetch.*)window(String)- Window management (Browser.*)tab(Object)- Tab/page switching (Target.*)
All other Driver methods (click, text, waitFor, etc.) are convenience methods
that delegate to these primitives, primarily to eval().
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionGet a cookie by name.voidSet a cookie.voidHandle JavaScript dialog (alert, confirm, prompt, beforeunload).Execute JavaScript and return result.voidSwitch to a frame.Get driver options.voidintercept(List<String> patterns, InterceptHandler handler) Enable request interception with a handler.booleanCheck if driver is terminated.keys()Get a Keys object for keyboard input.mouse()Get a Mouse object for mouse input.voidNavigate to URL and wait for page load.byte[]Generate a PDF of the current page.voidquit()Close driver and browser.byte[]Take screenshot and return PNG bytes.voidSwitch to a different tab/page.voidPerform window management operation.
-
Method Details
-
eval
Execute JavaScript and return result. This is THE foundational primitive - virtually all element operations generate JavaScript that is executed via this method.Examples:
eval("document.title") // get page title eval("document.querySelector('#btn').click()") // click element eval("document.querySelector('input').value") // get input value- Parameters:
js- JavaScript expression to execute- Returns:
- the result of the JavaScript execution
-
keys
Keys keys()Get a Keys object for keyboard input. Maps to CDP Input.dispatchKeyEvent.- Returns:
- the Keys object for typing and key events
-
screenshot
byte[] screenshot()Take screenshot and return PNG bytes. Maps to CDP Page.captureScreenshot.- Returns:
- PNG image bytes
-
frame
Switch to a frame. Maps to CDP Page.getFrameTree + Page.createIsolatedWorld.- Parameters:
target- frame identifier: -nullto return to main frame -Integerfor frame index -Stringfor frame locator
-
dialog
Handle JavaScript dialog (alert, confirm, prompt, beforeunload). Maps to CDP Page.handleJavaScriptDialog.- Parameters:
accept- true to accept (OK), false to dismiss (Cancel)input- text for prompt dialogs (ignored if accept is false)
-
mouse
Mouse mouse()Get a Mouse object for mouse input. Maps to CDP Input.dispatchMouseEvent.- Returns:
- a new Mouse object at position (0, 0)
-
pdf
Generate a PDF of the current page. Maps to CDP Page.printToPDF.- Parameters:
options- PDF options (scale, landscape, margins, etc.), or null for defaults- Returns:
- PDF bytes
-
cookie
Get a cookie by name. Maps to CDP Network.getCookies.- Parameters:
name- the cookie name- Returns:
- the cookie as a Map, or null if not found
-
cookie
Set a cookie. Maps to CDP Network.setCookie.- Parameters:
cookie- the cookie as a Map with keys: name, value, domain, path, etc.
-
intercept
Enable request interception with a handler. Maps to CDP Fetch.enable + Fetch.requestPaused handling.- Parameters:
patterns- URL patterns to intercept (e.g., "*api/*")handler- the intercept handler (return InterceptResponse to mock, null to continue)
-
window
Perform window management operation. Maps to CDP Browser.setWindowBounds.- Parameters:
operation- one of: "maximize", "minimize", "fullscreen", "normal"
-
tab
Switch to a different tab/page. Maps to CDP Target.activateTarget + Target.attachToTarget.- Parameters:
target- tab identifier: -Integerfor tab index -Stringfor title or URL substring match
-
quit
void quit()Close driver and browser. -
isTerminated
boolean isTerminated()Check if driver is terminated. -
getOptions
DriverOptions getOptions()Get driver options.
-