QA Automation Labs

Running End-to-End Cypress Test cases in a Google Cloud Pipeline

image-20-768x394

Running End-to-End Cypress Test cases in a Google Cloud Pipeline

Cypress is an end-to-end testing framework that is used to test web applications. It is an open-source JavaScript-based framework that enables developers to write and run automated tests for their web applications in a simple and easy way. It allows developers to write tests in JavaScript, and its powerful features include automatic reload of tests, time travel debugging, and interactive debugging. Cypress also provides a dashboard to view test results and insights.

Google Cloud Build is a fully managed continuous integration and delivery (CI/CD) platform provided by Google Cloud. It allows you to automate the build, test, and deployment processes for your applications. With Google Cloud Build, you define a pipeline configuration file (cloudbuild.yaml) that specifies the steps to be executed during the build process. Each step can run commands, execute scripts, or interact with various Google Cloud services.

By integrating Cypress with Google Cloud Pipeline, you can leverage the scalability and automation capabilities of the cloud platform to execute your tests in a consistent and controlled environment. This integration allows you to incorporate Cypress tests into your overall software delivery pipeline, helping you ensure the quality and stability of your applications.

What is End to End Testing?

End-to-end (E2E) testing is a software testing strategy that verifies an application’s complete flow from beginning to end.. It is a type of functional testing that tests the application’s behavior as a complete system, rather than testing individual components in isolation.

E2E testing simulates a real user scenario and covers all aspects of the application, including user interfaces, APIs, databases, and other integrations. It typically involves testing multiple components of an application to ensure that they work together as expected and fulfill the requirements of the business or end-users.

E2E testing is typically performed after other types of testing, such as unit testing and integration testing, have been completed. It is used to validate that the entire system works together seamlessly, and to identify any issues that may have been missed in earlier stages of testing.

Why is end to end testing necessary?

End-to-end testing (E2E testing) is a type of software testing that tests the entire system or application from start to finish, simulating real-world user scenarios.

Unit testing alone is not enough to ensure the quality and reliability of software. While unit testing is an important part of the testing process, it only verifies the behavior of individual components or modules of the software in isolation. It does not guarantee that the software will work correctly when integrated with other components or modules.

This is where integration testing enters  into the picture.Integration testing focuses on testing the interaction between two or more components of a system, to ensure that they work together correctly. However, even if all the individual components pass integration testing, there may still be issues with the overall system when all the components are put together. This is where end-to-end testing comes in, it tests the entire system from start to finish.

Cypress is a popular automation testing framework that is designed specifically for end-to-end testing. It runs tests directly in the browser, allowing it to provide an experience that is similar to how users interact with the application. This makes it easier to identify any issues that users might face, as the testing environment is as close to the real-world experience as possible.

Why Google Cloud Pipeline Integration With Cypress?

Google Cloud Build is a fully managed continuous integration and delivery (CI/CD) platform provided by Google Cloud. Integrating Google Cloud Build Pipeline with Cypress provides several benefits for automated testing and CI/CD workflows:

  1. Scalability: Google Cloud Pipeline provides a scalable infrastructure that allows you to run your Cypress tests in parallel across multiple machines or containers. This enables you to execute tests faster and handle larger test suites efficiently.
  2. Automation: With Google Cloud Pipeline, you can automate the execution of your Cypress tests as part of your CI/CD (Continuous Integration/Continuous Deployment) process. This eliminates the need for manual test execution and enables you to quickly validate your application changes.
  3. Consistency: By integrating Cypress with Google Cloud Pipeline, you ensure that your tests are executed in a consistent and controlled environment. The pipeline provides a standardized setup and configuration, ensuring that tests are run under the same conditions every time.
  4. Collaboration: Google Cloud Pipeline allows you to easily collaborate with your team members by providing shared access to the pipeline configuration, test results, and reports. This promotes collaboration and visibility among developers, testers, and other stakeholders involved in the testing process.
  5. Reporting and Notifications: Google Cloud Pipeline offers various reporting and notification mechanisms. You can generate detailed test reports, track test results over time, and receive notifications about the status of your pipeline runs. This helps you monitor the health of your tests and quickly identify any issues or failures.
  6. Integration with other Google Cloud Services: As part of the Google Cloud ecosystem, Google Cloud Pipeline integrates seamlessly with other services such as Google Cloud Storage, Google Cloud Build, and Google Cloud Functions. You can leverage these services to enhance your testing and deployment workflows further.

Pre-Condition

  1. User already logged in to Google Cloud
  2. User in google cloud Dashboard https://console.cloud.google.com/home/dashboard
  3. Code already pushed in GitHub

How to Set up the Code In Google Cloud?

To set up the Cypress code in Google Cloud, you need to follow these general steps:

Step 1: In the Dashboard from the left side click on ‘Cloud Build” under CI/CD section

Step 2 Click on Cloud Build -> Triggers

After clicking on the Triggers below screen is open

Step 3 Enter Name, Select the Region

Step 4 Select Source and Connect to the repository

Step 5 Select GitHub Account and Select the repository

The project package.json file looks like the one given below.

We will run test cases by giving cy:report in our .yaml file

{
“name”: “cypress_dashboard”,
“version”: “1.0.0”
“description”: “”,
“main”: “index.js”,
“scripts”: {
“cleanup”: “rm -fr cypress/reports”,
“merge_reports”: “mochawesome-merge cypress/reports/mochawesome-report/*.json > output.json”,
“mochawesome_report”: “marge — reportDir cypress/reports/mochawesome-html-report -t Cypress_Test_Report -p Cypress_HMTL_Report -f Cypress_HMTL_Report — charts true output.json”,
“cy_dashboard”: “cypress run — record — key aeed922c-98af-4143–9e77-f97c6c900754”,
“cy:report”: “npm run cleanup && npm run cy_dashboard && npm run merge_reports && npm run mochawesome_report”
},
“author”: “Kailash”,
“license”: “ISC”,
“devDependencies”: {
“cypress”: “9.7.0”,
“mocha”: “8.3.2”,
“mochawesome”: “6.2.2”,
“mochawesome-merge”: “4.2.0”
}
}

Step 6 Under the Configuration select “Cloud Build configuration file (.yaml or .json)”

cloudbuild.yaml file looks like see below

In the below YAML we can see first we are installing dependencies then in Cypress image /include:7.0.1 we are running our test cases

Step 7 Click on the “Create” button below the screen open

Steps to Run End-to-End Cypress Test cases

Step 1 Click on the RUN button from the above screen

Step 2 Click on the RUN TRIGGER button from the above screen. Build start running

The test case starts running see the below screen

Leave a Comment

Your email address will not be published. Required fields are marked *

Recent Posts

AI-Driven Testing with Applitools Autonomous

The demand for high quality software in the fast paced tech environment has never been greater. Since companies spend more on QA to make sure their pr
Read More

Visual Regression Testing Using Playwright

“Have you ever thought, ‘Why wasn’t that noticed?’ or ‘Is the bug so obvious that it should have been caught right away?
Read More

Cypress vs Selenium: Choosing the Best Tool for Your Automation Needs

Choosing the right testing tool for your project can be a challenging task. Two of the most widely used options are Cypress and Selenium, and understa
Read More