Skip to content

Commit

Permalink
Merge pull request #46 from nikolas-garza-ai/nikg/add-keyboard-actions
Browse files Browse the repository at this point in the history
[Auto Playwright] adding keyboard actions
  • Loading branch information
lucgagan authored Jan 21, 2025
2 parents 9951c33 + bca1ef8 commit 3d34887
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ console.log(`"There are 3 links" is a ${thereAreThreeLinks} statement`);
- `locator.textContent`
- `locator.uncheck`
- `page.goto`
- `page.keyboard.press`

Adding new actions is easy: just update the `functions` in [`src/completeTask.ts`](src/completeTask.ts).

Expand Down
46 changes: 46 additions & 0 deletions src/createActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,52 @@ export const createActions = (
};

return {
locator_pressKey: {
function: async (args: { elementId: string; key: string }) => {
const { elementId, key } = args;
await getLocator(elementId).press(key);
return { success: true };
},
name: "locator_pressKey",
description: "Presses a key while focused on the specified element.",
parse: (args: string) => {
return z
.object({
elementId: z.string(),
key: z.string(),
})
.parse(JSON.parse(args));
},
parameters: {
type: "object",
properties: {
elementId: { type: "string" },
key: { type: "string", description: "The name of the key to press, e.g., 'Enter', 'ArrowUp', 'a'." },
},
},
},
page_pressKey: {
function: async (args: { elementId: string; key: string }) => {
const { key } = args;
await page.keyboard.press(key);
return { success: true };
},
name: "page_pressKey",
description: "Presses a key globally on the page.",
parse: (args: string) => {
return z
.object({
key: z.string(),
})
.parse(JSON.parse(args));
},
parameters: {
type: "object",
properties: {
key: { type: "string", description: "The name of the key to press, e.g., 'Enter', 'ArrowDown', 'b'." },
},
},
},
locateElement: {
function: async (args: { cssSelector: string }) => {
const locator = await page.locator(args.cssSelector);
Expand Down

0 comments on commit 3d34887

Please sign in to comment.