Mount Persistence Volume using Zalenium helm charts

Kubernetes persistent volumes are an administrator provisioned volumes.

Note: This post explains you how to create & provision custom volumes through charts for Zalenium lovers. Charts is a new & easy approach for kubernetes to deploy containers; it has a structured pattern for templates in yaml format and a separate values.yaml file to provision containers.

Follow this hierarchy for quick understanding if you are a laymen to Helm charts:

deployment.yaml > pod-template.yaml > pvc-shared.yaml > values.yaml

deployment.yaml

Kubernetes deployment helps you manage & monitor containers

  • Make sure you mention the pod template file in deployment.yaml. See below snippet as in the existing deployment.yaml file
spec:
  template:
    {{- include "zalenium.podTemplate" . | nindent 4 }}

pod-template.yaml

By default, Zalenium has defined a pod template with the name podTemplate. You can either create your own template or use the existing one. I have used the existing template and made some additions in it.

  • Create a volume with the hostPath containing local directory/file path that needs to be mounted inside the containers
  • Here, I named the volume as zalenium-shared
spec:
  volumes:
    - name: {{ template "zalenium.fullname" . }}-shared
      hostPath:
        path: /Users/Username/local_dir_path/images/
  • And locate the target path inside containers
volumeMounts:
  - name: {{ template "zalenium.fullname" . }}-shared
    mountPath: /home/seluser/custom_directory

pvc-shared.yaml

Persistence Volume Claim / PVCs are objects that request storage resources from your cluster

  • Create a file pvc-shared.yaml with request template containing key-pairs to be imported from the values.yamlfile
  • Here, I named storageClassName as zale_sharedand rest of the data were imported from values.yaml file

values.yaml

  • Provision containers with required size, access, etc., as below
persistence:
  shared:
    enabled: false
    useExisting: false
    name: zale_shared
    accessMode: ReadWriteMany
    size: 2Gi
  • For more details, see example GitHub repo
Advertisements

Zalenium Dockerized Selenium Grid

Zalenium provides docker images (Hub + Nodes) with the latest browser drivers, browsers, and tools (for any language bindings) required for Selenium automation. The containers created from these images can be scaled-up with simple CLI commands. By default, there will be two live containers up and running.

  • Open terminal and download the below images from Docker hub
docker pull elgalu/selenium
docker pull dosel/zalenium
  • Create docker containers and start Zalenium proxy in a single command
docker run --rm -ti --name zalenium -p 4444:4444 -v /var/run/docker.sock:/var/run/docker.sock -v /tmp/videos:/home/seluser/videos --privileged dosel/zalenium start
  • Now, configure the driver initialization
options = {
  'chromeOptions' => {
    'args' => ['disable-infobars', 'disable-gpu', 'privileged', 'ignore-certificate-errors']
  }
}

caps = Selenium::WebDriver::Remote::Capabilities.chrome(options)
@driver = Selenium::WebDriver.for :remote, :url => "http://0.0.0.0:4444/wd/hub", desired_capabilities: caps
  • Check out live test session using the below URL
http://localhost:4444/grid/admin/live

  • Start monitoring the Zalenium live interface once the tests were triggered

  • You can also review tests through the recorded video stream
http://localhost:4444/dashboard/

  • To stop the docker containers spun through Zalenium, simply exit Zalenium proxy using the below command
docker stop zalenium

 

Method #2 (most preferred approach)

Using this approach actually detaches the Zalenium process from running in the terminal

  • A single line command to start Zalenium proxy and make docker containers up
curl -sSL https://raw.githubusercontent.com/dosel/t/i/p | bash -s start
  • Command to terminate the Zalenium proxy along with the running/exited containers
curl -sSL https://raw.githubusercontent.com/dosel/t/i/p | bash -s stop
  • Scale up docker containers as desired; but, make sure you create replicas only if the machine has proper CPU (x4/x8/x16) cores specific to the containers
curl -sSL https://raw.githubusercontent.com/dosel/t/i/p | bash -s start --desiredContainers 8 --screenWidth 1440 --screenHeight 900 --timeZone "Asia/Dubai" --maxDockerSeleniumContainers 10 --maxTestSessions 30 --videoRecordingEnabled true