Rayrun
← Back to Discord Forum

Test failing randomly

josipus_231posted in #help-playwright
Open in Discord

From my read of the docs, this should work, however the test sometimes passes and sometimes not, from the traces it seems the input does not get filled.

Thanks in advance.

test("should show an error with an invalid email", async ({ page }) => {
    const email = "invalidemail";

    const inputWrapper = page.getByTestId("newsletter-input");
    const input = inputWrapper.getByRole("textbox");
    await input.fill(email);

    await page.getByRole("button", { name: "Sign Up" }).click();

    await expect(
      page.getByText("This field must be a valid email")
    ).toBeVisible();
  });

This thread is trying to answer question "Why does a test sometimes pass and sometimes fail when trying to fill an input field using Playwright?"

3 replies
warlock_montero
warlock_montero

Hey, try adding await input.waitForLoadState('domcontentloaded'); before you do the await input.fill(email);

You mean await page.waitForLoadState("domcontentloaded");?

Does not seem to make a difference

warlock_montero
warlock_montero

Can you share the error or a sneakpeak of the trace?

https://playwright.dev/docs/api/class-page#page-wait-for-load-state

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].