Thursday 9 February 2023

Top 11 Cypress Commands asked in Interview Questions and Answers 2023?

 


SDET Interview Question and Answers.  

Jenkins Interview Questions and Answers

Appium Interview Questions and Answers

Selenium Interview Questions and answers

GIT Interview Questions and Answer


What is Cypress?

Cypress is a purely JavaScript-based front-end testing tool built for the modern web. It aims to address the pain points developers or QA engineers face while testing an application. Cypress is a more developer-friendly tool that uses a unique DOM manipulation technique and operates directly in the browser.


INSTALL CYPRESS

If you haven't installed Cypress yet then refer to this link on:


Top 10 Cypress Commands 

  • cy.visit(): 
This command is used to navigate to a specified URL in the browser.

describe('My First Test', function() {
    it('Visits the Kitchen Sink', function() {
        cy.visit('https://example.cypress.io');
    });
});


In this example, the cy.visit() command is used to navigate to the URL https://example.cypress.io. The describe and it blocks are used to define a test suite and a test case, respectively. In this case, the test case simply visits the specified URL, but you could add additional commands to interact with the page or perform assertions once the page has loaded.

  • cy.get(): 
This command is used to select an element on the page and perform various actions on it.


  • cy.contains(): 
This command is used to search for a specific string of text within an element or on the page.

describe('My First Test', function() {
    it('Finds a specific text on the page', function() {
        cy.visit('https://example.cypress.io');

        cy.contains('Type').click();

        cy.contains('form').find('input[name="email"]') .type('fake@email.com');

        cy.contains('Submit').click();

        cy.contains('Your form has been submitted!');
    });
});


In this example, the cy.contains() command is used in several ways:

  1. To click on a specific text on the page: cy.contains('Type').click();

  2. To locate an input field within a form and type into it: cy.contains('form').find('input[name="email"]').type('fake@email.com');

  3. To click a submit button: cy.contains('Submit').click();

  4. To make an assertion that a specific text is present on the page: cy.contains('Your form has been submitted!');

In each of these examples, the cy.contains() command is used to search for a specific string of text on the page, and then perform an action or make an assertion based on that search result.


  • cy.click(): 
This command is used to simulate a click event on an element.


  • cy.type(): 
This command is used to simulate typing into an input field.

describe('My First Test', function() {
    it('Types into an input field', function() {
        cy.visit('https://example.cypress.io');

        cy.contains('Type').click();

        cy.get('input[name="email"]').type('fake@email.com');

        cy.get('input[name="password"]').type('password123{enter}');

        cy.contains('Your form has been submitted!');
    });
});


In this example, the cy.type() command is used to enter text into two input fields on a form. The first line of text is entered into an input field with the name "email", while the second line of text is entered into an input field with the name "password". Additionally, the special key {enter} is used to simulate the pressing of the "Enter" key, which would typically submit the form. After the form is submitted, an assertion is made to verify that the expected text is present on the page.
  • cy.clear(): 
This command is used to clear the value of an input field.

  • Write a script in Cypress to automate gmail.

Ans: Click the link here for the Cypress script to automate gmail.

  • cy.wait(): 
This command is used to delay the execution of the next command for a specified amount of time.


  • cy.wrap(): 
This command is used to wrap an element in a chain able object, allowing you to perform multiple actions on the same element.

// Define an object that we want to wrap as a Cypress command
const myObject = {
  doSomething: () => {
    console.log('I am doing something');
  },
};

// Wrap the object as a Cypress command
Cypress.Commands.add('doSomething', function() {
  return cy.wrap(myObject).its('doSomething').invoke('doSomething');
});

// Use the custom command in a test
describe('My Test', () => {
  it('uses my custom command', () => {
    cy.doSomething();
  });
});


In this example, myObject is an object with a method doSomething. By wrapping it with cy.wrap, we can access the properties and methods of myObject using the Cypress command-like syntax. In this case, we are accessing the doSomething method of myObject and invoking it using invoke.
  • cy.should(): 
This command is used to add assertions to your tests, verifying that the state of the application meets expectations.

  • How to rerun failed test cases using Cypress?

Ans: Check the link HERE for detailed steps with the code.


  • cy.log(): 
This command is used to log a message to the console, making it easier to debug your tests and understand what is happening during test execution.

describe('My Test', () => {
  it('logs a message', () => {
    cy.log('This is a log message');
  });
});


In this example, the cy.log method is used to log the message 'This is a log message' to the browser's console and to the Cypress test runner. You can use cy.log to log any type of data, including strings, numbers, objects, and arrays. The logged data will be displayed in the Cypress test runner and can be used for debugging or for tracking the progress of your tests.

*******************************************************************
For any doubts or career guidance, reach out to me 


********************************************************************

These commands cover a range of basic UI interactions and are a good starting point for building automated tests with Cypress.

Do remember that knowing Linux is one of the most important aspect to work as an SDET.

Basic Linux Commands for Automation QA


****************************************

TOP 15 BDD - CUCUMBER Interview Q&A


************************************************

✍️AUTHORLinkedIn Profile

************************************************

Learn (API-Microservice)Testing+ Selenium UI Automation-SDET with Self Paced Videos prepared by FAANG employees and LIVE Doubt Session 

SDET TRANING VIDEOS AVAILABLE with Live Doubt Session(course-1 below,API TRaining Videos With Class Notes and Coding Set) and (API+UI, both course-1 & 2 below) Check Training Page for Course Content or reach out @whatsapp +91-9619094122. 
This includes classnotes, 300+ interview questions, 3 projects, Java Coding question set for product companies along with career guidance from FAANG employees for Automation and SDET.

For more details whatsapp : https://lnkd.in/dnBWDM33

*************************************************

SeleniumWebdriver Automation Testing Interview Questions:

https://automationreinvented.blogspot.com/search/label/SeleniumWebdriver

API Testing Interview Question Set:

https://automationreinvented.blogspot.com/2022/03/top-80-api-testing-interview-questions.html

DevOps Interview Q&A:

https://automationreinvented.blogspot.com/2021/11/top-11-devops-interview-questions-and.html 

Kubernetes Interview Question Set

https://automationreinvented.blogspot.com/search/label/Kubernetes

Docker Interview Question Set

https://automationreinvented.blogspot.com/Docker

Linux Interview question Set

https://automationreinvented.blogspot.com/search/label/Linux

Automation Testing/SDET Framework Design

https://automationreinvented.blogspot.com/search/label/FrameworkDesign

Java Related Interview Question Set

https://automationreinvented.blogspot.com/search/label/Java

GIT Interview Question Set:

https://automationreinvented.blogspot.com/2021/09/top-40-git-interview-questions-and.html

Coding Interview Question Set:

https://automationreinvented.blogspot.com/search/label/Coding%20Questions

Mobile Testing Interview Question Set:

https://automationreinvented.blogspot.com/search/label/Mobile%20Testing

Python Interview Question Set for QAE - SDET - SDE:

https://automationreinvented.blogspot.com/search/label/Python

No comments:

Post a Comment

All Time Popular Posts

Most Featured Post

Introduction to Web Testing with Playwright

  Introduction to Web Testing with Playwright 📌  Telegram Group:  https://t.me/+FTf_NPb--GQ2ODhl 📌  YouTube channel:  https://lnkd.in/gGUG...