u/StickyStapler

Class-based vs factory function for Page Object Models in Playwright - which do you use?

I recently joined a new repo and noticed the codebase has two different styles of Page Object Model patterns and I was wondering if there's a preference. From the docs I only see references to the class-based pattern.

Class-based:

  class AddTodoPage {
    public readonly page: Page;
    public readonly titleInput: Locator;
    public readonly submitButton: Locator;

    constructor(page: Page) {
      this.page = page;
      this.titleInput = page.getByRole('textbox', { name:
   'Title' });
      this.submitButton = page.getByRole('button', {
  name: 'Add Todo' });
    }

    async goto() {
      await this.page.goto('/todos/new');
    }

    async fillTitle(title: string) {
      await this.titleInput.fill(title);
    }

    async submit() {
      await this.submitButton.click();
    }
  }

  // Usage
  test('Adds a todo', async ({ page }) => {
    const addTodoPage = new AddTodoPage(page);
    await addTodoPage.goto();
    await addTodoPage.fillTitle('Buy milk');
    await addTodoPage.submit();
  });

Factory function:

  function createAddTodoPage(page: Page) {
    return {
      goto: () => page.goto('/todos/new'),
      fillTitle: (title: string) =>
  page.getByRole('textbox', { name: 'Title'
  }).fill(title),
      submit: () => page.getByRole('button', { name: 'Add
   Todo' }).click(),
    };
  }

  // Usage
  test('Adds a todo', async ({ page }) => {
    const addTodoPage = createAddTodoPage(page);
    await addTodoPage.goto();
    await addTodoPage.fillTitle('Buy milk');
    await addTodoPage.submit();
  });
reddit.com
u/StickyStapler — 1 day ago
▲ 5 r/ynab

This isn't really a big deal, but I'm curious how others deal with it.

For things like Car and Home insurance I set aside an amount each month up to what I think the max will be. I set the target for 1 month before it's due so that I can pay early. I'm often below the target, so I'm not sure if it's best to move the excess in the current month to "Ready to assign" and redistribute to other categories, and start saving again next month. Or should I change the target type to "Refill up to", meaning I have less to put in monthly given the category will already have some money in it.

reddit.com
u/StickyStapler — 17 days ago
▲ 5 r/ynab

Which do you prefer? I guess it can depend on the how old each car is. In our case, both cars are the same make, model and year.

reddit.com
u/StickyStapler — 21 days ago