Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider adjusting the API to an OOP design #18

Open
Merkie opened this issue Nov 17, 2023 · 1 comment
Open

Consider adjusting the API to an OOP design #18

Merkie opened this issue Nov 17, 2023 · 1 comment

Comments

@Merkie
Copy link
Contributor

Merkie commented Nov 17, 2023

Hey lucgagan, I really love this project.
I noticed that the API requires you to pass in the same options every time you call auto. Would you consider a more object-oriented approach like this one so users can initialize the function once and then call it repeatedly with the same state? This would also be useful for setting token limits and other configurations due to the nature of the persistent state in objects.

Here's the kind of syntax I was imagining:

import AutoPlaywright from "auto-playwright";

const ap = new AutoPlaywright({
    openAiKey: "sk-...",
    model: "gpt-4-1106-preview", // this can mirror the model types from OpenAI
    // ...whatever else here
});

ap.auto("Get the text of the first link", { page, test })

Let me know what you think, as this would be a bigger change, so I didn't want to start coding anything yet, but I think taking up this approach would have numerous benefits like the ones I mentioned previously. This is also similar to how many other packages behave.

Thanks!
Keep up the good work man

@lucgagan
Copy link
Owner

I think for most people, a better solution would be to just use Playwright fixtures.

https://playwright.dev/docs/test-fixtures

const test = base.extend<{ auto: TodoPage }>({
  auto: async ({ page, test }, use) => {
    await use((instructions, options) => {
      return auto(instructions, { page, test }, options);
    });
  },
});

Now you could just use it like:

test("auto Playwright example", async ({ auto, page }) => {
  await page.goto("/");

  const headerText = await auto("get the header text");

  await auto(`Type "${headerText}" in the search box`);

  const searchInputHasHeaderText = await auto(`Is the contents of the search box equal to "${headerText}"?`);

  expect(searchInputHasHeaderText).toBe(true);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants