I have a chat application that I’m writing Playwright tests for. There is a textbox
where the user can write their message. When the user presses Enter
, the message should be sent. When the user presses Shift+Enter
, the message should not be sent, but a line break should be added to the message.
How can I write Playwright tests for this? Here is a start:
test("pressing enter should send message", async ({ page }) => {
await page.goto("/chat");
const input = page.getByRole("textbox");
await input.fill("foo");
await input.press("Enter");
await expect(input).toHaveValue("foo");
// TODO: Expect that the form is submitted.
});
test("pressing shift+enter should create a line break", async ({ page }) => {
await page.goto("/chat");
const input = page.getByRole("textbox");
await input.fill("foo");
await input.press("Enter");
await expect(input).toHaveValue("foon"); // Can the line break be rn?
// TODO: Expect that the form is not submitted
});