Responsive

End-to-end testing of your Kubernetes applications with Cypress

Apr 29, 2022
6 min
read
Abdallah Abedraba
Product Leader
Kusk
Manage and run end-to-end Cypress testing in Kubernetes and access Cypress recorded videos easily with Testkube!
Share on Twitter
Share on LinkedIn
Share on Reddit
Share on HackerNews
Copy URL

Table of Contents

Want to learn more about this topic? Check out our Office Hours sessions!

Start Using Testkube with a Free Trial Today!

Subscribe to our monthly newsletter to stay up to date with all-things Testkube.

Applications running in dynamic environments like Kubernetes need end-to-end testing to ensure reliability and performance. Cypress has quickly become one of the most popular e2e testing tools on the market, thanks to its unique features, such as its powerful debugging tools and ease of use.

In this blog post, we'll look at the Cypress test and how TestKube simplifies Kubernetes testing with Cypress.

Cypress Test Runner

What is Cypress? Cypress is a framework for making end-to-end tests of your applications, mostly used for front-end testing. When you run your Cypress tests, a browser is spun up so you can assert against it automatically that, for example, when a button in your UI is clicked, the desired behavior is correctly executed. Cypress can then record the test execution and provide you with a video of what happened with the actual test.

Traditionally, when working with Kubernetes, you would run your Cypress tests in your Continuous Integration pipeline, and if you wanted to extract the videos recorded by Cypress, you would need to set up a complicated system of saving those videos in an external storage service like S3, with all the authentication, authorization, and networking setups needed just to extract the recorded videos.

Testkube: Solution to Cypress Testing in Kubernetes

What is Testkube? Testkube, a test execution framework for Kubernetes, solves issues by running tests from inside your Kubernetes clusters, saving the generated videos, and providing a simple way to access the videos without exposing to the public unnecessary parts of your Kubernetes cluster. At the end of this post, you will learn how to create a Cypress test, add it to your Kubernetes cluster via Testkube, execute the test, and access the resulting video of your Cypress tests.

Performing Cypress Test with Testkube

Testkube and Cypress can be integrated to simplify testing workflows, improve test visibility, and ensure consistent test execution.

Let's see how efficiently we can run Cypress tests with Testkube, which provides a step-by-step guide to running end-to-end tests on Kubernetes clusters. 

Prerequisites

After meeting the prerequisites, you can launch a target Kubernetes cluster with a configured Testkube agent.

Creating a Test Workflow

Using an existing example is the simplest way to create a Test Workflow on the Testkube dashboard. Testkube includes some prebuilt Test Workflows for k6, PlayWright, Cypress, and other tools.
Here, we'll go over a few steps for creating and understanding a Cypress Test Workflow.

Navigate to the Test Workflow section and click the “Add New Test Workflow” button.

A “Create a Test Workflow” dialog box appears that provides you with four options to create a Test Workflow:

  • Create from Wizard: This option opens a dialog box that prompts you to create a new Test Workflow. 
  • Start from an Example: This option allows you to use a pre-configured example, such as k6, Playwright, Cypress, Playwright, Postman, and many others.
  • Combine Existing Workflows: This option allows you to combine and execute multiple existing Test Workflows sequentially or simultaneously.
  • Import a Workflow from YAML: This option allows you to import a Test Workflow from a YAML definition.

Choose the “Start from an Example” option to create this workflow.

A new dialog box appears, with a list of test tools to choose from. We’ll choose “Cypress” to create this Test Workflow.

Click on the “Create & Run” button to create and run the Test Workflow.

Executing the Test Workflow

After you click the "Create & Run" button, the Test Workflow will begin.

To view real-time progress and logs, click on each step of the test procedure. Following execution, Testkube collects all artifacts, including a stats report containing all of the results and outputs.

Select the "Artifacts" tab. It lists all of the video artifacts captured during the Cypress test execution. You can review the *.mp4 file to see exactly what happened during the test, which will help with future debugging.

This was a simple example of how to use Test Workflows in Kubernetes testing. To get the most out of Test Workflows, you can create complex workflows or import custom workflows into Testkube.

Understanding Cypress Testing Workflow File

Let's analyze the Cypress Test Workflow that was used to set up and carry out this test:

```

spec:

  content:

    git:

      uri: https://github.com/kubeshop/testkube

      revision: main

      paths:

      - test/cypress/executor-tests/cypress-13

  container:

    workingDir: /data/repo/test/cypress/executor-tests/cypress-13

  steps:

  - name: Run tests

    run:

      image: cypress/included:13.6.4

      env:

      - name: CYPRESS_CUSTOM_ENV

        value: CYPRESS_CUSTOM_ENV_value

      args:

      - --env

      - NON_CYPRESS_ENV=NON_CYPRESS_ENV_value

      - --config

      - video=true

```

The specification file contains the following components:

  • The content includes a list of the test file's source, location, and path.
  • The steps specify the tests that will be run in the workflow using a specific Cypress Docker image, as well as custom environment variables and configurations.

Read our Test Workflow document to understand more about the Test Workflow specification.

More on End-to-End Testing

You could also run your tests from your CI/CD pipelines using the Testkube CLI or by triggering them manually. Testkube decouples your test execution from being strictly dependent on the CI/CD pipeline, allowing you to run tests both as part of your builds and for ad-hoc validation of your applications.

We support more integration test frameworks like Postman, K6, and many more. You can even incorporate your favorite testing tool by creating your own Testkube executor. The Testkube team aims to include most testing tools to improve integration tests in the Kubernetes realm!

You can also make use of Testkube webhooks to connect your test execution results to Slack or any notification service.

Why not give it a go yourself? Sign up to Testkube and try one of our examples or head over to our documentation - if you get stuck or have questions, we’re here to help! Find an answer to your questions in the Testkube Knowledge Base or reach out to us on Slack. We’re eager to hear how you use our integrations!

Abdallah Abedraba
Product Leader
Kusk
Share on Twitter
Share on LinkedIn
Share on Reddit
Share on HackerNews
Copy URL