So im trying to figure out/explain why a piece of code works the way it does. Im familiar with async for the most part and understand how promises work on a basic level, but I am trying to explain why a block of code works the way it does in Playwright.
import { test, expect } from "@playwright/test";
test.only("Basic Login", async ({ page }) => {
//Basic test that demonstrates logging into a webpage
await page.goto("/");
page
.getByPlaceholder("Email Address")
.fill("foo@email.com");
await page.getByPlaceholder("Password").fill("bar");
await page.getByRole("button", { name: "Sign In" }).click();
await expect(page).toHaveTitle("The Foobar Page");
});
So obviously this will not work, because the first "fill" for email address input isn't await
ing. Currently the behavior is it fills in the password field with both the email and password strings together (I assume, I can't see it because it's a password field, but the number of *
's is longer so I assume it's putting both fill
strings into the password field.
However I can't really understand why. getByPlaceholder
will keep retrying until it fails. and I also believe fill
waits for checks (IE: the field is fillable/visible/etc...)
However Playwright specifically doesn't state whether these return promises specifically. I ASSUME they do but the docs don't specifically say.
So what is actually going on here step by step? I can't really "walk" my way through it, so it makes it difficult to explain to others. As in I understand why it doesn't work on a high level, but not exactly why it doesn't work in detail.
This also leads me to a side question: Does Playwright wait for BOTH promises when chaining functions? Or only the last one?