Skip to main content

Quiz: Building a test framework

Why This Matters

A quick check that this module’s ideas hold up before you move on. Answer each question yourself before you open the answer.

Quiz

1. A test passed on its second attempt. What does Playwright report and what should you do?

  • A. Passed; nothing to do
  • B. Flaky; find the cause, because retries only hide it
  • C. Failed; delete the test
  • D. Skipped; rerun the pipeline
Show answer
B. Playwright marks it flaky. The retry kept the build green, but the cause is still there.
Quiz

2. Where does an assertion about behaviour belong?

  • A. Inside the page object
  • B. In the test, so the reader sees what is checked
  • C. In a fixture
  • D. In the config
Show answer
B. Thin page objects expose actions and locators. The test states what it expects. A page object may wait for a step to complete (the cart dialog to open), which is part of doing, not checking.
Quiz

3. What runs after await use(value) in a fixture?

  • A. Nothing; use ends the fixture
  • B. The teardown, after the test, also when the test failed
  • C. The next test
  • D. The fixture’s setup again
Show answer
B. use hands the value to the test and waits for it to finish. Cleanup after use runs whatever happened in the test, which is why cleanup belongs there and not at the end of the test body.
Quiz

4. Which data is safe to put in a worker-scoped fixture?

  • A. A cart that tests add products to
  • B. A logged-in user whose settings tests change
  • C. The product catalogue, which no test changes
  • D. The current order
Show answer
C. Worker fixtures are shared by every test in a worker. Only read-only data is safe; anything a test changes leaks into the next test.
Quiz

5. Two tests pass alone and fail now and then when run together with four workers. Most likely cause?

  • A. The browser is unstable
  • B. The tests share data, such as one cart or one user
  • C. Four workers is too many
  • D. The tests need more retries
Show answer
B. Passing alone and failing together is the signature of shared data. Give each test its own data (a sandbox, a unique user) instead of reducing workers or adding retries.
Quiz

6. A login test types the username, but the form says “Username is required.” It only happens on slow machines. Most likely cause?

  • A. A bug in Playwright’s fill
  • B. The test typed before the front-end framework had hydrated the form
  • C. The username is wrong
  • D. The test needs waitForTimeout(2000)
Show answer
B. In React, Vue or Next.js apps the HTML can appear before the framework is attached. Typing into it then does not reach the app’s state. Wait for a sign the app is ready, or repeat the interaction with toPass until the form responds as expected, with a comment saying why.
Quiz

7. What does npm run test:smoke give you that the full suite does not?

  • A. Better coverage
  • B. A fast check of the main paths before you push
  • C. Visual tests
  • D. Retries
Show answer
B. Five tagged tests in about three and a half seconds. The full suite still runs in CI; the smoke set is for the quick check on your own machine.
Quiz

8. Several pages show the same header navigation. How do you model it?

  • A. A BasePage with navigation methods that every page extends
  • B. A SiteNav component that pages have, scoped to the “Main navigation” landmark
  • C. Copy the navigation locators into every page object
  • D. A global variable with the link selectors
Show answer
B. Composition: a page that has the navigation gets a SiteNav, a page without it does not. A BasePage grows into a class every page inherits everything from. The scoping matters too: the footer has links with the same names.
Quiz

9. A test creates shop.product("Smartphone Stand") while the Smartphone Stand is not on the current page yet, then sorts by price and asserts on the card. Does that work?

  • A. No, the constructor throws because the card does not exist
  • B. Only with await in the constructor
  • C. Yes: locators are lazy and are resolved when an action or assertion uses them
  • D. Only if the test reloads the page first
Show answer
C. A locator is a description, not a search. That is why component objects can build all their locators in the constructor, and why they stay valid when the page re-renders.