arrow-left Back to topicQuizWriting your first testsCheck yourself1.Which locator should you reach for FIRST when targeting a button labelled “Sign in”?page.locator('button.signin')page.getByRole('button', { name: 'Sign in' })page.$('//button[contains(., "Sign in")]')2.What does await expect(locator).toBeVisible() do?Checks once immediately and throws if the element is not visible right now.Polls until the element becomes visible or the assertion timeout is reached.Sleeps for 5 seconds and then checks visibility.3.Why does each test get its own browser context by default?To make tests slower so they appear thorough.To isolate cookies, storage and permissions so tests don’t affect each other.Because Playwright cannot reuse browser contexts across tests.4.What is test.describe used for?To mark a test as skipped and add a description of why.To group related tests together under a shared name, enabling scoped hooks and better reporting.To run a single test in isolation from the rest of the suite.To add a description string to an assertion error message.5.Where should you put repeated setup steps (like navigating to a page) that every test in a file needs?Copy them into each test — there is no way to share setup code.Put them in a test.beforeAll block so they run once for the whole file.Put them in a test.beforeEach block so they run automatically before every test.Write a helper function and call it manually at the start of each test.6.What does the context fixture give you, compared to the page fixture?It is the same as page — just an alias.It gives you the BrowserContext so you can open multiple pages, set cookies, or grant permissions for the whole context.It provides access to the browser process for launching additional browser types.It is only available in test.beforeAll blocks, not in individual tests.7.How do you scope a locator search to only look inside a specific element, such as a dialog?Pass a CSS ancestor selector as the second argument to every locator method.Chain locators — call the next locator method on the parent locator instead of on page.Use page.frame() to switch context to the dialog.There is no way to scope a locator — all searches are always page-wide.8.Why does almost every Playwright action and assertion need await?It is just a convention — the tests also work without await but produce warnings.Playwright actions return Promises; without await the action is queued but the test moves on immediately, so assertions run before the action completes.await enables the auto-retry mechanism — without it, locators cannot poll the DOM.TypeScript requires await for any method that includes the word ‘async’.Submit answersarrow-left PreviousVS CodeRunning and debugging testsNext arrow-right