Cypress First Test Case

Cypress First Test Case

Writing first test case is always exciting and interesting to start with. Let’s write a hello world test case using cypress.

1. Open VS code

2. Open cypress project folder in VS Code

3. Create a file under e2e folder. helloWorld.cy.js

4. Write below code inside the file:

describe('My First test', () =>?{
 it('Hello World', ()=> {
  cy.log('Hello World')
 })
})        

?5. Now open terminal from VS code by clicking at left bottom of VS Code

6. In the terminal, run command -> npx cypress open

7. Select E2e and browser, now select your new test file from the list

8. This will run in a window and shows the log you mentioned in your code. like this

Lets understand and enhance our script and open a website:

9. Describe and it blocks comes from mocha. Describe blocks is consirered as test suite and it block can be used as test case. Context block can be used if we have different contexts within describe block. Context blocks can contain it blocks inside.

10. Cy is a cypress command, which is further chained with commands to be executed on browser

11. Cy.log is used to print in the cypress logs

12. Use cy.visit(‘webpage-url’) to visit the website

describe('My First test', () =>?{
 it('Visit Amazon', ()=> {
  cy.visit('https://www.amazon.com/')
 })
})        

?13. Save this and Re-run the tests (if cypress runner is already opened, test will re-run automatically on saving.)

This is how you can start with cypress' first test case. you should start exploring other commands in cypress from this link https://docs.cypress.io/api/table-of-contents. Do write to me if you are looking for specific command to know more about.

要查看或添加评论,请登录

Amit K Verma的更多文章

  • Cypress Runner with Failed Test Case Part - 2

    Cypress Runner with Failed Test Case Part - 2

    How to identify css locator using cypress runner: 1. In cypress runner app, click on this bullseye circled icon inside…

  • Understanding Cypress app runner

    Understanding Cypress app runner

    Pic - 1 Pic - 2 This chrome/browser window will be labeled to show you that the window/tab is being controlled by…

  • Cypress Folder Structure Explained

    Cypress Folder Structure Explained

    This article will help you knowing about the folder structure that comes with cypress e2e installation and setup. We…

  • Cypress Installation

    Cypress Installation

    Cypress comes as a node package. To install cypress we need node on the system.

  • Cypress vs Selenium - a comparison

    Cypress vs Selenium - a comparison

    This is the most common comparison selenium guys look for before they switch to cypress to know how cypress can ease…

  • Cypress Architecture

    Cypress Architecture

    Cypress architecture makes it so reliable, robust and fast than other tools in the market. To make this happen, cypress…

  • Cypress Disadvantages

    Cypress Disadvantages

    Nothing comes with benefits only, so does cypress. Cypress do have a few limitations to consider before you actually…

  • Cypress Advantages Part-2

    Cypress Advantages Part-2

    Here's the next 10 advantages of cypress for Web automation and API testing. Flake Resistance / Retries: Cypress is…

  • Cypress Advantages Part-1

    Cypress Advantages Part-1

    Lets first dive into the advantages of Cypress automation tool, which is being loved by the developers and automation…

  • Cypress Overview

    Cypress Overview

    Testing is a game of finding what others could not see or detect. This is an exciting game till you start feeling…

社区洞察

其他会员也浏览了