arrow-left Back to topicQuizAssertionsCheck yourself1.You click Submit and expect a success banner to appear. The banner is shown by an async API call. Which assertion should you use?const text = await page.locator('.banner').textContent(); expect(text).toBe('Success')await expect(page.getByTestId('success-banner')).toBeVisible()await page.waitForTimeout(2000); expect(await page.locator('.banner').isVisible()).toBe(true)2.You want to check 5 fields on a confirmation page and see ALL failures at once, not stop at the first one. What do you use?Regular expect() — it accumulates failures automaticallyexpect.soft() — marks the test as failed but continues runningexpect.poll() — retries each check until it passes3.What is the difference between toHaveText() and toContainText()?They are the same — both do a full exact matchtoHaveText() requires the full text to match exactly; toContainText() passes if the element's text includes the expected substringtoContainText() checks the HTML content while toHaveText() checks only visible texttoHaveText() retries automatically while toContainText() runs only once4.You want to assert that a table has exactly 10 data rows. Which assertion is correct?expect(await page.getByRole('row').count()).toBe(10)await expect(page.getByRole('row')).toHaveCount(10)await expect(page.getByRole('row').length).toBe(10)expect(page.getByRole('row')).toHaveLength(10)5.A button should be disabled after a form is submitted. Which assertion correctly verifies this?expect(await page.getByRole('button').getAttribute('disabled')).toBe('true')await expect(page.getByRole('button', { name: 'Submit' })).toBeDisabled()await expect(page.getByRole('button', { name: 'Submit' })).not.toBeEnabled()Both B and C are correct6.How do you assert that an element has a specific HTML attribute value, for example data-status='active'?await expect(locator).toHaveText('active')await expect(locator).toHaveAttribute('data-status', 'active')expect(await locator.getAttribute('data-status')).toBe('active')await expect(locator).toHaveValue('active')7.The default assertion timeout is 5 seconds. How do you change it to 10 seconds for all assertions in a project?Pass { timeout: 10000 } to every individual expect() callSet expect: { timeout: 10000 } in playwright.config.tsSet use: { actionTimeout: 10000 } in playwright.config.tsCall expect.setTimeout(10000) at the top of each test file8.When should you use expect.poll() instead of a regular locator assertion?When you want to assert something faster than the default retry intervalWhen you need to retry an assertion on a non-locator value, like an API response status or a computed countWhen the locator assertion does not support the .not modifierWhen you want to run multiple assertions in parallelSubmit answersarrow-left PreviousAuto-waitingCommand lineNext arrow-right