Aller au contenu

How to run cypress tests on Kunai

Objectives

The idea is to use an Ubuntu VM with the graphical interface on which Cypress could be run to write and run Kunai E2E tests.

Ideally, the tests should be run in a graphical environment, however, they can also be run without the graphical mode.

Steps

Prerequisites

Cypress

  1. Download the repository Kunai

    git clone https://gitlab.com/sylva-projects/sylva-elements/kunai.git
    
  2. Install Yarn

    curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
    echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
    sudo apt update
    sudo apt install yarn
    
  3. Install Cypress

    sudo apt-get install libgtk2.0-0t64 libgtk-3-0t64 libgbm-dev libnotify-dev libnss3 libxss1 libasound2t64 libxtst6 xauth xvfb
    cd ~/kunai/client
    yarn --frozen-lockfile
    
  4. Run localy Kunai application

    cd ~/kunai
    
    tilt up
    
  5. Configure Cypress

    In order to run Cypress E2E test we need to set some parameters using the following files.

    • Creation of the directory for the environment parameters

      cd ~/kunai/client/cypress/environment
      
    • Creation of the cluster certificat file

      kubectl get secret demo-service-account-token -o jsonpath="{.data['ca\.crt']}" | base64 -d > cluster_certificat.txt
      
    • Creation of the global parameters file

      vi .env.cypress 
      
      CURRENT_PATH=`dirname $BASH_SOURCE `
      export CYPRESS_BASE_URL_API=https://kunai.local
      export CYPRESS_BASE_URL_GUI=https://kunai.local
      
      export CYPRESS_AUTH_URL=https://keycloak.local
      
      export CYPRESS_USERNAME=to_be_defined
      export CYPRESS_PASSWORD=to_be_defined
      
      export CYPRESS_GIT_REPO=https://gitlab.com/your_git_repo
      export CYPRESS_GIT_TOKEN=glpat-to_be_defined
      export CYPRESS_GIT_CERTIFICAT=$([ -f $CURRENT_PATH/git_certificat.txt ] && cat $CURRENT_PATH/git_certificat.txt)
      
      kubectl config use-context kind-kind
      export CYPRESS_MGT_CLUSTER_URL=https://kubernetes.default.svc.cluster.local
      export CYPRESS_MGT_CLUSTER_TOKEN=$(kubectl get secret demo-service-account-token -o jsonpath={.data.token} | base64 -d)
      export CYPRESS_MGT_CLUSTER_CERTIFICAT=$(kubectl get secret demo-service-account-token -o jsonpath="{.data['ca\.crt']}" | base64 -d)
      
      export CYPRESS_WORKLOAD_CLUSTER_NAME="tilt-cluster"
      export CYPRESS_WORKLOAD_CLUSTER_TEMPLATE="docker-kubeadm"
      # -------------------------------------------
      # variable for docker-kubadm template
      # -------------------------------------------
      export CYPRESS_WORKLOAD_CLUSTER_HTTP_PROXY="to_be_defined"
      export CYPRESS_WORKLOAD_CLUSTER_HTTPS_PROXY="to_be_defined"
      export CYPRESS_WORKLOAD_CLUSTER_NO_PROXY="to_be_defined"
      export CYPRESS_WORKLOAD_CLUSTER_MIRROR_DEFAULT_OVERRIDE_PATH=false
      export CYPRESS_WORKLOAD_CLUSTER_MIRROR_REGISTRY_DOCKER_IO="to_be_defined"
      export CYPRESS_WORKLOAD_CLUSTER_MIRROR_REGISTRY_REGISTRY_K8S_IO="to_be_defined"
      # -------------------------------------------
      # variable for open template itcaas-capo-prod
      # -------------------------------------------
      # export CYPRESS_WORKLOAD_CLUSTER_PLATFORM="to_be_defined"
      # export CYPRESS_WORKLOAD_CLUSTER_NETWORK_ID="to_be_defined"
      # export CYPRESS_WORKLOAD_CLUSTER_EXTERNAL_NETWORK_ID="to_be_defined"
      # export CYPRESS_WORKLOAD_CLUSTER_STORAGE_CLASS="to_be_defined"
      
      
      export CYPRESS_TEMPLATE_CAPI_TYPE="capd"
      export CYPRESS_TEMPLATE_REPO=https://gitlab.com/your_git_repo_templates
      export CYPRESS_TEMPLATE_TOKEN=glpat-to_be_defined
      export CYPRESS_TEMPLATE_VERSION="x.y.z"
      export CYPRESS_TEMPLATE_COMMIT_ID="to_be_defined"
      
      export CYPRESS_LABEL_NAME="cypress label with spaces and UPPERCASE"
      
    • Set variables using parameters file

      . ~/kunai/client/cypress/environment/.env.cypress 
      
  6. Run Cypress

    Before running the Local Proxy we need to run the Cypress

    export NO_PROXY=gitlab.com,localhost,.local
    export no_proxy=$NO_PROXY
    yarn cypress run