Cypress Automation Interview Questions

Modern JavaScript testing framework questions and best practices

Showing 141 of 141 questions

Q1: What is Cypress?

Answer: A modern JavaScript-based end-to-end testing framework for web applications.

Q2: Who created Cypress?

Answer: Cypress.io.

Q3: Is Cypress open-source?

Answer: Yes, the test runner is open-source. Cypress Dashboard is a paid SaaS.

Q4: Which language is supported in Cypress?

Answer: JavaScript (with TypeScript support).

Q5: Does Cypress use Selenium/WebDriver?

Answer: No. Cypress runs inside the browser, unlike Selenium.

Q6: Can Cypress test both frontend and backend?

Answer: Yes. It supports UI testing and API testing.

Q7: Where does Cypress run?

Answer: Inside the browser + Node.js process.

Q8: What is Cypress Test Runner?

Answer: A GUI that shows tests running in real time.

Q9: What is the default Cypress folder structure?

Answer: cypress/fixtures, cypress/e2e, cypress/support, cypress/plugins.

Q10: What is cypress.config.js?

Answer: The configuration file to set baseUrl, timeouts, reporter, etc.

Q11: How do you install Cypress?

Answer: npm install cypress --save-dev.

Q12: How to open Cypress Test Runner?

Answer: npx cypress open.

Q13: How to run Cypress in headless mode?

Answer: npx cypress run.

Q14: Which browsers are supported?

Answer: Chrome, Edge, Firefox, Electron, WebKit (experimental).

Q15: Does Cypress support Safari?

Answer: Not directly. Only WebKit experimental support.

Q16: Which test frameworks are used in Cypress?

Answer: Mocha (test runner), Chai (assertions), Sinon (spies/stubs).

Q17: What's the default test file extension in Cypress?

Answer: .cy.js or .cy.ts.

Q18: How to run a specific test file?

Answer: npx cypress run --spec 'cypress/e2e/test.cy.js'.

Q19: How to run tests in a specific browser?

Answer: npx cypress run --browser chrome.

Q20: Can Cypress be used for mobile app testing?

Answer: No, only for web apps in browsers.

Q21: Does Cypress support TypeScript?

Answer: Yes, with built-in support.

Q22: How is Cypress different from Playwright?

Answer: Cypress is JS-only, simpler. Playwright supports multiple languages and browsers.

Q23: What is Cypress Dashboard?

Answer: A cloud service for recording test results and parallelization.

Q24: Can Cypress be used in CI/CD pipelines?

Answer: Yes, with GitHub Actions, GitLab, Jenkins, CircleCI, etc.

Q25: Is Cypress synchronous or asynchronous?

Answer: Cypress commands are asynchronous but appear synchronous due to command queue.

Q26: What's the difference between cy.get() and cy.contains()?

Answer: cy.get() finds elements by selector, cy.contains() finds by visible text.

Q27: What's the difference between cy.get() and cy.find()?

Answer: cy.get() searches from the document root, cy.find() searches inside a located element.

Q28: How to type into an input field?

Answer: cy.get('input[name="username"]').type('admin').

Q29: How to clear an input field?

Answer: cy.get('input').clear().

Q30: How to click a button?

Answer: cy.get('button').click().

Q31: How to force click an invisible element?

Answer: cy.get('button').click({ force: true }).

Q32: How to double-click?

Answer: cy.get('#id').dblclick().

Q33: How to right-click?

Answer: cy.get('#id').rightclick().

Q34: How to hover on element?

Answer: cy.get('#id').trigger('mouseover').

Q35: How to check a checkbox?

Answer: cy.get('input[type="checkbox"]').check().

Q36: How to uncheck a checkbox?

Answer: cy.get('input[type="checkbox"]').uncheck().

Q37: How to select from a dropdown?

Answer: cy.get('select').select('Option1').

Q38: How to assert element visibility?

Answer: cy.get('#id').should('be.visible').

Q39: How to assert element is hidden?

Answer: cy.get('#id').should('not.be.visible').

Q40: How to assert element text?

Answer: cy.get('h1').should('have.text', 'Welcome').

Q41: How to assert partial text?

Answer: cy.get('h1').should('contain.text', 'Welc').

Q42: How to check CSS property?

Answer: cy.get('h1').should('have.css', 'color', 'rgb(0, 0, 0)').

Q43: How to check element attribute?

Answer: cy.get('img').should('have.attr', 'src').

Q44: How to assert number of elements?

Answer: cy.get('li').should('have.length', 5).

Q45: How to alias an element?

Answer: cy.get('#username').as('user'); cy.get('@user').type('admin').

Q46: Difference between should() and then()?

