[{"id":"cypressadvanced-001","courseId":"cypress-advanced","domain":"test-structure","topic":"Overwriting built-in commands","prompt":"Your team wants every plain cy.visit() in the project to add a locale parameter to the URL. Which API changes the built-in visit command itself?","hint":"Think about whether you are adding something new or changing a built-in command that Cypress itself uses.","explain":"Cypress lets you add new commands or change a built-in one. Commands and queries are separate kinds, each with its own variant. Changing a built-in affects Cypress itself.","source":"https://docs.cypress.io/api/cypress-api/custom-commands","interaction":{"type":"single"},"options":[{"id":"a","text":"Cypress.Commands.add('visit', ...)","whyNot":"add() creates a new command for your tests; it does not replace how the built-in visit works."},{"id":"b","text":"Cypress.Commands.overwriteQuery('visit', ...)","whyNot":"overwriteQuery is for queries such as get; visit is a command, so this is the wrong family."},{"id":"c","text":"Cypress.Commands.overwrite('visit', ...)","why":"overwrite replaces the built-in visit; its callback receives the original command first, and you call it with the adjusted URL."},{"id":"d","text":"A visitWithLocale() helper imported into each spec","whyNot":"A helper leaves the built-in visit untouched, so plain cy.visit() calls keep the original behaviour."}],"answer":"c","explanation":"Cypress.Commands.overwrite() replaces an existing built-in command; its callback receives the original command first so it can call it, and the change affects Cypress itself.","concept":"Cypress.Commands.overwrite() replaces an existing built-in command; its callback receives the original command first so it can call it, and the change affects Cypress itself.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["To change a built-in command, overwrite it and call the original; Cypress itself is affected too."]},{"id":"cypressadvanced-002","courseId":"cypress-advanced","domain":"test-structure","topic":"Parent, child and dual commands","prompt":"Cypress groups custom commands into parent, child and dual kinds by how they treat the subject from the previous command. Which TWO statements about these kinds are true?","hint":"Check whether the kind needs an existing subject, forbids one, or allows either.","explain":"Commands differ in whether they need a predecessor. Some ignore what came before, some require a handed-over value, and some accept both. A declared option sets which behaviour applies.","source":"https://docs.cypress.io/api/cypress-api/custom-commands","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"A parent command always starts a new chain and ignores any subject yielded before it.","why":"Parent commands such as cy.visit() begin a fresh chain, so earlier subjects are never passed in."},{"id":"b","text":"cy.wait() is a child command, so it can never start a chain of commands.","whyNot":"cy.wait() is a dual command, which can start a chain on its own."},{"id":"c","text":"A dual command can either start a chain or be chained off an existing one.","why":"Dual commands such as cy.screenshot() and cy.wait() work with or without a previous subject."},{"id":"d","text":"A child command such as .click() can be called as cy.click() to begin a chain.","whyNot":"Child commands are always chained off a parent or another child, so they cannot begin a chain."},{"id":"e","text":"A child command can start a chain whenever its function ignores the previous subject.","whyNot":"Ignoring the subject doesn't change how a child command is chained; it still needs a previous command."},{"id":"f","text":"Child commands receive the previous subject only when prevSubject is set to optional.","whyNot":"optional is the setting for dual commands; a child command uses prevSubject set to true."}],"answer":"ac","explanation":"Parent commands always start a new chain and ignore earlier subjects; child commands always chain off a previous command and receive its subject; dual commands can do either.","concept":"Parent commands always start a new chain and ignore earlier subjects; child commands always chain off a previous command and receive its subject; dual commands can do either.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["Child commands need a previous command; parent commands always start fresh; dual commands accept both."]},{"id":"cypressadvanced-003","courseId":"cypress-advanced","domain":"test-structure","topic":"cy.session validation and re-setup","prompt":"A spec calls cy.session() with a validate function. An earlier test cached the session, and now validate fails on the restored session. What does Cypress do next?","hint":"Think about what Cypress does with a cached session that no longer passes its check.","explain":"Saved browser state can be reused, but only if a check still passes on it. Consider what should happen when that check fails on state carried over from an earlier test, compared with state built moments ago.","source":"https://docs.cypress.io/api/commands/session","interaction":{"type":"single"},"options":[{"id":"a","text":"Cypress skips validate and reuses the cached session as it is.","whyNot":"validate runs on restored sessions as well, so it is not skipped."},{"id":"b","text":"Cypress re-runs the setup function to create the session again.","why":"When validation fails after a session is restored, the setup function runs again."},{"id":"c","text":"The test fails at once, because a restored session that fails validation can't be recovered.","whyNot":"The test fails straight away only when validation fails right after setup; a restored session is set up again."},{"id":"d","text":"Cypress keeps the cached session, because a failed validation only logs a warning.","whyNot":"A failed validation makes the session invalid rather than just logging a warning."}],"answer":"b","explanation":"cy.session() runs validate on a restored session; if it fails after restoring, setup re-runs, and if it fails right after setup, the test fails.","concept":"cy.session() runs validate on a restored session; if it fails after restoring, setup re-runs, and if it fails right after setup, the test fails.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["A failing validate on a restored session re-runs setup; one failing right after setup fails the test."]},{"id":"cypressadvanced-004","courseId":"cypress-advanced","domain":"test-structure","topic":"setupNodeEvents Node listeners","prompt":"In setupNodeEvents, an object returned from the function has no effect on the configuration; only editing the config file can change it.","hint":"Consider what the function can hand back to Cypress besides listeners.","explain":"Node-side code can change the settings Cypress uses. Consider what Cypress does with a value handed back from a setup function, and what it gets merged into.","source":"https://docs.cypress.io/api/node-events/overview","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","whyNot":"The function may return or resolve an object, and Cypress merges it into the config, so returned values do change settings."},{"id":"b","text":"False","why":"Returned or resolved objects are merged into the config, overwriting settings, so the statement does not hold."}],"answer":"b","explanation":"setupNodeEvents can return or resolve with an object, which Cypress merges into the config to overwrite configuration or environment variables.","concept":"setupNodeEvents can return or resolve with an object, which Cypress merges into the config to overwrite configuration or environment variables.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["setupNodeEvents can change config by returning an object, not only by registering listeners."]},{"id":"cypressadvanced-005","courseId":"cypress-advanced","domain":"test-structure","topic":"Task return value rules","prompt":"Your setupNodeEvents calls on('task', userTasks), and an installed plugin also exports a task named getUser. Both register the same name. What happens?","hint":"Think about how merging objects with a repeated key behaves, and what Cypress reports.","explain":"Several sets of named task handlers can be combined into one lookup. Think about how merging plain objects treats two entries that share a key.","source":"https://docs.cypress.io/api/commands/task","interaction":{"type":"single"},"options":[{"id":"a","text":"The later registration replaces the earlier handler for that name, and Cypress prints a warning naming it.","why":"Like merged objects with duplicate keys, the later entry overwrites the earlier one, and Cypress warns in the terminal."},{"id":"b","text":"Cypress throws an error and stops the run before any test starts.","whyNot":"A duplicate produces a warning, not a fatal error that stops the run."},{"id":"c","text":"Both handlers run in sequence, and their return values are combined.","whyNot":"Only one handler is kept for a given task name, so nothing is chained or combined."},{"id":"d","text":"The first registration wins, and the later one is silently ignored.","whyNot":"The later registration is the one kept, and Cypress prints a warning, so nothing is silent."}],"answer":"a","explanation":"Duplicate task keys: the later on('task') registration overwrites the earlier handler for that key, and Cypress prints a warning naming the duplicated task.","concept":"Duplicate task keys: the later on('task') registration overwrites the earlier handler for that key, and Cypress prints a warning naming the duplicated task.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["Duplicate task names: the later registration replaces the earlier one, and Cypress prints a warning."]}]