arrow-left Back to topicQuizGenerating testsCheck yourself1.You're writing a test for a new 'Create order' page you've never touched before. Which is the fastest way to get the right locator for the Save button?Open DevTools, inspect the button, copy its CSS selectorRun npx playwright codegen, click the Save button — Playwright generates the locator automatically with the best strategy (role first, then text)Try getByText('Save') and see if it works2.What two windows does codegen open when you run 'npx playwright codegen'?A terminal with live code output and a browser DevTools panelA browser window to interact with the app and Playwright Inspector showing the generated codeA VS Code editor tab with the test file and a headless browser running in the backgroundTwo browser windows — one to record and one to replay the recording3.In what priority order does codegen pick locators when you click an element?CSS selector first, then XPath, then text contentRole first, then text, then test id — preferring the most stable and semantic optiondata-testid first, then aria-label, then CSS classThe locator type is chosen randomly and you must manually select a better one4.What can you record as assertions in codegen without writing code manually?Only network response assertions — codegen cannot record DOM assertionsVisibility, text content, and input value assertions — by clicking the assert toolbar button then clicking the elementOnly screenshot assertions — codegen saves a screenshot and generates a visual comparisonCodegen records actions only — assertions must always be written manually5.You need a locator for one specific element in an existing test — not a full recording. How do you use codegen for this?Record a full test, then delete all lines except the locator you needPress Stop to pause recording, then click 'Pick Locator' — hover over the element to see the recommended locator, click to copy itOpen DevTools in the codegen browser and use $0 to get the selected element's selectorPick Locator is only available in the VS Code extension, not in codegen6.When is generated code from codegen NOT ideal and requires manual editing?Always — codegen output is never production-quality and is only a starting pointWhen elements lack semantic roles or labels — codegen may fall back to fragile position-based or CSS selectorsWhen the page uses React — codegen cannot generate correct selectors for component-based UIsWhen tests run in Firefox or WebKit — codegen only works correctly with Chromium7.What is the key difference between recording a test with codegen versus writing locators manually?Codegen produces slower tests because it records extra wait stepsCodegen lets you discover the right locator by interacting with the live page instead of guessing from source code or DevToolsManual locators use getByRole while codegen always uses CSS selectorsThere is no difference — codegen just types the same code you would write manually8.How do you start codegen to record a test for a specific URL?npx playwright test --record http://localhost:3000/ordersnpx playwright codegen http://localhost:3000/ordersnpx playwright open --codegen http://localhost:3000/ordersnpx playwright generate http://localhost:3000/ordersSubmit answersarrow-left PreviousCommand lineTest generatorNext arrow-right