IKivan-kozenko -aqa
Try yourself as a QA tester
Back to topic

Quiz

Mock browser APIs

Check yourself

  1. 1.Why must page.addInitScript() be called BEFORE page.goto()?
  2. 2.You want to test a feature that checks navigator.cookieEnabled. But navigator.cookieEnabled = false has no effect. Why, and what's the fix?
  3. 3.How do you test that a battery warning banner appears when the battery level drops below 20% mid-session (not just on initial load)?
  4. 4.What does page.exposeFunction('logCall', handler) do?
  5. 5.Your app checks navigator.getBattery() on page load. You write a mock in page.evaluate() after page.goto(). The mock doesn't take effect. Why?
  6. 6.Which scenario is a good use case for mocking browser APIs with addInitScript(), rather than using page.route()?
  7. 7.You want to verify that the app correctly subscribes to chargingchange and levelchange battery events. How do you capture which events the app actually listened for?
  8. 8.The Battery API mock returns level: 0.15 on page load. Your test asserts the warning banner is visible. But the test is flaky — sometimes the banner doesn't appear. What's the most likely cause?