Top Cypress Interview Questions (2021) | CodeUsingJava
















Most frequently Asked Cypress Interview Questions


  1. What is Cypress?
  2. What is Cypress ecosystem?
  3. What are the advantages of Cypress?
  4. What is Cypress CLI?
  5. What are the features of Cypress?
  6. How can we run single specfile in Command Line?
  7. Explain Cypress Architecture?
  8. What are the components of Cypress?
  9. What browsers are supported by Cypress?
  10. What is Automation in Cypress?
  11. What is Cypress run?
  12. How can we access shadow DOM in Cypress?
  13. How can we verify title of the page in Cypress?
  14. How do we press keyboard keys in Cypress?
  15. How can we create custom commands in Cypress?
  16. How can we change the baseUrl in Cypress dynamically?

What is Cypress?

Cypress is a test automation tool that is used for creating Automated Tests in our application. Cypress helps by working in the same area where tools such as Selenium works, it uses real browsers by allowing the developers to create a higher quality of tests. It also can take screenshots and videos by using Testing Process which makes it easier to debug errors within the tests.

What is Cypress ecosystem?

Cypress contains free, open-source, installed Test Runner and Dashboard Services used for recording our tests.
Cypress also helps us to set up and write tests while building our application locally. Cypress works with our CI Provider, Dashboard Service that can record our test runs.

What are the advantages of Cypress?

  • Cypress works with Single Page Applications and internal Ajax Calls.
  • Cypress can take snapshots of tests after executing each step.We don't need to have configuration with cypress.
  • Cypress can provide access to the developer tools so they can debug directly into the browser.
  • Cypress can run tests and also execute commands on the browser.
  • Cypress can execute commands easily and fast than Selenium based tools.

What is Cypress CLI?

Cypress CLI helps in providing the ability for running our cypress tests in Command-Line. It is a feature that is used to run our cypress tests in Pipelines. It also provides Options and Flags Control of the cypress Test Behavior.

What are the features of Cypress?

  • Time Travel - Cypress is used to take snapshots as our tests runs.
  • Debuggability - Cypress stops guessing why our tests are failing.It can debug tools such as Developer Tools.
  • Automatic Waiting - Cypress will not wait or add to our tests and wait for commands and assertions before moving on.
  • Screenshots and Videos - Cypress is used in viewing screenshots that are taken automatically on the failure of our entire test suite while running from CLI.

How can we run single specfile in Command Line?

We can run Single Specifile by using the spec option and also using the following command:
npm cypress run - - spec="my spec.ts""


Explain Cypress Architecture?

Cypress
  • Testing Tools like Selenium helps by operating the browser and also executing remote commands all over the network. Cypress Engine helps operating inside the Browser.
  • Cypress allows to Listen and Modify the browser behavior at the run time by manipulating and altering Network requests and all responses on the Fly.
  • It also opens doors for testing new kind of ultimate controlling over our application.

What are the components of Cypress?

Cypress
Test Runner helps in testing in an interactive runner which helps by allowing us to see command and execute while viewing the application under the test.
Test Status helps in showing us a summary of what tests Passed, Failed, or in Progress.
URL Preview helps in showing us the URL of our test and also helps in tracking the URL Route.
Viewport Sizing helps in setting our app viewport size for testing layouts.
Command Log helps in showing us the command logs while executing the tests.
App Preview helps in seeing the the tests while executing the commands.

What browsers are supported by Cypress?

Cypress

What is Automation in Cypress?

Cypress Automation is a process to run a Test Code with the application. The test cannot be executed in a single loop and it also happens in the Single Browser.
Node.js Server is used in the tasks which can happen outside.

What is Cypress run?

Cypress Run helps in executing our cypress tests in Headless Browsers. It helps in opening a New Browser Tab and in loading Cypress at the URL Cypress which was installed from it. Cypress helps in detecting cypress.json, it also runs cypress tests in the webpack monitor.

How can we access shadow DOM in Cypress?

Shadow DOM helps in allowing hidden DOM Trees which needs to be attached to the elements in the regular DOM Tree.Shadow DOM can be understood by the following command:
cy.get('#locator').shadow().find('.nb-btn').click()


How can we verify title of the page in Cypress?

We can verify the title of the pages by using the following command:
cy.title().should('eq','My Site Title')


How do we press keyboard keys in Cypress?

We can press keyboard keys by using the following command:
cy.get('#locator').type('{shift}{alt}'));



How can we create custom commands in Cypress?

We can create custom commands by using the following command:
Cypress.Commands.add("login", (username, password) => {
  cy.get("#username").type(username);
  cy.get("#password").type(password);
  cy.get("#login").click();
});


How can we change the baseUrl in Cypress dynamically?

We can change the baseUrl in Cypress dynamically by using the CLI Command:
npx cypress run --config baseUrl="