Answer: should() retries until assertion passes, then() executes once when element is available.

Q47: How to wrap a JS object in Cypress chain?

Answer: cy.wrap({ foo: 'bar' }).its('foo').should('eq', 'bar').

Q48: How to pause test execution?

Answer: cy.pause().

Q49: How to debug a Cypress test?

Answer: cy.get('#id').debug() or browser dev tools.

Q50: How to reload a page?

Answer: cy.reload().

Q51: How to navigate back/forward?

Answer: cy.go('back'), cy.go('forward').

Q52: How to wait explicitly for time?

Answer: cy.wait(5000).

Q53: How to wait for an alias?

Answer: cy.wait('@getUsers').

Q54: How to handle alerts?

Answer: cy.on('window:alert', (msg) => { expect(msg).to.equal('Hello'); });

Q55: How to handle confirm dialog?

Answer: cy.on('window:confirm', () => true);

Q56: How to stub a confirm dialog to cancel?

Answer: cy.on('window:confirm', () => false).

Q57: How to scroll into view?

Answer: cy.get('#footer').scrollIntoView().

Q58: How to take a screenshot?

Answer: cy.screenshot('homepage').

Q59: How to record video of tests?

Answer: By default with cypress run (headless mode).

Q60: How to assert URL contains a value?

Answer: cy.url().should('include', '/dashboard').

Q61: What are fixtures in Cypress?

Answer: Fixtures are external static files (usually JSON) used to store test data.

Q62: Where are fixtures stored?

Answer: By default in the cypress/fixtures folder.

Q63: How do you load a fixture in a test?

Answer: cy.fixture('user.json').then((user) => { cy.get('#username').type(user.name); });

Q64: How do you alias a fixture?

Answer: cy.fixture('user.json').as('userData'); cy.get('@userData').then((user) => { cy.log(user.name); });

Q65: Can fixtures contain arrays and objects?

Answer: Yes, fixtures can contain any valid JSON (arrays, nested objects, strings, numbers).

Q66: How to use fixture with API stubbing?

Answer: cy.intercept('GET', '/users', { fixture: 'users.json' });

Q67: How to handle test data that changes frequently?

Answer: Use beforeEach hooks with dynamic data generation instead of static fixtures.

Q68: How to generate random test data in Cypress?

Answer: Use libraries like faker.js or chance.js.

Q69: How to share data between tests?

Answer: Use aliases, environment variables, or cy.wrap().

Q70: How to write to a file in Cypress?

Answer: cy.writeFile('cypress/fixtures/data.json', { name: 'Rakshit' });

Q71: How to read from a file in Cypress?

Answer: cy.readFile('cypress/fixtures/data.json').then((data) => { expect(data.name).to.equal('Rakshit'); });

Q72: How to preserve cookies across tests?

Answer: In beforeEach: Cypress.Cookies.preserveOnce('session_id');

Q73: How to access environment variables in Cypress?

Answer: Cypress.env('varName').

Q74: Where do you define environment variables?

Answer: In cypress.config.js, CLI, or cypress.env.json.

Q75: How to pass env variables via CLI?

Answer: npx cypress run --env username=admin,password=123

Q76: How to use custom configuration per test?

Answer: Use Cypress.config('defaultCommandTimeout', 10000) inside a test.

Q77: How to create global reusable test data?

Answer: Put it in fixtures or cypress/support/commands.js.

Q78: How to parameterize tests in Cypress?

Answer: Use forEach() loops or plugins like cypress-each.

Q79: Can fixtures be used with TypeScript?

Answer: Yes, Cypress provides type definitions for fixtures.

Q80: When should you avoid using fixtures?

Answer: When test data changes frequently or needs to be unique (better to generate dynamically).

Q81: What is Cypress command queue?

Answer: Cypress queues commands and executes them serially in the order they appear, unlike Promises which run immediately.

Q82: What is the difference between Cypress commands and Promises?

Answer: Cypress commands are enqueued and retried automatically, Promises are not.

Q83: What is a custom command in Cypress?

Answer: A reusable command you define in cypress/support/commands.js. Example: Cypress.Commands.add('login', (user, pass) => { cy.get('#user').type(user); cy.get('#pass').type(pass); cy.get('form').submit(); });

Q84: How do you overwrite a Cypress command?

Answer: Using Cypress.Commands.overwrite(). Example: Cypress.Commands.overwrite('visit', (originalFn, url, options) => { return originalFn(url, { timeout: 10000 }); });

Q85: What is Cypress Dashboard used for?

Answer: A cloud service for recording test runs, debugging, running in parallel, and test analytics.

Q86: Can Cypress tests run in parallel?

