QA Interview Hub · Knowledge base · Quizzes · Українська
All topics
Cypress interview questions
92 questions on Cypress, from the basics to the hard ones. Answers and explanations are in the quiz and the knowledge base.
By level: Junior QA interview questions · Middle QA interview questions · Senior QA interview questions
Basics and architecture
- Where does Cypress test code run? Junior
- A link opens a page in a new tab (target="_blank"). How is this tested in Cypress? Middle
- What is cy.origin() for? Middle
- The file cypress/e2e/login.js with tests sits in a project with the default specPattern, but cypress open does not list it among the specs. What is the most likely cause? Junior
- How does cypress open differ from cypress run? Junior
- In which language are Cypress tests written? Junior
Take the quiz for this chapter · Read the explanation in the knowledge base
Command queue and asynchrony
- What does cy.get() return? Junior
- In what order will the logs appear in the console? Junior
cy.visit('/login')
console.log('A')
cy.get('h1').then(() => console.log('B'))
console.log('C')
- Why don't you write await cy.get() in Cypress? Middle
- What value is passed to cy.log(total)? Middle
let total
cy.get('[data-cy=total]').then(($el) => {
total = $el.text()
})
cy.log(total)
- What does the alias do in this code? Middle
cy.get('[data-cy=submit]').as('btn');
cy.get('@btn').click();
- How do you pass a plain JavaScript object into a Cypress chain to check its property with should? Middle
- What does this code check? Junior
cy.get('.item').its('length').should('eq', 3);
- How do you run a check for every element of the list returned by cy.get('li')? Junior
Take the quiz for this chapter · Read the explanation in the knowledge base
Retry-ability, waiting, timeouts
- What is retry-ability? Junior
- Which commands are not retried? Middle
- The status changes to 'Paid' one second after the page loads. What happens to the test? Middle
cy.get('[data-cy=status]').then(($el) => {
expect($el.text()).to.eq('Paid')
})
- What does Cypress check before click() (actionability)? Middle
- Why is cy.wait(3000) considered an antipattern? Junior
- How is
should('have.text', 'Paid') different from should('contain', 'Paid')? Junior - How is
should('not.exist') different from should('not.be.visible')? Junior - How do you get an element's text for a later comparison? Middle
Take the quiz for this chapter · Read the explanation in the knowledge base
Locators and working with the DOM
- Which selector is the most reliable? Junior
- How is cy.get() different from .find()? Junior
- What does cy.contains('button', 'Pay') do? Middle
- How do you hover the mouse to show a menu that opens on mouseover? Middle
- How do you limit a search to elements inside a form? Middle
- What does the call .type('anna@example.com{enter}') do? Junior
- Which call picks the option with the visible text “Ukraine” in a <select> element? Junior
- The “I agree” checkbox is already checked. What does cy.get('#agree').check() do? Junior
- The Delete button is nested in a <tr> through several levels of tags, and the depth may change. Which command goes up from the button to its row? Middle
- How do you check that the #email input currently holds anna@example.com in a way that is retried? Middle
Take the quiz for this chapter · Read the explanation in the knowledge base
Network: cy.intercept
- What is cy.intercept for? Junior
- What happens if you register an intercept after the click that triggers the request? Junior
- What kind of intercept is this? Middle
cy.intercept('GET', '/api/products').as('getProducts')
- What does cy.wait('@createOrder') return? Middle
- How do you check that the front end sent 2 items in the order? Middle
- How do you check how the UI reacts to a server error during payment? Middle
- How do you serve a response from a fixture file? Middle
- How is
cy.spy different from cy.stub? Middle - The app throws an uncaught error from a third-party script, and the test fails. How do you turn this off only for the known error? Middle
Take the quiz for this chapter · Read the explanation in the knowledge base
API testing
- What does cy.request do by default if the server returns 404? Junior
- How do you use the id of the created product in the next request? Middle
- In which property of a cy.request response is the parsed JSON body? Junior
- A test calls cy.request('POST', '/api/login', credentials) and then cy.visit('/profile'). The login response sets a session cookie through Set-Cookie. Why does the profile page open as logged in? Middle
- An app on localhost:3000 calls an API on another domain without CORS headers, and the browser fetch is blocked. Why does cy.request to the same API work in a test? Middle
Take the quiz for this chapter · Read the explanation in the knowledge base
State, sessions, isolation
- What does testIsolation (on by default) do? Junior
- The test fails on the first cy.get right after cy.session (testIsolation is on). The most likely cause? Middle
- Where is it better to reset state (for example, clearing the cart through the API): in afterEach or in beforeEach? Middle
- How many times does each hook run in this describe? Junior
describe('Cart', () => {
before(() => { cy.log('A'); });
beforeEach(() => { cy.log('B'); });
it('first', () => {});
it('second', () => {});
it('third', () => {});
});
- In what order does the code run for the test “T”? Middle
describe('outer', () => {
beforeEach(() => { cy.log('outer'); });
describe('inner', () => {
beforeEach(() => { cy.log('inner'); });
it('T', () => { cy.log('T'); });
});
});
Take the quiz for this chapter · Read the explanation in the knowledge base
Framework architecture
- What are fixtures in Cypress? Junior
- What is better written as a custom command than as a utility function? Middle
- What is cy.task() for? Middle
- Why doesn't
this.user work in a test with an arrow function? Middle - How do you work with elements inside an iframe without plugins? Middle
- Where are custom commands usually declared so that they are available in all specs? Junior
- How do you declare a custom command that works only in a chain after cy.get and receives the found element as its subject? Middle
- How do you add logging to the built-in cy.visit command for all tests without changing Cypress itself? Middle
- Where do files downloaded by the app during a test go by default? Junior
- The environment variable CYPRESS_api_server=https://stage.example.com is set in CI. Which key do you pass to cy.env() to read this value in a test? Middle
Take the quiz for this chapter · Read the explanation in the knowledge base
CI, parallelization, reports
- Why set baseUrl in cypress.config? Junior
- What does retries: { runMode: 2, openMode: 0 } mean? Middle
- How do you set a timeout for one slow command? Middle
- What is component testing in Cypress? Middle
- In CI the tests are started with npx cypress run, with no --browser and no defaultBrowser in the config (Cypress 16). In which browser do they run? Junior
- Without the --posix-exit-codes flag, 3 tests fail in a cypress run. What exit code does the process return? Middle
- A CI step reads npm start & npx cypress run. Why is such a launch unreliable? Junior
- A cypress-io/github-action step sets start: npm start and wait-on: 'http://localhost:3000'. What does the action do between starting the server and the tests? Middle
- uses: cypress-io/github-action@v7
with:
start: npm start
wait-on: 'http://localhost:3000'
- What does cypress-io/github-action cache automatically in an npm project? Junior
- The repository has only package-lock.json. Which install command does cypress-io/github-action run by default? Middle
- Cypress downloads its binary separately from the npm package. Which folder do you cache in CI on Linux to avoid downloading it in every run? Junior
- How do you make Cypress keep its binary in a folder of your own, for example inside the CI workspace? Middle
- The pipeline runs npm ci --ignore-scripts, so the Cypress postinstall hook does not run and cypress run says the binary is not installed. How do you fix this without removing the flag? Middle
- How does the official Docker image cypress/base differ from cypress/browsers? Junior
- What is the cypress/included image used for? Middle
- How do you run only the specs from the cypress/e2e/auth folder in CI? Junior
- How do you run the tests against the staging environment in CI without changing cypress.config in the repository? Middle
- Where should the test user's password needed by the tests in CI be stored? Junior
- The upload-artifact step comes right after the cypress run step and has no if field. The tests failed. What happens to the screenshot upload step? Junior
- uses: cypress-io/github-action@v7
- uses: actions/upload-artifact@v7
with:
name: screenshots
path: cypress/screenshots
- A test failed during cypress run with the default configuration (Cypress 16). Which artifacts appear on disk? Junior
- reporter: 'junit' is set with mochaFile: 'results/out.xml'. After a run of several specs the file shows the results of the last one only. What should be changed? Middle
- Three jobs in a CI matrix run npx cypress run --parallel without --record. What happens? Middle
Take the quiz for this chapter · Read the explanation in the knowledge base
Extra questions from common lists
- After a click the app navigates to /search?q=cypress&page=2. How do you check only the page parameter without comparing the whole URL? Junior
- The /reports page on the test server responds with status 500. What does cy.visit('/reports') do by default? Middle
- What does .and() do in this chain? Junior
cy.get('[data-cy=status]')
.should('be.visible')
.and('have.text', 'Paid');
- The text in [data-cy=total] becomes “42” one second after the page opens. Which variant passes reliably? Middle
- In a spec with five tests one was left as it.only(...) and merged. What happens in CI to this file, and what to the other specs? Middle
- What status does a test declared as it.skip('...', () => { ... }) get in the report? Junior
- What is cy.pause() added to a test for? Junior
- A test fails on a step after cy.get('[data-cy=total]'). How do you stop at that place and see in DevTools what get actually found? Middle
- A task named log that calls console.log in Node is registered in setupNodeEvents. How do you print a message from a test to the terminal during cypress run? Middle
Take the quiz for this chapter · Read the explanation in the knowledge base