Skip to content

Conversation

@stefanbinoj
Copy link
Contributor

@stefanbinoj stefanbinoj commented Nov 6, 2025

ref #1064

Problem

  • Previously, utils/replyHelper used promises with a timeout of 5000 ms to determine whether the modal was for creating or editing saved replies.
  const buttonPromises = [
    updateBtn
      .waitFor({ state: "visible", timeout: 5000 })
      .then(() => updateBtn)
      .catch(() => null),
    addBtn
      .waitFor({ state: "visible", timeout: 5000 })
      .then(() => addBtn)
      .catch(() => null),
    saveBtn
      .waitFor({ state: "visible", timeout: 5000 })
      .then(() => saveBtn)
      .catch(() => null),
  ];

  // Wait for any button to become visible
  const buttons = await Promise.all(buttonPromises);
  const visibleButton = buttons.find((btn) => btn !== null);
  • As a result, the clickSaveButton function took 5 seconds timeout to execute, and it’s used in 13 places across the codebase.

Solution

  • Instead of identifying the modal type via visible buttons, a more efficient approach is to distinguish it using the modal title and perform the action directly.
  const createDialog = page.locator('[role="dialog"]:has-text("New saved reply")');
  const editDialog = page.locator('[role="dialog"]:has-text("Edit saved reply")');

  const [isCreateContext, isEditContext] = await Promise.all([
    createDialog.isVisible({ timeout: 500 }).catch(() => false),
    editDialog.isVisible({ timeout: 500 }).catch(() => false)
  ]);

  if (isCreateContext) {
    await createDialog.locator('button:has-text("Add")').click();
  } else if (isEditContext) {
    await editDialog.locator('button:has-text("Update")').click();
  }
  • This optimization reduces the total time from 5–10 seconds to under 500 ms. Saving couple of 5sec delays.

Local

Before After
Screenshot 2025-11-06 at 3 45 16 PM Screenshot 2025-11-06 at 3 45 25 PM Screenshot 2025-11-06 at 3 37 11 PM Screenshot 2025-11-06 at 3 37 31 PM
  • Saves approximately 13 × 5 = 65 seconds overall.

AI Usage

  • GPT (free) via chat.openai.com was used for formatting and fixing typos in the PR description.

Self Review

  • All code was written by myself and I have reviewed all the code.

Live Stream Disclosure

  • Viewed both live streams of antiwork and guidelines to follow.

@stefanbinoj
Copy link
Contributor Author

@slavingia, could you please review? I’ve confirmed with the artifact from this PR’s Playwright E2E tests that this change reduces the runtime by 5 seconds across 13 tests.

@stefanbinoj stefanbinoj changed the title optimize saved-replies test suite perf(e2e) : optimize saved-replies test suite Nov 7, 2025
@stefanbinoj stefanbinoj changed the title perf(e2e) : optimize saved-replies test suite perf(e2e) : Optimize saved-replies test suite Nov 7, 2025
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

Successfully merging this pull request may close these issues.

1 participant