Skip to content

Commit

Permalink
feat: wrap function response types
Browse files Browse the repository at this point in the history
  • Loading branch information
lucgagan committed Nov 12, 2023
1 parent d03fcd7 commit 4c95f48
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
35 changes: 24 additions & 11 deletions src/completeTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,15 @@ export const completeTask = async (
},
},
{
function: (args: { attributeName: string; elementId: string }) => {
return getLocator(args.elementId).getAttribute(args.attributeName);
function: async (args: {
attributeName: string;
elementId: string;
}) => {
return {
attributeValue: await getLocator(args.elementId).getAttribute(
args.attributeName
),
};
},
name: "locator_getAttribute",
description: "Returns the matching element's attribute value.",
Expand All @@ -91,8 +98,8 @@ export const completeTask = async (
},
},
{
function: (args: { elementId: string }) => {
return getLocator(args.elementId).innerHTML();
function: async (args: { elementId: string }) => {
return { innerHTML: await getLocator(args.elementId).innerHTML() };
},
name: "locator_innerHTML",
description: "Returns the element.innerHTML.",
Expand All @@ -113,8 +120,8 @@ export const completeTask = async (
},
},
{
function: (args: { elementId: string }) => {
return getLocator(args.elementId).innerText();
function: async (args: { elementId: string }) => {
return { innerText: await getLocator(args.elementId).innerText() };
},
name: "locator_innerText",
description: "Returns the element.innerText.",
Expand Down Expand Up @@ -159,8 +166,10 @@ export const completeTask = async (
},
},
{
function: (args: { elementId: string }) => {
return getLocator(args.elementId).inputValue();
function: async (args: { elementId: string }) => {
return {
inputValue: await getLocator(args.elementId).inputValue(),
};
},
name: "locator_inputValue",
description:
Expand All @@ -183,7 +192,9 @@ export const completeTask = async (
},
{
function: async (args: { elementId: string }) => {
return await getLocator(args.elementId).blur();
await getLocator(args.elementId).blur();

return { success: true };
},
name: "locator_blur",
description: "Removes keyboard focus from the current element.",
Expand Down Expand Up @@ -467,8 +478,10 @@ export const completeTask = async (
},
},
{
function: (args: { url: string }) => {
return page.goto(args.url);
function: async (args: { url: string }) => {
return {
url: await page.goto(args.url),
};
},
name: "page_goto",
description: "Set a value to the input field.",
Expand Down
9 changes: 4 additions & 5 deletions tests/auto.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ test("executes action", async ({ page }) => {
test("executes click", async ({ page }) => {
await page.goto("/");

await auto(
"Click the button until the counter value is equal to 2",
{ page, test },
{ debug: true }
);
await auto("Click the button until the counter value is equal to 2", {
page,
test,
});

await expect(page.getByTestId("current-count")).toHaveText("2");
});
Expand Down

0 comments on commit 4c95f48

Please sign in to comment.