Answer: Yes, using Cypress Dashboard and the --parallel flag.

Q87: What is the use of cy.intercept()?

Answer: To stub, spy, or intercept network requests. Example: cy.intercept('GET', '/users', { fixture: 'users.json' }).as('getUsers'); cy.visit('/dashboard'); cy.wait('@getUsers');

Q88: Difference between cy.request() and cy.intercept()?

Answer: cy.request() makes actual HTTP requests, cy.intercept() spies/stubs requests from the app.

Q89: How to handle authentication in Cypress?

Answer: By setting tokens in localStorage/cookies or calling login API with cy.request().

Q90: How to handle file uploads?

Answer: Using cypress-file-upload plugin: cy.get('input[type=file]').attachFile('file.pdf');

Q91: How to handle file downloads?

Answer: Use cy.readFile() to check downloaded file content, or plugins like cypress-downloadfile.

Q92: Can Cypress handle iframes?

Answer: Yes, but indirectly. Use .its('0.contentDocument') or cypress-iframe plugin.

Q93: How to switch between tabs in Cypress?

Answer: Cypress doesn't support multiple tabs. Workarounds: stub target=_blank, or directly visit the new URL.

Q94: How do you make a GET request in Cypress?

Answer: cy.request('GET', '/api/users').then((res) => { expect(res.status).to.eq(200) })

Q95: How do you make a POST request with JSON body?

Answer: cy.request({ method: 'POST', url: '/api/users', body: { name: 'Rakshit', role: 'Tester' } }).then((res) => { expect(res.status).to.eq(201) })

Q96: How do you pass headers in an API request?

Answer: cy.request({ method: 'GET', url: '/api/data', headers: { Authorization: `Bearer ${token}` } })

Q97: How do you validate response body properties?

Answer: cy.request('/api/users').its('body').should('have.property', 'id')

Q98: How do you handle Bearer Token authentication in Cypress?

Answer: Store token in Cypress.env() and pass it in headers.

Q99: Can Cypress store tokens across multiple API tests?

Answer: Yes, use before() or Cypress.env() to store and reuse tokens.

Q100: How would you test login APIs in Cypress?

Answer: Send a cy.request('POST', '/login', {username, password}) and assert status/token.

Q101: How do you refresh tokens automatically in Cypress tests?

Answer: Use cy.request() inside beforeEach() hook to generate a fresh token.

Q102: Can Cypress test OAuth 2.0 APIs?

Answer: Yes, by handling redirects or generating tokens via API requests.

Q103: How do you assert response status code?

Answer: cy.request('/api/users').then((res) => { expect(res.status).to.eq(200) })

Q104: How do you check a specific value in response JSON?

Answer: cy.request('/api/users/1').its('body.name').should('eq', 'Rakshit')

Q105: How do you check response time in Cypress?

Answer: Cypress doesn't provide direct response time, but you can measure with Date.now() before/after request.

Q106: How do you validate an array in the response?

Answer: cy.request('/api/users').its('body').should('be.an', 'array')

Q107: Can Cypress validate API response schema?

Answer: Not built-in. You can use plugins like cypress-ajv-schema-validator.

Q108: How do you mock an API response with Cypress?

Answer: cy.intercept('GET', '/api/users', { fixture: 'users.json' })

Q109: How do you wait for a mocked API call before asserting?

Answer: cy.intercept('GET', '/api/users').as('getUsers'); cy.visit('/'); cy.wait('@getUsers')

Q110: Can Cypress modify live API responses during tests?

Answer: Yes, using cy.intercept() with a function callback to manipulate response.

Q111: How do you simulate API failure in Cypress?

Answer: cy.intercept('GET', '/api/users', { statusCode: 500 })

Q112: How do you chain multiple API calls?

Answer: cy.request('POST', '/api/users', {name: 'Rakshit'}).then((res) => { cy.request('GET', `/api/users/${res.body.id}`) })

Q113: How do you handle dynamic data between API calls?

Answer: Store data in an alias or Cypress environment variable.

Q114: How do you perform data-driven API testing in Cypress?

Answer: Load test data from fixtures or JSON and loop with forEach.

Q115: How do you test file upload APIs in Cypress?

Answer: Use cy.fixture('file.pdf', 'binary') + pass binary data in cy.request() body.

Q116: Can Cypress API tests be run independently of UI tests?

Answer: Yes, Cypress tests are JavaScript-based and can run standalone in headless mode.

Q117: How do you integrate API tests into CI/CD with Cypress?

Answer: Run headless tests: npx cypress run --spec 'cypress/e2e/api-tests/*'

Q118: How do you generate API test reports in Cypress?

