Class PlaywrightService
java.lang.Object
com.shaft.mcp.PlaywrightService
MCP-safe Playwright tools backed by
SHAFT.GUI.Playwright.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionappendText(locatorStrategy locatorStrategy, String locatorValue, String textValue) Appends text to a Playwright element.clear(locatorStrategy locatorStrategy, String locatorValue) Clears a Playwright element.click(locatorStrategy locatorStrategy, String locatorValue) Clicks a Playwright element.clickUsingJavaScript(locatorStrategy locatorStrategy, String locatorValue) Clicks a Playwright element using JavaScript.doubleClick(locatorStrategy locatorStrategy, String locatorValue) Double-clicks a Playwright element.dragAndDrop(locatorStrategy sourceLocatorStrategy, String sourceLocatorValue, locatorStrategy targetLocatorStrategy, String targetLocatorValue) Drags one Playwright element to another.Gets current Playwright page URL.getPageDom(int maxCharacters) Captures the current Playwright page DOM.getTitle()Gets current Playwright page title.hover(locatorStrategy locatorStrategy, String locatorValue) Hovers over a Playwright element.voidinitialize(String browser, boolean headless) Initializes a SHAFT Playwright browser session.booleanisDisplayed(locatorStrategy locatorStrategy, String locatorValue) Checks Playwright element visibility.booleanisEnabled(locatorStrategy locatorStrategy, String locatorValue) Checks Playwright element enabled state.loadStorageState(String filePath) Loads cookies,localStorage, andsessionStoragefrom a JSON file into the active Playwright session.Navigates the Playwright page to a URL.Navigates back in the Playwright page history.Navigates forward in the Playwright page history.Opens a new Playwright tab or window.voidquit()Quits the active SHAFT Playwright session.recordAtTargetCodeBlocks(String recordingPath, String driverVariableName, String targetSourcePath, String insertAfter) Generates focused Playwright recording snippets for insertion into an existing Page Object.recordingCodeBlocks(String recordingPath, String driverVariableName) Generates copy-paste replay code from a Playwright recording.recordStart(String outputPath, String mode, boolean includeSensitiveValues) Starts recording Playwright actions performed through MCP Playwright tools.Returns Playwright recording status.recordStop(boolean discard) Stops Playwright recording.refresh()Refreshes the Playwright page.replayRecording(String recordingPath, String driverVariableName) Replays a Playwright recording against the active Playwright session.saveStorageState(String filePath) Saves the active Playwright session's cookies,localStorage, andsessionStorageto a JSON file.setValueUsingJavaScript(locatorStrategy locatorStrategy, String locatorValue, String textValue) Sets an element value using JavaScript.setWindowSize(int width, int height) Sets the Playwright viewport size.stepDelete(String stepId) Deletes a recorded Playwright step by its stable stepId, as surfaced in recorder status.stepReorder(String stepId, String direction) Moves a recorded Playwright step up or down by its stable stepId, as surfaced in recorder status.takeScreenshot(String outputPath, boolean includeBase64) Takes a PNG screenshot of the current Playwright page.type(locatorStrategy locatorStrategy, String locatorValue, String textValue) Types into a Playwright element.uploadFile(locatorStrategy locatorStrategy, String locatorValue, String filePath) Uploads a file through a Playwright file input.
-
Constructor Details
-
PlaywrightService
public PlaywrightService()Creates the default Playwright MCP service.
-
-
Method Details
-
initialize
Initializes a SHAFT Playwright browser session.- Parameters:
browser- chromium, chrome, firefox, webkit, or safari; blank uses SHAFT defaultsheadless- whether to launch headlessly
-
quit
public void quit()Quits the active SHAFT Playwright session. -
recordStart
public McpMobileRecordingStatus recordStart(String outputPath, String mode, boolean includeSensitiveValues) Starts recording Playwright actions performed through MCP Playwright tools.- Parameters:
outputPath- workspace-contained recording JSON output pathmode- recording labelincludeSensitiveValues- whether typed values may be persisted- Returns:
- recorder status
-
recordStatus
Returns Playwright recording status.- Returns:
- recorder status
-
recordStop
Stops Playwright recording.- Parameters:
discard- whether to delete the recording output- Returns:
- final recorder status
-
stepDelete
Deletes a recorded Playwright step by its stable stepId, as surfaced in recorder status.- Parameters:
stepId- stable step id (e.g. "m2") fromMcpMobileRecordingStatus.steps()- Returns:
- updated recorder status
-
stepReorder
Moves a recorded Playwright step up or down by its stable stepId, as surfaced in recorder status.- Parameters:
stepId- stable step id (e.g. "m2") fromMcpMobileRecordingStatus.steps()direction- "up" or "down"- Returns:
- updated recorder status
-
recordingCodeBlocks
Generates copy-paste replay code from a Playwright recording.- Parameters:
recordingPath- workspace-contained recording pathdriverVariableName- driver variable name to use in generated snippets- Returns:
- replay code blocks
-
recordAtTargetCodeBlocks
public McpMobileReplayResult recordAtTargetCodeBlocks(String recordingPath, String driverVariableName, String targetSourcePath, String insertAfter) Generates focused Playwright recording snippets for insertion into an existing Page Object.- Parameters:
recordingPath- workspace-contained recording pathdriverVariableName- driver variable name to use in generated snippetstargetSourcePath- workspace-contained Java Page Object source pathinsertAfter- method name or textual anchor to insert after- Returns:
- replay code blocks plus target insertion snippets
-
replayRecording
Replays a Playwright recording against the active Playwright session.- Parameters:
recordingPath- workspace-contained recording pathdriverVariableName- driver variable name to use in generated snippets- Returns:
- replay result
-
refresh
Refreshes the Playwright page.- Returns:
- recorded action metadata
-
setWindowSize
Sets the Playwright viewport size.- Parameters:
width- viewport widthheight- viewport height- Returns:
- recorded action metadata
-
newWindow
Opens a new Playwright tab or window.- Parameters:
targetUrl- optional URL; blank opens about:blankwindowType- TAB or WINDOW- Returns:
- recorded action metadata
-
getCurrentUrl
-
getTitle
-
getPageDom
Captures the current Playwright page DOM.- Parameters:
maxCharacters- maximum DOM characters to return- Returns:
- page DOM snapshot
-
takeScreenshot
Takes a PNG screenshot of the current Playwright page.- Parameters:
outputPath- optional workspace-contained output file pathincludeBase64- whether to include base64 bytes in the response- Returns:
- screenshot metadata
-
saveStorageState
Saves the active Playwright session's cookies,localStorage, andsessionStorageto a JSON file.Produces the same JSON schema as
browser_storage_state_save, so files are interchangeable between the WebDriver and Playwright backends.- Parameters:
filePath- workspace-relative or workspace-contained output file path- Returns:
- the absolute path the storage state was written to
-
loadStorageState
Loads cookies,localStorage, andsessionStoragefrom a JSON file into the active Playwright session.Navigate to the target origin before loading storage state so browser cookie domain rules can apply.
- Parameters:
filePath- workspace-contained source JSON file path- Returns:
- a short confirmation including the resolved path and restored cookie count
-
click
Clicks a Playwright element. -
clickUsingJavaScript
public McpMobileActionResult clickUsingJavaScript(locatorStrategy locatorStrategy, String locatorValue) Clicks a Playwright element using JavaScript. -
doubleClick
Double-clicks a Playwright element. -
hover
Hovers over a Playwright element. -
type
public McpMobileActionResult type(locatorStrategy locatorStrategy, String locatorValue, String textValue) Types into a Playwright element. -
appendText
public McpMobileActionResult appendText(locatorStrategy locatorStrategy, String locatorValue, String textValue) Appends text to a Playwright element. -
setValueUsingJavaScript
public McpMobileActionResult setValueUsingJavaScript(locatorStrategy locatorStrategy, String locatorValue, String textValue) Sets an element value using JavaScript. -
clear
Clears a Playwright element. -
uploadFile
public McpMobileActionResult uploadFile(locatorStrategy locatorStrategy, String locatorValue, String filePath) Uploads a file through a Playwright file input. -
dragAndDrop
public McpMobileActionResult dragAndDrop(locatorStrategy sourceLocatorStrategy, String sourceLocatorValue, locatorStrategy targetLocatorStrategy, String targetLocatorValue) Drags one Playwright element to another. -
isDisplayed
Checks Playwright element visibility. -
isEnabled
Checks Playwright element enabled state.
-