[{"id":"playwrightbeginner-001","courseId":"playwright-beginner","domain":"locators-and-selectors","topic":"Recommended built-in locators","prompt":"A teammate needs to click the Sign in button in a new login test. Which built-in locator does the Playwright documentation recommend trying first?","hint":"Pick the locator that matches the control the way a person would perceive it.","explain":"Built-in locators find elements by how users perceive them, by attributes such as titles or placeholders, or by raw markup. Each kind holds up differently when the page's markup changes.","source":"https://playwright.dev/docs/locators#quick-guide","interaction":{"type":"single"},"options":[{"id":"a","text":"page.locator('#sign-in-btn')","whyNot":"CSS selectors tie a test to the DOM structure, and the docs warn that they break when that structure changes."},{"id":"b","text":"page.getByTitle('Sign in')","whyNot":"Title locators need a title attribute on the element, which a plain button usually lacks."},{"id":"c","text":"page.getByRole('button', { name: 'Sign in' })","why":"Role locators match the way users and assistive technology perceive the page, and the docs prioritize them."},{"id":"d","text":"page.getByPlaceholder('Sign in')","whyNot":"Placeholder locators find inputs by their hint text, and a button does not carry a placeholder."}],"answer":"c","explanation":"page.getByRole() is the first built-in locator the docs recommend, because it matches elements the way users and assistive technology perceive them.","concept":"page.getByRole() is the first built-in locator the docs recommend, because it matches elements the way users and assistive technology perceive them.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["Start with user-facing built-in locators; reach for CSS or XPath only when nothing else fits."]},{"id":"playwrightbeginner-002","courseId":"playwright-beginner","domain":"locators-and-selectors","topic":"Role locators and accessible names","prompt":"A page has two buttons: 'Submit order' and 'Submit feedback'. A test calls page.getByRole('button') and clicks the result. What is the problem?","hint":"Count how many elements a query naming only the kind of control would match on this page.","explain":"Elements can be described by a role, the job they play, and by a name that assistive technology reads out. Each part of that description narrows which elements a query can land on.","source":"https://playwright.dev/docs/locators#locate-by-role","interaction":{"type":"single"},"options":[{"id":"a","text":"It finds nothing, because native buttons have no role attribute for the locator to match.","whyNot":"Native button elements have an implicit role that role locators recognize, so they are found."},{"id":"b","text":"It works as written, since a role alone pinpoints one element by default.","whyNot":"The docs advise passing the accessible name as well, because the role alone is not meant to pinpoint one element."},{"id":"c","text":"It clicks the button whose name comes first alphabetically.","whyNot":"Nothing in the docs describes ordering by name; the name is an argument you add to narrow the match."},{"id":"d","text":"It matches every button on the page, so it doesn't pinpoint one; adding the accessible name narrows the match.","why":"A role alone describes a kind of element, so every button qualifies; the accessible name picks out the exact one."}],"answer":"d","explanation":"When locating by role, pass the accessible name too: a role alone can match many elements, and the name pinpoints the exact one.","concept":"When locating by role, pass the accessible name too: a role alone can match many elements, and the name pinpoints the exact one.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["A role locator without a name is a warning sign when a page has several controls of the same kind."]},{"id":"playwrightbeginner-003","courseId":"playwright-beginner","domain":"locators-and-selectors","topic":"Label locators for form fields","prompt":"page.getByLabel('Email') can find a plain paragraph whose only text is 'Email'.","hint":"Think about which elements a label is attached to in the markup.","explain":"A locator can target an element by its place in a form, by the words it displays, or by its attributes. Each built-in locator is designed around one of these routes.","source":"https://playwright.dev/docs/locators#locate-by-label","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","whyNot":"getByLabel() only finds form controls tied to a label, so a plain paragraph lies outside what it matches."},{"id":"b","text":"False","why":"getByLabel() locates a form control through its associated label; plain paragraph text is what text locators are for."}],"answer":"b","explanation":"page.getByLabel() locates a form control through the text of its associated label; it is meant for form fields, not arbitrary text.","concept":"page.getByLabel() locates a form control through the text of its associated label; it is meant for form fields, not arbitrary text.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["Use label locators for form fields and text locators for plain content like paragraphs and spans."]},{"id":"playwrightbeginner-004","courseId":"playwright-beginner","domain":"locators-and-selectors","topic":"Text matching with getByText","prompt":"A span on the page reads 'Welcome, John Smith'. A test calls page.getByText('Welcome, John') with no other arguments. What happens?","hint":"Check whether the call passes any options that narrow how the text is compared.","explain":"Text can be compared in several ways: as a loose piece of a longer string, as an identical whole, or as a pattern. A stricter comparison rejects extra words that a looser one accepts.","source":"https://playwright.dev/docs/locators#locate-by-text","interaction":{"type":"single"},"options":[{"id":"a","text":"Nothing matches, because the search text must equal the whole content of the span.","whyNot":"Matching the full content is only required when you pass exact: true."},{"id":"b","text":"The span matches, because getByText finds an element by the text it contains.","why":"Without exact, the search text is matched inside the element's text, so the shorter phrase finds this span."},{"id":"c","text":"It throws an error, because partial text needs exact: true to be matched.","whyNot":"exact: true asks for a full match; partial text is matched without it, so no error is raised."},{"id":"d","text":"It matches only if the search text is written as a regular expression.","whyNot":"A regular expression is one allowed form, but a plain string also works without one."}],"answer":"b","explanation":"page.getByText() matches elements by the text they contain; exact: true turns the match into a full-string comparison.","concept":"page.getByText() matches elements by the text they contain; exact: true turns the match into a full-string comparison.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["getByText matches substrings unless you set an exact match."]},{"id":"playwrightbeginner-005","courseId":"playwright-beginner","domain":"locators-and-selectors","topic":"Test id locators","prompt":"Your team wants a locator that survives wording changes on a button. Which TWO statements about page.getByTestId() match the Playwright docs?","hint":"Ask what the locator reads from the element, and whether a copywriter would ever change it.","explain":"Locators can key on content people read, on roles, or on markup added only for testing. Each kind changes for different reasons, which decides how long a test stays stable.","source":"https://playwright.dev/docs/locators#locate-by-test-id","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"It is user-facing, so it reflects what a person sees on screen.","whyNot":"The docs say testing by test ids is not user facing; it reads a dedicated attribute instead."},{"id":"b","text":"It finds elements by the data-testid attribute unless the config changes that attribute name.","why":"By default getByTestId reads data-testid, and the test config can set a different attribute."},{"id":"c","text":"It is the first choice whenever a role or text locator is available.","whyNot":"The docs suggest test ids when you can't locate by role or text, and role locators come first."},{"id":"d","text":"It keeps working when an element's visible text or role changes, because it doesn't read them.","why":"The docs note the test still passes if the text or role of the element changes."},{"id":"e","text":"It reads the aria-label attribute by default.","whyNot":"The default attribute is data-testid; aria-label is not used by this locator."},{"id":"f","text":"It matches the element's visible text, so a label change breaks it.","whyNot":"Test ids don't match visible text; the docs say a test still passes when the text changes."}],"answer":"bd","explanation":"page.getByTestId() matches a dedicated test attribute, data-testid by default, so it is not tied to visible text or role, and it is not user-facing.","concept":"page.getByTestId() matches a dedicated test attribute, data-testid by default, so it is not tied to visible text or role, and it is not user-facing.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["Test ids trade user-facing meaning for stability; use them when role or text locators don't fit."]}]