Ndor
Ndor

Reputation: 29

How to fix assertion error using playwright?

I'm using playwright to do e2e testing to check if the email is exists or not, and while I run my tests its said : "Finished test flow with status passed"

But its show me that the test is failed because i have assertion error and not because i do something wrong

this is a piece my code:

const fillEmail = async (page: Page, value: string) =>
    await page.fill("email-for-test", value);

const fillPassword = async (page: Page, value: string) =>
    await page.fill("password-for-test", value);


  await fillName(page, name);
  await fillEmail(page, email);
  const res = await page.locator('.email-error').innerText(); // return error string
  expect(res).toContain("Email is already in used");

enter image description here and i got error, you can see in the picture that I uploaded any idea how to remove or fix this error

enter image description here

Upvotes: 0

Views: 4139

Answers (3)

Ndor
Ndor

Reputation: 29

i soulve this one by upgrade playwright library, From v1.15 to v1.25

Upvotes: 0

Alapan Das
Alapan Das

Reputation: 18601

How about you just use this:

await expect(page.locator('.email-error')).toContainText(
  'Email is already in used',
  {timeout: 7000}
)

Also Check if the last word of the assertion message is used or use.

You can also use the text selector and assert it to be visible. Something like this:

await expect(page.locator('text=Email is already in use')).toBeVisible({
  timeout: 7000,
})

Upvotes: 1

Pablo
Pablo

Reputation: 350

You code actually works. You can also use page.textContent()

const res = await page.locator('.email-error').innerText(); 
expect(res).toContain("Email is already in use");

const text = await page.textContent('.email-error');
expect(text).toContain("Email is already in use");

Upvotes: 3

Related Questions