Skip to content

Commit

Permalink
Merge pull request #150 from incubyte/blog/cypress-guide
Browse files Browse the repository at this point in the history
Add cypress guide blog
  • Loading branch information
2KAbhishek committed Nov 20, 2023
2 parents d144dea + 320774b commit 6068a23
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 0 deletions.
5 changes: 5 additions & 0 deletions content/authors/utsav-parmar/pranita-aitwadkar/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Pranita Aitwadkar
image: "/images/favicon.png"
subtitle: "Quality Craftsperson at Incubyte"
---
151 changes: 151 additions & 0 deletions content/blog/cypress-guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
+++
authors = ["Pranita Aitwadkar"]
categories = ["Testing", "Automation"]
date = 2023-11-14T00:00:00Z
description = ""
draft = false
image = "/images/2023/cypress-guide/header-image.jpg"
slug = "cypress-guide"
tags = ["Testing", "Automation"]
title = "A Comprehensive Guide To Web Testing with Cypress"
+++

In the fast-paced world of web development, ensuring the quality of your applications is paramount.
One powerful tool that has gained significant popularity in recent years is Cypress.
Cypress is an end-to-end testing framework that empowers developers and QA engineers to write reliable, efficient, and maintainable tests.
In this blog, we will explore the ins and outs of Cypress and discover how it can revolutionize your web testing workflow.

## What is Cypress?

Cypress is an automation testing tool for web applications.
It runs on Windows, Linux and macOS.
Cypress app is open-source software released under the MIT License while the Cypress Cloud is a web application.

## Installation and Setup Instructions

**Prerequisites:** Ensure that you have Node.js installed on your machine.
You can download and install it from the [Node.js website](https://nodejs.org).

1. Creating a new project

Create a new directory for your project and navigate to it in your terminal or command prompt.

```bash
mkdir -p cypress-starter
cd cypress-starter
```

2. Initializing npm

Run the following command to initialize a new npm project.

```bash
npm init -y
```

4. Installing Cypress

Run the following command to install Cypress as a development dependency in your project.

```bash
npm install cypress --save-dev
```

5. Verifying installation

After the installation is complete, Cypress should be available in your project's node_modules directory.
You can verify it by running the following Cypress command.

```bash
npx cypress --version
```

6. Opening Cypress

To open the Cypress Test Runner, run the below command.

```bash
npx cypress open
```

This will open the Cypress Test Runner, which provides an interactive interface for managing and running your tests.

## Creating Your First Cypress Test

1. With the Cypress Test Runner open, you'll see a list of example tests provided by Cypress.
You can choose to keep them or remove them.

2. To create a new test, click on the "New File" button in the Cypress Test Runner.
By default, the test files are created in the cypress/e2e directory.

3. In your new test file, you can write your first Cypress test using the Cypress API.

Here's a simple example that tests the title of a web page.

```javascript
describe('My First Test', () => {
it('Visits the homepage and checks the title', () => {
cy.visit('https://example.com');
cy.title().should('contain', 'Example Domain');
});
});
```

4. Save the test file with a `.cy.js` extension.
For instance, you can save it as `homepage.cy.js`.

5. In the Cypress Test Runner, click on your test file to run it.
You should see a browser window open and the test being executed.
You can see the test commands and assertions in the Cypress Test Runner's command log.

### Feature of Cypress

#### Time Travel

Cypress has an interesting feature called time-travel debugging.
Basically, it allows you to watch your tests run step by step, pause whenever you want, and check out what's happening in the application at that moment.

It's like having a slow-motion button for your tests!

#### Automatic Waiting and Retrying

Cypress automatically waits for things to finish before moving on to the next step in your test.

What's great about this is that it's really smart! If a command or assertion takes longer than expected, Cypress will keep retrying it until it succeeds or until it reaches a timeout.

So you don't have to worry about writing explicit waits or adding delays in your tests.

#### Screenshots and Video Recording

Cypress offers a convenient feature that captures screenshots and records videos as your tests run. This proves incredibly useful for visually diagnosing any failures that may occur during the test.

#### Headless and Interactive Modes

Cypress gives you the freedom to run tests in different modes: headless mode and interactive mode.Running your tests in headless mode can speed up the testing process and allow you to run tests in environments.Cypress runs tests interactively, allowing you to see commands as they execute while also viewing the Application or Component Under Test, and exploring its DOM.


#### Customization and Extensibility

The plugin architecture feature in Cypress operates like a toolbox, enabling you to customize and expand Cypress's capabilities to meet your specific needs. With this plugin architecture, you can create your own custom commands.

#### DOM Manipulation and Control

Cypress simplifies working with the Document Object Model (DOM) directly. The DOM serves as the blueprint of a webpage, and Cypress empowers you to interact with it effortlessly. By using selectors, you can pinpoint specific elements on the page, just like using a super-smart search tool that precisely locates what you're seeking.

#### Cross Browser Testing

Cypress makes it easy to run tests with Firefox, Chrome, Edge & Electron.

#### Debugging

With Cypress, when a test fails, you can simply open the developer tools & explore the console, network, request & other useful information.

### Conclusion

Cypress is undoubtedly a game-changer in the world of web testing, providing developers and QA engineers with a powerful and intuitive toolset. With its extensive features, straightforward syntax, and seamless integration with modern development workflows, Cypress is a valuable asset for any web testing endeavor.

By following the best practices outlined in this guide, you'll be equipped to leverage Cypress to its fullest potential, delivering high-quality web applications with confidence.

Get ready to elevate your web testing game with Cypress!

For more details, check out the official [Cypress Docs.](https://docs.cypress.io/guides/getting-started/installing-cypress)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6068a23

Please sign in to comment.