Bird
0
0

Which of the following is the correct syntax to assert that a page contains the text 'Welcome' using Playwright's test library?

easy📝 Syntax Q3 of 15
Remix - Testing
Which of the following is the correct syntax to assert that a page contains the text 'Welcome' using Playwright's test library?
Aawait expect(page).toHaveText('Welcome')
Bawait expect(page).toContainText('Welcome')
Cawait expect(page.locator('Welcome')).exists()
Dawait expect(page.locator('text=Welcome')).toBeVisible()
Step-by-Step Solution
Solution:
  1. Step 1: Understand Playwright assertion syntax

    To check text visibility, use expect(locator).toBeVisible() with a text locator.
  2. Step 2: Evaluate options

    await expect(page.locator('text=Welcome')).toBeVisible() correctly uses page.locator('text=Welcome') and toBeVisible(). Others are invalid or incorrect syntax.
  3. Final Answer:

    await expect(page.locator('text=Welcome')).toBeVisible() -> Option D
  4. Quick Check:

    Text presence = expect(locator).toBeVisible() [OK]
Quick Trick: Use locator with text= and toBeVisible() for text assertions [OK]
Common Mistakes:
MISTAKES
  • Using expect(page) directly for text
  • Wrong method names like toHaveText
  • Missing locator for text

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Remix Quizzes