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

  1. Where does Cypress test code run? Junior
  2. A link opens a page in a new tab (target="_blank"). How is this tested in Cypress? Middle
  3. What is cy.origin() for? Middle
  4. 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
  5. How does cypress open differ from cypress run? Junior
  6. 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

  1. What does cy.get() return? Junior
  2. 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')
  3. Why don't you write await cy.get() in Cypress? Middle
  4. What value is passed to cy.log(total)? Middle
    let total
    cy.get('[data-cy=total]').then(($el) => {
      total = $el.text()
    })
    cy.log(total)
  5. What does the alias do in this code? Middle
    cy.get('[data-cy=submit]').as('btn');
    cy.get('@btn').click();
  6. How do you pass a plain JavaScript object into a Cypress chain to check its property with should? Middle
  7. What does this code check? Junior
    cy.get('.item').its('length').should('eq', 3);
  8. 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

  1. What is retry-ability? Junior
  2. Which commands are not retried? Middle
  3. 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')
    })
  4. What does Cypress check before click() (actionability)? Middle
  5. Why is cy.wait(3000) considered an antipattern? Junior
  6. How is should('have.text', 'Paid') different from should('contain', 'Paid')? Junior
  7. How is should('not.exist') different from should('not.be.visible')? Junior
  8. 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

  1. Which selector is the most reliable? Junior
  2. How is cy.get() different from .find()? Junior
  3. What does cy.contains('button', 'Pay') do? Middle
  4. How do you hover the mouse to show a menu that opens on mouseover? Middle
  5. How do you limit a search to elements inside a form? Middle
  6. What does the call .type('anna@example.com{enter}') do? Junior
  7. Which call picks the option with the visible text “Ukraine” in a <select> element? Junior
  8. The “I agree” checkbox is already checked. What does cy.get('#agree').check() do? Junior
  9. 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
  10. 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

  1. What is cy.intercept for? Junior
  2. What happens if you register an intercept after the click that triggers the request? Junior
  3. What kind of intercept is this? Middle
    cy.intercept('GET', '/api/products').as('getProducts')
  4. What does cy.wait('@createOrder') return? Middle
  5. How do you check that the front end sent 2 items in the order? Middle
  6. How do you check how the UI reacts to a server error during payment? Middle
  7. How do you serve a response from a fixture file? Middle
  8. How is cy.spy different from cy.stub? Middle
  9. 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

  1. What does cy.request do by default if the server returns 404? Junior
  2. How do you use the id of the created product in the next request? Middle
  3. In which property of a cy.request response is the parsed JSON body? Junior
  4. 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
  5. 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

  1. What does testIsolation (on by default) do? Junior
  2. The test fails on the first cy.get right after cy.session (testIsolation is on). The most likely cause? Middle
  3. Where is it better to reset state (for example, clearing the cart through the API): in afterEach or in beforeEach? Middle
  4. 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', () => {});
    });
  5. 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

  1. What are fixtures in Cypress? Junior
  2. What is better written as a custom command than as a utility function? Middle
  3. What is cy.task() for? Middle
  4. Why doesn't this.user work in a test with an arrow function? Middle
  5. How do you work with elements inside an iframe without plugins? Middle
  6. Where are custom commands usually declared so that they are available in all specs? Junior
  7. 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
  8. How do you add logging to the built-in cy.visit command for all tests without changing Cypress itself? Middle
  9. Where do files downloaded by the app during a test go by default? Junior
  10. 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

  1. Why set baseUrl in cypress.config? Junior
  2. What does retries: { runMode: 2, openMode: 0 } mean? Middle
  3. How do you set a timeout for one slow command? Middle
  4. What is component testing in Cypress? Middle
  5. 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
  6. Without the --posix-exit-codes flag, 3 tests fail in a cypress run. What exit code does the process return? Middle
  7. A CI step reads npm start & npx cypress run. Why is such a launch unreliable? Junior
  8. 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'
  9. What does cypress-io/github-action cache automatically in an npm project? Junior
  10. The repository has only package-lock.json. Which install command does cypress-io/github-action run by default? Middle
  11. 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
  12. How do you make Cypress keep its binary in a folder of your own, for example inside the CI workspace? Middle
  13. 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
  14. How does the official Docker image cypress/base differ from cypress/browsers? Junior
  15. What is the cypress/included image used for? Middle
  16. How do you run only the specs from the cypress/e2e/auth folder in CI? Junior
  17. How do you run the tests against the staging environment in CI without changing cypress.config in the repository? Middle
  18. Where should the test user's password needed by the tests in CI be stored? Junior
  19. 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
  20. A test failed during cypress run with the default configuration (Cypress 16). Which artifacts appear on disk? Junior
  21. 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
  22. 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

  1. 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
  2. The /reports page on the test server responds with status 500. What does cy.visit('/reports') do by default? Middle
  3. What does .and() do in this chain? Junior
    cy.get('[data-cy=status]')
      .should('be.visible')
      .and('have.text', 'Paid');
  4. The text in [data-cy=total] becomes “42” one second after the page opens. Which variant passes reliably? Middle
  5. 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
  6. What status does a test declared as it.skip('...', () => { ... }) get in the report? Junior
  7. What is cy.pause() added to a test for? Junior
  8. 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
  9. 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