Answer: Use cypress-mochawesome-reporter or cypress-json-to-html-reporter.

Q119: How do you run only API tests, not UI tests?

Answer: Organize API specs in a separate folder and target it with --spec.

Q120: How do you parallelize Cypress API tests in GitLab/Jenkins?

Answer: Split API spec files and run them on multiple runners using Cypress Dashboard or CI matrix.

Q121: How do you ensure data cleanup after API tests?

Answer: Use after() hooks to delete created data with cy.request() calls.

Q122: What is a Cypress testing framework?

Answer: A structured setup where you organize tests, page objects, custom commands, fixtures, utilities, plugins, and reporting to make your Cypress tests maintainable, scalable, and reusable.

Q123: How do you structure a Cypress framework?

Answer: Common structure: cypress/e2e/ (test cases), fixtures/ (test data), support/ (custom commands), plugins/ (extend functionality), pages/ (POM files), reports/ (test reports), cypress.config.js (configuration)

Q124: What is the role of cypress/support in a framework?

Answer: commands.js → add reusable custom commands, e2e.js → global hooks like before(), after(), or test setup logic. Ensures reusability and centralizes common setup logic.

Q125: Why use the Page Object Model (POM) in Cypress?

Answer: Separates test logic from UI locators, increases maintainability, improves reusability across tests, makes test scripts cleaner and more readable.

Q126: How do you implement Page Object Model in Cypress?

Answer: Create a page class file with locators and methods, then import and use in tests. Example: class LoginPage { login(username, password) { cy.get('#username').type(username); } }

Q127: How do you manage test data in a Cypress framework?

Answer: Using cypress/fixtures JSON files, environment variables (Cypress.env), dynamic test data via utilities, Faker.js or Chance.js for random data.

Q128: How do you handle multiple environments (Dev, QA, Prod) in Cypress?

Answer: Define separate cypress.config.{env}.js files, use Cypress.env('baseUrl'), example: npx cypress run --config baseUrl=https://qa.myapp.com

Q129: How do you add reporting to a Cypress framework?

Answer: Use cypress-mochawesome-reporter for HTML reports, integrate with JUnit for CI/CD pipelines, combine with Allure Reports for detailed analysis.

Q130: How do you integrate Cypress framework with CI/CD?

Answer: Add Cypress run command to CI pipeline (GitHub Actions, GitLab, Jenkins), use Dockerized Cypress image for consistency, store reports & screenshots as pipeline artifacts.

Q131: What is the role of Cypress plugins in framework design?

Answer: Extend Cypress with additional functionality like file upload, database connection, API stubbing. Defined in cypress/plugins/index.js (v9) or cypress.config.js (v10+).

Q132: How do you manage reusable functions in a Cypress framework?

Answer: Use support/commands.js for Cypress commands, use utils/ folder for helper functions (e.g., date formatter, API utility).

Q133: What design patterns can be applied in Cypress framework?

Answer: Page Object Model (POM), Data-driven testing (fixtures), Custom Commands pattern, Service Layer abstraction for APIs, Modular test design.

Q134: How do you implement retries in a Cypress framework?

Answer: Use built-in retry mechanism for commands/assertions or use cypress-retries plugin: retries: { runMode: 2, openMode: 1 }

Q135: How do you parameterize tests in a Cypress framework?

Answer: Use fixtures for external data, use it.each() pattern (via cypress-each plugin), or loop over datasets with forEach in the test file.

Q136: How do you scale Cypress tests for large projects?

Answer: Use POM for UI tests, use service layer testing for APIs, parallel test execution in CI/CD, reduce test data dependencies, split tests into smaller suites.

Q137: How do you maintain consistency in locators across Cypress framework?

Answer: Use data-testid or data-cy attributes, store locators in Page Objects or a central locators.js file, avoid brittle locators like XPath with indexes.

Q138: How do you add video recording and screenshots in Cypress framework?

Answer: Enabled by default in cypress run mode. Configurable in cypress.config.js: video: true, screenshotOnRunFailure: true

Q139: How do you organize test suites in a Cypress framework?

Answer: Group by feature/module (cypress/e2e/auth, cypress/e2e/cart), tag tests using it.only or plugins like cypress-grep, use describe blocks to structure scenarios.

Q140: What is a custom command in Cypress framework?

Answer: A reusable command added in commands.js file: Cypress.Commands.add('login', (user, pass) => { cy.get('#username').type(user); cy.get('#password').type(pass); cy.get('#loginBtn').click(); });

Q141: How do you implement API layer testing in a Cypress framework?

Answer: Create services/ folder with reusable API request functions. Example: class UserService { createUser(user) { return cy.request('POST', '/api/users', user); } }