- dependencies
- cypress version
- commands to run cypress test
- cypress:open : "cypress open"
- plugins
- mochawesome
- project name
- project version
Display a message to the user with an OK button. The user must click OK to dismiss the alert
Here is the way to verify that the alert is clicked
Display a message to the user with the OK and Cancel buttons. The user can choose to confirm or cancel the action.
Here is the way to verify that the Cancel is clicked
cy.on('window:confirm', (text) => {
expect(text).to.contains('Would you like to confirm?');
return false;
});
Here is the way to verify that the Ok is clicked
cy.on('window:confirm', (text) => {
expect(text).to.contains('Would you like to confirm?');
return true;
});
In Prompt Alert user needs to enter text into the input field
it('should trigger a prompt with a message', () => {
cy.window().then(win => {
cy.stub(win, 'prompt').returns('This is my answer.');
cy.get('#prompt-button').click();
cy.get('#prompt-answer').contains('Answer: This is my answer.');
});
});
Hooks in Cypress allow you to run setup and teardown code before and after your tests or test suites. This is useful for tasks like setting up test data, starting or stopping servers, logging in, and cleaning up after tests. Cypress provides several hooks that you can use in your testing framework.
Cypress interview questions are commonly asked during job interviews for roles related to web development and quality assurance. These questions focus on assessing a candidate's proficiency in using the Cypress testing framework, their knowledge of JavaScript, and their ability to write effective test scripts. Interviewers may also inquire about test automation best practices and strategies for handling common testing scenarios
General questions
Shadow DOM (Shadow Document Object Model) is a web standard that allows encapsulation of the DOM and CSS within a web component, preventing external CSS and JavaScript from affecting the component's internal structure. When working with Shadow DOM in Cypress, you might encounter challenges in selecting and interacting with elements within the shadow DOM. Cypress provides ways to interact with shadow DOM elements using its commands and APIs.
cy.get('your-element-with-shadow-dom').shadow().find('element-inside-shadow-dom').click();
Cypress operates within the browser
Cypress is built using JavaScript and runs within a Node.js environment.
The Cypress server is a Node.js process that runs alongside your application and the Electron-based test runner.
It acts as an intermediary between your tests and the browser.
The server listens for commands from your test scripts, communicates with the browser to perform actions, and collects data and results.
Cypress has built-in support for Chromium-based browsers like Chrome and Electron.
Cypress has automatic waiting for elements and actions, reducing the need for explicit waits and timeouts
Cypress offers real-time interactive debugging with time-travel capabilities.
Cypress has a built-in interactive test runner with a live preview of the application under test.
Cypress is relatively easy to set up and get started with, especially for web applications.
cy.get('.list-item').last().click(cy.get('.list-item').first().click(); Purpose:
`cy.log()`: This is a Cypress command used for logging information specifically within Cypress test scripts. It is meant for logging messages that are relevant to your test cases and can be viewed in the Cypress Test Runner's Command Log. It helps you debug and understand the flow of your test scripts.
- `console.log()`: This is a standard JavaScript function used for logging information in the browser's developer console. It is primarily used for debugging JavaScript code in your application. It's not part of Cypress itself but is a core feature of the browser's DevTools.
2. Output Location:
- `cy.log()`: Logs generated by `cy.log()` are displayed in the Cypress Test Runner's Command Log, making them easily accessible while running and debugging your tests within the Cypress environment.
- `console.log()`: Logs generated by `console.log()` are displayed in the browser's developer console. These logs are typically used for debugging your application code and are not directly visible in the Cypress Test Runner.
3. Timing:
- `cy.log()`: Logs generated by `cy.log()` are synchronized with the Cypress test runner and will appear in the order they are executed within your test script. They are part of your test's execution timeline.
- `console.log()`: Logs generated by `console.log()` are asynchronous, meaning they may not appear in real-time order in the console, especially when dealing with asynchronous code. This can make it challenging to correlate them with specific test steps.
Alerts, in the context of web development and user interfaces, are pop-up dialog boxes that display important information or notifications to users. They are commonly used to convey messages, warnings, errors, or requests for user input. Here's a brief description of different types of alerts:
Cypress offers developers a powerful and user-friendly testing framework that simplifies test automation and enhances the reliability of web applications