fix(screenshot): support refs and improve error messages (#141)
* fix(screenshot): support refs and improve error messages * fix(cli): support selector argument in screenshot command * Fix CSS class selectors being treated as file paths * fix(test): update screenshot test assertions --------- Co-authored-by: Chris Tate <chris@ctate.dev>
This commit is contained in:
co-authored by
Chris Tate
parent
c046de2ec7
commit
9f3c3ad933
+14
-7
@@ -549,15 +549,22 @@ async function handleScreenshot(
|
||||
|
||||
let target: Page | ReturnType<Page['locator']> = page;
|
||||
if (command.selector) {
|
||||
target = page.locator(command.selector);
|
||||
target = browser.getLocator(command.selector);
|
||||
}
|
||||
|
||||
if (command.path) {
|
||||
await target.screenshot({ ...options, path: command.path });
|
||||
return successResponse(command.id, { path: command.path });
|
||||
} else {
|
||||
const buffer = await target.screenshot(options);
|
||||
return successResponse(command.id, { base64: buffer.toString('base64') });
|
||||
try {
|
||||
if (command.path) {
|
||||
await target.screenshot({ ...options, path: command.path });
|
||||
return successResponse(command.id, { path: command.path });
|
||||
} else {
|
||||
const buffer = await target.screenshot(options);
|
||||
return successResponse(command.id, { base64: buffer.toString('base64') });
|
||||
}
|
||||
} catch (error) {
|
||||
if (command.selector) {
|
||||
throw toAIFriendlyError(error, command.selector);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user