Knowledge check
Nine questions on the decisions that matter most in a real Cypress suite. Each answer comes with a short explanation, so a wrong answer points you back to the right chapter.
1. A test clicks "Load more" and then runs cy.wait(3000) before checking that 20 rows exist. It is slow and still fails now and then. What is the better version?
The assertion retries until the rows are there and finishes as soon as they are. A longer sleep is slower and still a guess; .then() checks once and does not retry.
2. A spec has const rows = cy.get('tbody tr') followed by if (rows.length > 0) { ... }. The branch never runs. Why?
No command has run when that line executes. Values from the page are only available in callbacks such as .then() or .should(), and awaiting a chainer does not work either.
3. Which selector is least likely to break when the design team restyles the checkout page?
A dedicated test attribute has one job and does not change with styling or layout. Classes and structural paths change whenever the markup does.
4. You want to test how the orders page looks when the API returns an empty list. The real test account has 40 orders. What is the cleanest approach?
Stubbing the response gives you the exact state you want, instantly and without changing data. Register the intercept before the visit so the page's request is caught.
5. Every test in a 150-test suite logs in through the form, and the suite takes 25 minutes. What change helps most?
cy.session logs in once and restores the cookies and storage for each later test, while keeping tests isolated. Disabling isolation lets other state leak between tests too, and with isolation on, a before hook's login is cleared before the second test.
6. The same specs must run against localhost on laptops and against staging in CI. How should the URL be chosen?
With relative paths, one setting decides where the whole suite points, and the specs never mention a host.
7. A test passes only on its second attempt in most CI runs. Retries keep the pipeline green. What should you do?
A regular pass-on-retry is a bug report. In chapter 9 the cause was a real defect in the application (duplicate ids), which retries had been hiding.
8. You run testingbot-cypress run and nothing in your component tests runs on the grid. Why?
The grid runs your end-to-end specs. Component tests need your framework's dev server and stay on your machine or CI runner.
9. In GitHub Actions, the login spec passes on TestingBot from a laptop but fails from CI with an empty username. cypress.env.json is in .gitignore. What is the fix?
On a laptop the CLI uploads cypress.env.json with the project; in CI the file does not exist. --env sets Cypress environment variables on the remote run without putting secrets in the repository.
You finished Cypress Tutorial: First Spec to CI
Put what you learned into practice. Run your tests on 6100+ real browsers and physical iOS and Android devices.