Latest commit

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Running Selenium Grid on Kubernetes cluster

In this tutorial, I’ll show you how to get Selenium Grid up and running on Kubernetes cluster using Helm package manager.

Contents

  1. Prerequisites
  2. Selenium Grid
  3. Kubernetes
  4. Selenium-Grid Installation
  5. Run Selenium tests
  6. Debugging with VNC Viewer
  7. Deletes a release

Selenium Grid

Selenium Grid makes automation execution jobs much easier. Using Selenium Grid, one can run multiple tests on multiple machines in parallel, which reduces execution times from days to hours. However, setting up our own Selenium Grid means we have to configure browsers across multiple machines, virtual or physical, and making sure each machine is running the Selenium Server correctly. This also means maintaining the Grid and making updates would be a time-consuming. This is where Kubernetes comes in and saves the day!

Kubernetes

Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications.

Helm

Helm is a package manager for Kubernetes applications, responsible for installing and managing Kubernetes applications. Helm packages all of the different Kubernetes resources (such as deployments, services, and ingress) into a chart, which may be hosted in a repository. Users can pull down charts and install them on any number of Kubernetes clusters. This is similar to Homebrew and apt-get package manager. We will use Helm to deploy selenium-grid on Kubernetes Cluster.

What We’ll Accomplish
  1. Set up a Kubernetes cluster using Docker for Mac
  2. Deploy Selenium-Grid to the cluster
  3. Running selenium test and viewing your Selenium tests running on Kubernetes cluster

Prerequisites

  • kubectl - macOS users can use brew install kubectl to install
  • Docker for Mac - Docker with Kubernetes is currently only available on Docker for Mac in the latest Edge version
  • Virtualbox - macOS users can use brew cask install virtualbox to install
  • Helm - macOS users can use brew install kubernetes-helm to install

Verify the Installation

docker --version # Docker version 17.09.0-ce, build afdb6d4
docker-compose --version # docker-compose version 1.16.1, build 6d1ac21
docker-machine --version # docker-machine version 0.12.2, build 9371605
kubectl version --client # Client Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.1", GitCommit:"f38e43b221d08850172a9a4ea785a86a3ffa3b3a", GitTreeState:"clean", BuildDate:"2017-10-12T00:45:05Z", GoVersion:"go1.9.1", Compiler:"gc", Platform:"darwin/amd64"} helm version --client # Client: &version.Version{SemVer:"v2.9.0", GitCommit:"f6025bb9ee7daf9fee0026541c90a6f557a3e0bc", GitTreeState:"clean"}

Enabling the local Kubernetes cluster

Click the Docker icon in the status bar, go to “Preferences”, and on the “Kubernetes”-tab, check “Enable Kubernetes”. This will start a single node Kubernetes cluster for you and install the kubectl command line utility. This might take a while, but the dialog will let you know once the Kubernetes cluster is ready.

Next step, you’ll need to increase Docker’s available memory to 4GB or more.

Click the Docker icon in the status bar, go to “Preferences”, and on the “Advanced”-tab, change memoery to 4GB or more.

Selenium Grid installation

To install the chart with the release name selenium-grid:

helm install --name selenium-grid stable/selenium \
--set chromeDebug.enabled=true \
--set firefoxDebug.enabled=true

The command deploys Selenium Grid on the Kubernetes cluster in the default configuration with chromeDebug and firefoxDebug enabled.

Note: You should see the following output after executing helm install ...

NAME: selenium-grid
LAST DEPLOYED: Fri May 11 23:09:29 2018
NAMESPACE: default
STATUS: DEPLOYED
RESOURCES:
==> v1/Service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
selenium-grid-selenium-hub LoadBalancer 10.110.225.161 localhost 4444:30665/TCP 0s
==> v1beta1/Deployment
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
selenium-grid-selenium-chrome-debug 1 1 1 0 0s
selenium-grid-selenium-firefox-debug 1 1 1 0 0s
selenium-grid-selenium-hub 1 1 1 0 0s
==> v1/Pod(related)
NAME READY STATUS RESTARTS AGE
selenium-grid-selenium-chrome-debug-6d8898d7c4-7psdh 0/1 ContainerCreating 0 0s
selenium-grid-selenium-firefox-debug-84f6f484d8-wh66d 0/1 ContainerCreating 0 0s
selenium-grid-selenium-hub-f7f874cd-p5lrd 0/1 ContainerCreating 0 0s

Selenium hub will automatically start-up using port 4444 by default. You can view the status of the hub by opening a browser window and navigating to: http://localhost:4444/grid/console

Run Selenium Test

Let's run a quick Selenium test to validate our setup.

Clone this github repo:
git clone https://github.com/sayems/selenium.grid.git
Go into the project
$ cd selenium.grid
Run tests

Before you run docker-compose up, verify Selenium grid is up & running on Kubernetes cluster, you can verify by executing the following command: $ kubectl get pods

$ docker-compose up

It typically takes several minutes for docker setup for the first time, so wait for few minutes …

Debugging with VNC Viewer

It is useful to be able to view your Selenium tests running on Kubernetes cluster. This can help us to debug issues better and have more confidence in our tests. To view running tests on Kubernetes cluster.

  1. Download VNC® Viewer for Google Chrome
  2. Execute the following command to bind ports between Kubernetes cluster to the local machine:
 kubectl port-forward --namespace default \
$(kubectl get pods --namespace default \
-l app=selenium-grid-selenium-chrome-debug \
-o jsonpath='{ .items[0].metadata.name }') 5900
  1. Open VNC® Viewer for Google Chrome
    • Address: 127.0.0.1:5900
    • Password: secret

Deletes a release from Kubernetes

The helm list function will show you a list of all deployed releases.

$ helm list

List of all releases

NAME REVISION UPDATED STATUS CHART NAMESPACE
selenium-grid 1 Fri May DEPLOYED selenium default

If you want to delete selenium-grid, you can execute the following command

$ helm delete selenium-grid
release "selenium-grid" deleted

If you want to delete all Helm releases, you can pipe the output of helm ls --short to xargs, and run helm delete for each release name.

$ helm ls --short | xargs -L1 helm delete

Configuration

The following table lists the configurable parameters of the Selenium chart and their default values.

ParameterDescriptionDefault
global.nodeselectorNode label to be useed globally for scheduling of all imagesnil
hub.imageThe selenium hub imageselenium/hub
hub.tagThe selenium hub image tag3.11.0
hub.pullPolicyThe pull policy for the hub imageIfNotPresent
hub.portThe port the hub listens on4444
hub.javaOptsThe java options for the selenium hub JVM, default sets the maximum heap size to 1,000 mb-Xmx1000m
hub.resourcesThe resources for the hub container, defaults to minimum half a cpu and maximum 1,000 mb RAM{"limits":{"cpu":".5", "memory":"1000Mi"}}
hub.serviceTypeThe Service typeNodePort
hub.serviceSessionAffinityThe session affinity for the hub serviceNone
hub.gridNewSessionWaitTimeoutnil
hub.gridJettyMaxThreadsnil
hub.gridNodePollingnil
hub.gridCleanUpCyclenil
hub.gridTimeoutnil
hub.gridBrowserTimeoutnil
hub.gridMaxSessionnil
hub.gridUnregisterIfStillDownAfernil
hub.seOptsCommand line arguments to pass to hubnil
hub.timeZoneThe time zone for the containernil
hub.nodeselectorNode label to use for scheduling of the hub if set this takes precedence over the global valuenil
chrome.enabledSchedule a chrome node podfalse
chrome.imageThe selenium node chrome imageselenium/node-chrome
chrome.tagThe selenium node chrome tag3.11.0
chrome.pullPolicyThe pull policy for the node chrome imageIfNotPresent
chrome.replicasThe number of selenium node chrome pods1
chrome.javaOptsThe java options for the selenium node chrome JVM, default sets the maximum heap size to 900 mb-Xmx900m
chrome.volumeMountsAdditional volumes to mount, the default provides a larger shared memory[{"mountPath":"/dev/shm", "name":"dshm"}]
chrome.volumesAdditional volumes import, the default provides a larger shared memory[{"name":"dshm", "emptyDir":{"medium":"Memory"}}]
chrome.resourcesThe resources for the node chrome container, defaults to minimum half a cpu and maximum 1,000 mb{"limits":{"cpu":".5", "memory":"1000Mi"}}
chrome.screenWidthnil
chrome.screenHeightnil
chrome.screenDepthnil
chrome.displayThe vnc displaynil
chrome.chromeVersionThe version of chrome to usenil
chrome.nodeMaxInstancesThe maximum number of browser instancesnil
chrome.nodeMaxSessionThe maximum number of sessionsnil
chrome.nodeRegistryCycleThe number of milliseconds to wait, registering a nodenil
chrome.nodePortThe port to listen onnil
chrome.seOptsCommand line arguments to pass to nodenil
chrome.timeZoneThe time zone for the containernil
chrome.nodeselectorNode label to use for scheduling of chrome images if set this takes precedence over the global valuenil
chromeDebug.enabledSchedule a selenium node chrome debug podfalse
chromeDebug.imageThe selenium node chrome debug imageselenium/node-chrome-debug
chromeDebug.tagThe selenium node chrome debug tag3.11.0
chromeDebug.pullPolicyThe selenium node chrome debug pull policyIfNotPresent
chromeDebug.replicasThe number of selenium node chrome debug pods1
chromeDebug.javaOptsThe java options for a selenium node chrome debug JVM, default sets the max heap size to 900 mb-Xmx900m
chromeDebug.volumeMountsAdditional volumes to mount, the default provides a larger shared[{"mountPath":"/dev/shm", "name":"dshm"}]
chromeDebug.volumesAdditional volumes import, the default provides a larger shared[{"name":"dshm", "emptyDir":{"medium":"Memory"}}]
chromeDebug.resourcesThe resources for the hub container, defaults to minimum half a cpu and maximum 1,000 mb{"limits":{"cpu":".5", "memory":"1000Mi"}}
chromeDebug.screenWidthnil
chromeDebug.screenHeightnil
chromeDebug.screenDepthnil
chromeDebug.displayThe vnc displaynil
chromeDebug.chromeVersionThe version of chrome to usenil
chromeDebug.nodeMaxInstancesThe maximum number of browser instancesnil
chromeDebug.nodeMaxSessionThe maximum number of sessionsnil
chromeDebug.nodeRegistryCycleThe number of milliseconds to wait, registering a nodenil
chromeDebug.nodePortThe port to listen onnil
chromeDebug.seOptsCommand line arguments to pass to nodenil
chromeDebug.timeZoneThe time zone for the containernil
chromeDebug.nodeselectorNode label to use for scheduling of chromeDebug images if set this takes precedence over the global valuenil
firefox.enabledSchedule a selenium node firefox podfalse
firefox.imageThe selenium node firefox imageselenium/node-firefox
firefox.tagThe selenium node firefox tag3.11.0
firefox.pullPolicyThe selenium node firefox pull policyIfNotPresent
firefox.replicasThe number of selenium node firefox pods1
firefox.javaOptsThe java options for a selenium node firefox JVM, default sets the max heap size to 900 mb-Xmx900m
firefox.resourcesThe resources for the hub container, defaults to minimum half a cpu and maximum 1,000 mb{"limits":{"cpu":".5", "memory":"1000Mi"}}
firefox.screenWidthnil
firefox.screenHeightnil
firefox.screenDepthnil
firefox.displayThe vnc displaynil
firefox.firefoxVersionThe version of firefox to usenil
firefox.nodeMaxInstancesThe maximum number of browser instancesnil
firefox.nodeMaxSessionThe maximum number of sessionsnil
firefox.nodeRegistryCycleThe number of milliseconds to wait, registering a nodenil
firefox.nodePortThe port to listen onnil
firefox.seOptsCommand line arguments to pass to nodenil
firefox.timeZoneThe time zone for the containernil
firefox.nodeselectorNode label to use for scheduling of firefox images if set this takes precedence over the global valuenil
firefoxDebug.enabledSchedule a selenium node firefox debug podfalse
firefoxDebug.imageThe selenium node firefox debug imageselenium/node-firefox-debug
firefoxDebug.tagThe selenium node firefox debug tag3.11.0
firefoxDebug.pullPolicyThe selenium node firefox debug pull policyIfNotPresent
firefoxDebug.replicasThe numer of selenium node firefox debug pods1
firefoxDebug.javaOptsThe java options for a selenium node firefox debug JVM, default sets the max heap size to 900 mb-Xmx900m
firefoxDebug.resourcesThe resources for the selenium node firefox debug container, defaults to minimum half a cpu and maximum 1,000 mb{"limits":{"cpu":".5", "memory":"1000Mi"}}
firefoxDebug.screenWidthnil
firefoxDebug.screenHeightnil
firefoxDebug.screenDepthnil
firefoxDebug.displayThe vnc displaynil
firefoxDebug.firefoxVersionThe version of firefox to usenil
firefoxDebug.nodeMaxInstancesThe maximum number of browser instancesnil
firefoxDebug.nodeMaxSessionThe maximum number of sessionsnil
firefoxDebug.nodeRegistryCycleThe number of milliseconds to wait, registering a nodenil
firefoxDebug.nodePortThe port to listen onnil
firefoxDebug.seOptsCommand line arguments to pass to nodenil
firefoxDebug.timeZoneThe time zone for the containernil
firefoxDebug.nodeselectorNode label to use for scheduling of firefoxDebug images if set this takes precedence over the global valuenil

Specify each parameter using the --set key=value[,key=value] argument to helm install. For example,

$ helm install --name my-release \ --set chrome.enabled=true \ stable/selenium

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Latest commit

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Running Selenium Grid on Kubernetes cluster

In this tutorial, I’ll show you how to get Selenium Grid up and running on Kubernetes cluster using Helm package manager.

Contents

  1. Prerequisites
  2. Selenium Grid
  3. Kubernetes
  4. Selenium-Grid Installation
  5. Run Selenium tests
  6. Debugging with VNC Viewer
  7. Deletes a release

Selenium Grid

Selenium Grid makes automation execution jobs much easier. Using Selenium Grid, one can run multiple tests on multiple machines in parallel, which reduces execution times from days to hours. However, setting up our own Selenium Grid means we have to configure browsers across multiple machines, virtual or physical, and making sure each machine is running the Selenium Server correctly. This also means maintaining the Grid and making updates would be a time-consuming. This is where Kubernetes comes in and saves the day!

Kubernetes

Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications.

Helm

Helm is a package manager for Kubernetes applications, responsible for installing and managing Kubernetes applications. Helm packages all of the different Kubernetes resources (such as deployments, services, and ingress) into a chart, which may be hosted in a repository. Users can pull down charts and install them on any number of Kubernetes clusters. This is similar to Homebrew and apt-get package manager. We will use Helm to deploy selenium-grid on Kubernetes Cluster.

What We’ll Accomplish
  1. Set up a Kubernetes cluster using Docker for Mac
  2. Deploy Selenium-Grid to the cluster
  3. Running selenium test and viewing your Selenium tests running on Kubernetes cluster

Prerequisites

  • kubectl - macOS users can use brew install kubectl to install
  • Docker for Mac - Docker with Kubernetes is currently only available on Docker for Mac in the latest Edge version
  • Virtualbox - macOS users can use brew cask install virtualbox to install
  • Helm - macOS users can use brew install kubernetes-helm to install

Verify the Installation

docker --version # Docker version 17.09.0-ce, build afdb6d4
docker-compose --version # docker-compose version 1.16.1, build 6d1ac21
docker-machine --version # docker-machine version 0.12.2, build 9371605
kubectl version --client # Client Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.1", GitCommit:"f38e43b221d08850172a9a4ea785a86a3ffa3b3a", GitTreeState:"clean", BuildDate:"2017-10-12T00:45:05Z", GoVersion:"go1.9.1", Compiler:"gc", Platform:"darwin/amd64"} helm version --client # Client: &version.Version{SemVer:"v2.9.0", GitCommit:"f6025bb9ee7daf9fee0026541c90a6f557a3e0bc", GitTreeState:"clean"}

Enabling the local Kubernetes cluster

Click the Docker icon in the status bar, go to “Preferences”, and on the “Kubernetes”-tab, check “Enable Kubernetes”. This will start a single node Kubernetes cluster for you and install the kubectl command line utility. This might take a while, but the dialog will let you know once the Kubernetes cluster is ready.

Next step, you’ll need to increase Docker’s available memory to 4GB or more.

Click the Docker icon in the status bar, go to “Preferences”, and on the “Advanced”-tab, change memoery to 4GB or more.

Selenium Grid installation

To install the chart with the release name selenium-grid:

helm install --name selenium-grid stable/selenium \
--set chromeDebug.enabled=true \
--set firefoxDebug.enabled=true

The command deploys Selenium Grid on the Kubernetes cluster in the default configuration with chromeDebug and firefoxDebug enabled.

Note: You should see the following output after executing helm install ...

NAME: selenium-grid
LAST DEPLOYED: Fri May 11 23:09:29 2018
NAMESPACE: default
STATUS: DEPLOYED
RESOURCES:
==> v1/Service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
selenium-grid-selenium-hub LoadBalancer 10.110.225.161 localhost 4444:30665/TCP 0s
==> v1beta1/Deployment
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
selenium-grid-selenium-chrome-debug 1 1 1 0 0s
selenium-grid-selenium-firefox-debug 1 1 1 0 0s
selenium-grid-selenium-hub 1 1 1 0 0s
==> v1/Pod(related)
NAME READY STATUS RESTARTS AGE
selenium-grid-selenium-chrome-debug-6d8898d7c4-7psdh 0/1 ContainerCreating 0 0s
selenium-grid-selenium-firefox-debug-84f6f484d8-wh66d 0/1 ContainerCreating 0 0s
selenium-grid-selenium-hub-f7f874cd-p5lrd 0/1 ContainerCreating 0 0s

Selenium hub will automatically start-up using port 4444 by default. You can view the status of the hub by opening a browser window and navigating to: http://localhost:4444/grid/console

Run Selenium Test

Let's run a quick Selenium test to validate our setup.

Clone this github repo:
git clone https://github.com/sayems/selenium.grid.git
Go into the project
$ cd selenium.grid
Run tests

Before you run docker-compose up, verify Selenium grid is up & running on Kubernetes cluster, you can verify by executing the following command: $ kubectl get pods

$ docker-compose up

It typically takes several minutes for docker setup for the first time, so wait for few minutes …

Debugging with VNC Viewer

It is useful to be able to view your Selenium tests running on Kubernetes cluster. This can help us to debug issues better and have more confidence in our tests. To view running tests on Kubernetes cluster.

  1. Download VNC® Viewer for Google Chrome
  2. Execute the following command to bind ports between Kubernetes cluster to the local machine:
 kubectl port-forward --namespace default \
$(kubectl get pods --namespace default \
-l app=selenium-grid-selenium-chrome-debug \
-o jsonpath='{ .items[0].metadata.name }') 5900
  1. Open VNC® Viewer for Google Chrome
    • Address: 127.0.0.1:5900
    • Password: secret

Deletes a release from Kubernetes

The helm list function will show you a list of all deployed releases.

$ helm list

List of all releases

NAME REVISION UPDATED STATUS CHART NAMESPACE
selenium-grid 1 Fri May DEPLOYED selenium default

If you want to delete selenium-grid, you can execute the following command

$ helm delete selenium-grid
release "selenium-grid" deleted

If you want to delete all Helm releases, you can pipe the output of helm ls --short to xargs, and run helm delete for each release name.

$ helm ls --short | xargs -L1 helm delete

Configuration

The following table lists the configurable parameters of the Selenium chart and their default values.

ParameterDescriptionDefault
global.nodeselectorNode label to be useed globally for scheduling of all imagesnil
hub.imageThe selenium hub imageselenium/hub
hub.tagThe selenium hub image tag3.11.0
hub.pullPolicyThe pull policy for the hub imageIfNotPresent
hub.portThe port the hub listens on4444
hub.javaOptsThe java options for the selenium hub JVM, default sets the maximum heap size to 1,000 mb-Xmx1000m
hub.resourcesThe resources for the hub container, defaults to minimum half a cpu and maximum 1,000 mb RAM{"limits":{"cpu":".5", "memory":"1000Mi"}}
hub.serviceTypeThe Service typeNodePort
hub.serviceSessionAffinityThe session affinity for the hub serviceNone
hub.gridNewSessionWaitTimeoutnil
hub.gridJettyMaxThreadsnil
hub.gridNodePollingnil
hub.gridCleanUpCyclenil
hub.gridTimeoutnil
hub.gridBrowserTimeoutnil
hub.gridMaxSessionnil
hub.gridUnregisterIfStillDownAfernil
hub.seOptsCommand line arguments to pass to hubnil
hub.timeZoneThe time zone for the containernil
hub.nodeselectorNode label to use for scheduling of the hub if set this takes precedence over the global valuenil
chrome.enabledSchedule a chrome node podfalse
chrome.imageThe selenium node chrome imageselenium/node-chrome
chrome.tagThe selenium node chrome tag3.11.0
chrome.pullPolicyThe pull policy for the node chrome imageIfNotPresent
chrome.replicasThe number of selenium node chrome pods1
chrome.javaOptsThe java options for the selenium node chrome JVM, default sets the maximum heap size to 900 mb-Xmx900m
chrome.volumeMountsAdditional volumes to mount, the default provides a larger shared memory[{"mountPath":"/dev/shm", "name":"dshm"}]
chrome.volumesAdditional volumes import, the default provides a larger shared memory[{"name":"dshm", "emptyDir":{"medium":"Memory"}}]
chrome.resourcesThe resources for the node chrome container, defaults to minimum half a cpu and maximum 1,000 mb{"limits":{"cpu":".5", "memory":"1000Mi"}}
chrome.screenWidthnil
chrome.screenHeightnil
chrome.screenDepthnil
chrome.displayThe vnc displaynil
chrome.chromeVersionThe version of chrome to usenil
chrome.nodeMaxInstancesThe maximum number of browser instancesnil
chrome.nodeMaxSessionThe maximum number of sessionsnil
chrome.nodeRegistryCycleThe number of milliseconds to wait, registering a nodenil
chrome.nodePortThe port to listen onnil
chrome.seOptsCommand line arguments to pass to nodenil
chrome.timeZoneThe time zone for the containernil
chrome.nodeselectorNode label to use for scheduling of chrome images if set this takes precedence over the global valuenil
chromeDebug.enabledSchedule a selenium node chrome debug podfalse
chromeDebug.imageThe selenium node chrome debug imageselenium/node-chrome-debug
chromeDebug.tagThe selenium node chrome debug tag3.11.0
chromeDebug.pullPolicyThe selenium node chrome debug pull policyIfNotPresent
chromeDebug.replicasThe number of selenium node chrome debug pods1
chromeDebug.javaOptsThe java options for a selenium node chrome debug JVM, default sets the max heap size to 900 mb-Xmx900m
chromeDebug.volumeMountsAdditional volumes to mount, the default provides a larger shared[{"mountPath":"/dev/shm", "name":"dshm"}]
chromeDebug.volumesAdditional volumes import, the default provides a larger shared[{"name":"dshm", "emptyDir":{"medium":"Memory"}}]
chromeDebug.resourcesThe resources for the hub container, defaults to minimum half a cpu and maximum 1,000 mb{"limits":{"cpu":".5", "memory":"1000Mi"}}
chromeDebug.screenWidthnil
chromeDebug.screenHeightnil
chromeDebug.screenDepthnil
chromeDebug.displayThe vnc displaynil
chromeDebug.chromeVersionThe version of chrome to usenil
chromeDebug.nodeMaxInstancesThe maximum number of browser instancesnil
chromeDebug.nodeMaxSessionThe maximum number of sessionsnil
chromeDebug.nodeRegistryCycleThe number of milliseconds to wait, registering a nodenil
chromeDebug.nodePortThe port to listen onnil
chromeDebug.seOptsCommand line arguments to pass to nodenil
chromeDebug.timeZoneThe time zone for the containernil
chromeDebug.nodeselectorNode label to use for scheduling of chromeDebug images if set this takes precedence over the global valuenil
firefox.enabledSchedule a selenium node firefox podfalse
firefox.imageThe selenium node firefox imageselenium/node-firefox
firefox.tagThe selenium node firefox tag3.11.0
firefox.pullPolicyThe selenium node firefox pull policyIfNotPresent
firefox.replicasThe number of selenium node firefox pods1
firefox.javaOptsThe java options for a selenium node firefox JVM, default sets the max heap size to 900 mb-Xmx900m
firefox.resourcesThe resources for the hub container, defaults to minimum half a cpu and maximum 1,000 mb{"limits":{"cpu":".5", "memory":"1000Mi"}}
firefox.screenWidthnil
firefox.screenHeightnil
firefox.screenDepthnil
firefox.displayThe vnc displaynil
firefox.firefoxVersionThe version of firefox to usenil
firefox.nodeMaxInstancesThe maximum number of browser instancesnil
firefox.nodeMaxSessionThe maximum number of sessionsnil
firefox.nodeRegistryCycleThe number of milliseconds to wait, registering a nodenil
firefox.nodePortThe port to listen onnil
firefox.seOptsCommand line arguments to pass to nodenil
firefox.timeZoneThe time zone for the containernil
firefox.nodeselectorNode label to use for scheduling of firefox images if set this takes precedence over the global valuenil
firefoxDebug.enabledSchedule a selenium node firefox debug podfalse
firefoxDebug.imageThe selenium node firefox debug imageselenium/node-firefox-debug
firefoxDebug.tagThe selenium node firefox debug tag3.11.0
firefoxDebug.pullPolicyThe selenium node firefox debug pull policyIfNotPresent
firefoxDebug.replicasThe numer of selenium node firefox debug pods1
firefoxDebug.javaOptsThe java options for a selenium node firefox debug JVM, default sets the max heap size to 900 mb-Xmx900m
firefoxDebug.resourcesThe resources for the selenium node firefox debug container, defaults to minimum half a cpu and maximum 1,000 mb{"limits":{"cpu":".5", "memory":"1000Mi"}}
firefoxDebug.screenWidthnil
firefoxDebug.screenHeightnil
firefoxDebug.screenDepthnil
firefoxDebug.displayThe vnc displaynil
firefoxDebug.firefoxVersionThe version of firefox to usenil
firefoxDebug.nodeMaxInstancesThe maximum number of browser instancesnil
firefoxDebug.nodeMaxSessionThe maximum number of sessionsnil
firefoxDebug.nodeRegistryCycleThe number of milliseconds to wait, registering a nodenil
firefoxDebug.nodePortThe port to listen onnil
firefoxDebug.seOptsCommand line arguments to pass to nodenil
firefoxDebug.timeZoneThe time zone for the containernil
firefoxDebug.nodeselectorNode label to use for scheduling of firefoxDebug images if set this takes precedence over the global valuenil

Specify each parameter using the --set key=value[,key=value] argument to helm install. For example,

$ helm install --name my-release \ --set chrome.enabled=true \ stable/selenium

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Latest commit

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Running Selenium Grid on Kubernetes cluster

In this tutorial, I’ll show you how to get Selenium Grid up and running on Kubernetes cluster using Helm package manager.

Contents

  1. Prerequisites
  2. Selenium Grid
  3. Kubernetes
  4. Selenium-Grid Installation
  5. Run Selenium tests
  6. Debugging with VNC Viewer
  7. Deletes a release

Selenium Grid

Selenium Grid makes automation execution jobs much easier. Using Selenium Grid, one can run multiple tests on multiple machines in parallel, which reduces execution times from days to hours. However, setting up our own Selenium Grid means we have to configure browsers across multiple machines, virtual or physical, and making sure each machine is running the Selenium Server correctly. This also means maintaining the Grid and making updates would be a time-consuming. This is where Kubernetes comes in and saves the day!

Kubernetes

Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications.

Helm

Helm is a package manager for Kubernetes applications, responsible for installing and managing Kubernetes applications. Helm packages all of the different Kubernetes resources (such as deployments, services, and ingress) into a chart, which may be hosted in a repository. Users can pull down charts and install them on any number of Kubernetes clusters. This is similar to Homebrew and apt-get package manager. We will use Helm to deploy selenium-grid on Kubernetes Cluster.

What We’ll Accomplish
  1. Set up a Kubernetes cluster using Docker for Mac
  2. Deploy Selenium-Grid to the cluster
  3. Running selenium test and viewing your Selenium tests running on Kubernetes cluster

Prerequisites

  • kubectl - macOS users can use brew install kubectl to install
  • Docker for Mac - Docker with Kubernetes is currently only available on Docker for Mac in the latest Edge version
  • Virtualbox - macOS users can use brew cask install virtualbox to install
  • Helm - macOS users can use brew install kubernetes-helm to install

Verify the Installation

docker --version # Docker version 17.09.0-ce, build afdb6d4
docker-compose --version # docker-compose version 1.16.1, build 6d1ac21
docker-machine --version # docker-machine version 0.12.2, build 9371605
kubectl version --client # Client Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.1", GitCommit:"f38e43b221d08850172a9a4ea785a86a3ffa3b3a", GitTreeState:"clean", BuildDate:"2017-10-12T00:45:05Z", GoVersion:"go1.9.1", Compiler:"gc", Platform:"darwin/amd64"} helm version --client # Client: &version.Version{SemVer:"v2.9.0", GitCommit:"f6025bb9ee7daf9fee0026541c90a6f557a3e0bc", GitTreeState:"clean"}

Enabling the local Kubernetes cluster

Click the Docker icon in the status bar, go to “Preferences”, and on the “Kubernetes”-tab, check “Enable Kubernetes”. This will start a single node Kubernetes cluster for you and install the kubectl command line utility. This might take a while, but the dialog will let you know once the Kubernetes cluster is ready.

Next step, you’ll need to increase Docker’s available memory to 4GB or more.

Click the Docker icon in the status bar, go to “Preferences”, and on the “Advanced”-tab, change memoery to 4GB or more.

Selenium Grid installation

To install the chart with the release name selenium-grid:

helm install --name selenium-grid stable/selenium \
--set chromeDebug.enabled=true \
--set firefoxDebug.enabled=true

The command deploys Selenium Grid on the Kubernetes cluster in the default configuration with chromeDebug and firefoxDebug enabled.

Note: You should see the following output after executing helm install ...

NAME: selenium-grid
LAST DEPLOYED: Fri May 11 23:09:29 2018
NAMESPACE: default
STATUS: DEPLOYED
RESOURCES:
==> v1/Service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
selenium-grid-selenium-hub LoadBalancer 10.110.225.161 localhost 4444:30665/TCP 0s
==> v1beta1/Deployment
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
selenium-grid-selenium-chrome-debug 1 1 1 0 0s
selenium-grid-selenium-firefox-debug 1 1 1 0 0s
selenium-grid-selenium-hub 1 1 1 0 0s
==> v1/Pod(related)
NAME READY STATUS RESTARTS AGE
selenium-grid-selenium-chrome-debug-6d8898d7c4-7psdh 0/1 ContainerCreating 0 0s
selenium-grid-selenium-firefox-debug-84f6f484d8-wh66d 0/1 ContainerCreating 0 0s
selenium-grid-selenium-hub-f7f874cd-p5lrd 0/1 ContainerCreating 0 0s

Selenium hub will automatically start-up using port 4444 by default. You can view the status of the hub by opening a browser window and navigating to: http://localhost:4444/grid/console

Run Selenium Test

Let's run a quick Selenium test to validate our setup.

Clone this github repo:
git clone https://github.com/sayems/selenium.grid.git
Go into the project
$ cd selenium.grid
Run tests

Before you run docker-compose up, verify Selenium grid is up & running on Kubernetes cluster, you can verify by executing the following command: $ kubectl get pods

$ docker-compose up

It typically takes several minutes for docker setup for the first time, so wait for few minutes …

Debugging with VNC Viewer

It is useful to be able to view your Selenium tests running on Kubernetes cluster. This can help us to debug issues better and have more confidence in our tests. To view running tests on Kubernetes cluster.

  1. Download VNC® Viewer for Google Chrome
  2. Execute the following command to bind ports between Kubernetes cluster to the local machine:
 kubectl port-forward --namespace default \
$(kubectl get pods --namespace default \
-l app=selenium-grid-selenium-chrome-debug \
-o jsonpath='{ .items[0].metadata.name }') 5900
  1. Open VNC® Viewer for Google Chrome
    • Address: 127.0.0.1:5900
    • Password: secret

Deletes a release from Kubernetes

The helm list function will show you a list of all deployed releases.

$ helm list

List of all releases

NAME REVISION UPDATED STATUS CHART NAMESPACE
selenium-grid 1 Fri May DEPLOYED selenium default

If you want to delete selenium-grid, you can execute the following command

$ helm delete selenium-grid
release "selenium-grid" deleted

If you want to delete all Helm releases, you can pipe the output of helm ls --short to xargs, and run helm delete for each release name.

$ helm ls --short | xargs -L1 helm delete

Configuration

The following table lists the configurable parameters of the Selenium chart and their default values.

ParameterDescriptionDefault
global.nodeselectorNode label to be useed globally for scheduling of all imagesnil
hub.imageThe selenium hub imageselenium/hub
hub.tagThe selenium hub image tag3.11.0
hub.pullPolicyThe pull policy for the hub imageIfNotPresent
hub.portThe port the hub listens on4444
hub.javaOptsThe java options for the selenium hub JVM, default sets the maximum heap size to 1,000 mb-Xmx1000m
hub.resourcesThe resources for the hub container, defaults to minimum half a cpu and maximum 1,000 mb RAM{"limits":{"cpu":".5", "memory":"1000Mi"}}
hub.serviceTypeThe Service typeNodePort
hub.serviceSessionAffinityThe session affinity for the hub serviceNone
hub.gridNewSessionWaitTimeoutnil
hub.gridJettyMaxThreadsnil
hub.gridNodePollingnil
hub.gridCleanUpCyclenil
hub.gridTimeoutnil
hub.gridBrowserTimeoutnil
hub.gridMaxSessionnil
hub.gridUnregisterIfStillDownAfernil
hub.seOptsCommand line arguments to pass to hubnil
hub.timeZoneThe time zone for the containernil
hub.nodeselectorNode label to use for scheduling of the hub if set this takes precedence over the global valuenil
chrome.enabledSchedule a chrome node podfalse
chrome.imageThe selenium node chrome imageselenium/node-chrome
chrome.tagThe selenium node chrome tag3.11.0
chrome.pullPolicyThe pull policy for the node chrome imageIfNotPresent
chrome.replicasThe number of selenium node chrome pods1
chrome.javaOptsThe java options for the selenium node chrome JVM, default sets the maximum heap size to 900 mb-Xmx900m
chrome.volumeMountsAdditional volumes to mount, the default provides a larger shared memory[{"mountPath":"/dev/shm", "name":"dshm"}]
chrome.volumesAdditional volumes import, the default provides a larger shared memory[{"name":"dshm", "emptyDir":{"medium":"Memory"}}]
chrome.resourcesThe resources for the node chrome container, defaults to minimum half a cpu and maximum 1,000 mb{"limits":{"cpu":".5", "memory":"1000Mi"}}
chrome.screenWidthnil
chrome.screenHeightnil
chrome.screenDepthnil
chrome.displayThe vnc displaynil
chrome.chromeVersionThe version of chrome to usenil
chrome.nodeMaxInstancesThe maximum number of browser instancesnil
chrome.nodeMaxSessionThe maximum number of sessionsnil
chrome.nodeRegistryCycleThe number of milliseconds to wait, registering a nodenil
chrome.nodePortThe port to listen onnil
chrome.seOptsCommand line arguments to pass to nodenil
chrome.timeZoneThe time zone for the containernil
chrome.nodeselectorNode label to use for scheduling of chrome images if set this takes precedence over the global valuenil
chromeDebug.enabledSchedule a selenium node chrome debug podfalse
chromeDebug.imageThe selenium node chrome debug imageselenium/node-chrome-debug
chromeDebug.tagThe selenium node chrome debug tag3.11.0
chromeDebug.pullPolicyThe selenium node chrome debug pull policyIfNotPresent
chromeDebug.replicasThe number of selenium node chrome debug pods1
chromeDebug.javaOptsThe java options for a selenium node chrome debug JVM, default sets the max heap size to 900 mb-Xmx900m
chromeDebug.volumeMountsAdditional volumes to mount, the default provides a larger shared[{"mountPath":"/dev/shm", "name":"dshm"}]
chromeDebug.volumesAdditional volumes import, the default provides a larger shared[{"name":"dshm", "emptyDir":{"medium":"Memory"}}]
chromeDebug.resourcesThe resources for the hub container, defaults to minimum half a cpu and maximum 1,000 mb{"limits":{"cpu":".5", "memory":"1000Mi"}}
chromeDebug.screenWidthnil
chromeDebug.screenHeightnil
chromeDebug.screenDepthnil
chromeDebug.displayThe vnc displaynil
chromeDebug.chromeVersionThe version of chrome to usenil
chromeDebug.nodeMaxInstancesThe maximum number of browser instancesnil
chromeDebug.nodeMaxSessionThe maximum number of sessionsnil
chromeDebug.nodeRegistryCycleThe number of milliseconds to wait, registering a nodenil
chromeDebug.nodePortThe port to listen onnil
chromeDebug.seOptsCommand line arguments to pass to nodenil
chromeDebug.timeZoneThe time zone for the containernil
chromeDebug.nodeselectorNode label to use for scheduling of chromeDebug images if set this takes precedence over the global valuenil
firefox.enabledSchedule a selenium node firefox podfalse
firefox.imageThe selenium node firefox imageselenium/node-firefox
firefox.tagThe selenium node firefox tag3.11.0
firefox.pullPolicyThe selenium node firefox pull policyIfNotPresent
firefox.replicasThe number of selenium node firefox pods1
firefox.javaOptsThe java options for a selenium node firefox JVM, default sets the max heap size to 900 mb-Xmx900m
firefox.resourcesThe resources for the hub container, defaults to minimum half a cpu and maximum 1,000 mb{"limits":{"cpu":".5", "memory":"1000Mi"}}
firefox.screenWidthnil
firefox.screenHeightnil
firefox.screenDepthnil
firefox.displayThe vnc displaynil
firefox.firefoxVersionThe version of firefox to usenil
firefox.nodeMaxInstancesThe maximum number of browser instancesnil
firefox.nodeMaxSessionThe maximum number of sessionsnil
firefox.nodeRegistryCycleThe number of milliseconds to wait, registering a nodenil
firefox.nodePortThe port to listen onnil
firefox.seOptsCommand line arguments to pass to nodenil
firefox.timeZoneThe time zone for the containernil
firefox.nodeselectorNode label to use for scheduling of firefox images if set this takes precedence over the global valuenil
firefoxDebug.enabledSchedule a selenium node firefox debug podfalse
firefoxDebug.imageThe selenium node firefox debug imageselenium/node-firefox-debug
firefoxDebug.tagThe selenium node firefox debug tag3.11.0
firefoxDebug.pullPolicyThe selenium node firefox debug pull policyIfNotPresent
firefoxDebug.replicasThe numer of selenium node firefox debug pods1
firefoxDebug.javaOptsThe java options for a selenium node firefox debug JVM, default sets the max heap size to 900 mb-Xmx900m
firefoxDebug.resourcesThe resources for the selenium node firefox debug container, defaults to minimum half a cpu and maximum 1,000 mb{"limits":{"cpu":".5", "memory":"1000Mi"}}
firefoxDebug.screenWidthnil
firefoxDebug.screenHeightnil
firefoxDebug.screenDepthnil
firefoxDebug.displayThe vnc displaynil
firefoxDebug.firefoxVersionThe version of firefox to usenil
firefoxDebug.nodeMaxInstancesThe maximum number of browser instancesnil
firefoxDebug.nodeMaxSessionThe maximum number of sessionsnil
firefoxDebug.nodeRegistryCycleThe number of milliseconds to wait, registering a nodenil
firefoxDebug.nodePortThe port to listen onnil
firefoxDebug.seOptsCommand line arguments to pass to nodenil
firefoxDebug.timeZoneThe time zone for the containernil
firefoxDebug.nodeselectorNode label to use for scheduling of firefoxDebug images if set this takes precedence over the global valuenil

Specify each parameter using the --set key=value[,key=value] argument to helm install. For example,

$ helm install --name my-release \ --set chrome.enabled=true \ stable/selenium

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Latest commit

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Running Selenium Grid on Kubernetes cluster

In this tutorial, I’ll show you how to get Selenium Grid up and running on Kubernetes cluster using Helm package manager.

Contents

  1. Prerequisites
  2. Selenium Grid
  3. Kubernetes
  4. Selenium-Grid Installation
  5. Run Selenium tests
  6. Debugging with VNC Viewer
  7. Deletes a release

Selenium Grid

Selenium Grid makes automation execution jobs much easier. Using Selenium Grid, one can run multiple tests on multiple machines in parallel, which reduces execution times from days to hours. However, setting up our own Selenium Grid means we have to configure browsers across multiple machines, virtual or physical, and making sure each machine is running the Selenium Server correctly. This also means maintaining the Grid and making updates would be a time-consuming. This is where Kubernetes comes in and saves the day!

Kubernetes

Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications.

Helm

Helm is a package manager for Kubernetes applications, responsible for installing and managing Kubernetes applications. Helm packages all of the different Kubernetes resources (such as deployments, services, and ingress) into a chart, which may be hosted in a repository. Users can pull down charts and install them on any number of Kubernetes clusters. This is similar to Homebrew and apt-get package manager. We will use Helm to deploy selenium-grid on Kubernetes Cluster.

What We’ll Accomplish
  1. Set up a Kubernetes cluster using Docker for Mac
  2. Deploy Selenium-Grid to the cluster
  3. Running selenium test and viewing your Selenium tests running on Kubernetes cluster

Prerequisites

  • kubectl - macOS users can use brew install kubectl to install
  • Docker for Mac - Docker with Kubernetes is currently only available on Docker for Mac in the latest Edge version
  • Virtualbox - macOS users can use brew cask install virtualbox to install
  • Helm - macOS users can use brew install kubernetes-helm to install

Verify the Installation

docker --version # Docker version 17.09.0-ce, build afdb6d4
docker-compose --version # docker-compose version 1.16.1, build 6d1ac21
docker-machine --version # docker-machine version 0.12.2, build 9371605
kubectl version --client # Client Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.1", GitCommit:"f38e43b221d08850172a9a4ea785a86a3ffa3b3a", GitTreeState:"clean", BuildDate:"2017-10-12T00:45:05Z", GoVersion:"go1.9.1", Compiler:"gc", Platform:"darwin/amd64"} helm version --client # Client: &version.Version{SemVer:"v2.9.0", GitCommit:"f6025bb9ee7daf9fee0026541c90a6f557a3e0bc", GitTreeState:"clean"}

Enabling the local Kubernetes cluster

Click the Docker icon in the status bar, go to “Preferences”, and on the “Kubernetes”-tab, check “Enable Kubernetes”. This will start a single node Kubernetes cluster for you and install the kubectl command line utility. This might take a while, but the dialog will let you know once the Kubernetes cluster is ready.

Next step, you’ll need to increase Docker’s available memory to 4GB or more.

Click the Docker icon in the status bar, go to “Preferences”, and on the “Advanced”-tab, change memoery to 4GB or more.

Selenium Grid installation

To install the chart with the release name selenium-grid:

helm install --name selenium-grid stable/selenium \
--set chromeDebug.enabled=true \
--set firefoxDebug.enabled=true

The command deploys Selenium Grid on the Kubernetes cluster in the default configuration with chromeDebug and firefoxDebug enabled.

Note: You should see the following output after executing helm install ...

NAME: selenium-grid
LAST DEPLOYED: Fri May 11 23:09:29 2018
NAMESPACE: default
STATUS: DEPLOYED
RESOURCES:
==> v1/Service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
selenium-grid-selenium-hub LoadBalancer 10.110.225.161 localhost 4444:30665/TCP 0s
==> v1beta1/Deployment
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
selenium-grid-selenium-chrome-debug 1 1 1 0 0s
selenium-grid-selenium-firefox-debug 1 1 1 0 0s
selenium-grid-selenium-hub 1 1 1 0 0s
==> v1/Pod(related)
NAME READY STATUS RESTARTS AGE
selenium-grid-selenium-chrome-debug-6d8898d7c4-7psdh 0/1 ContainerCreating 0 0s
selenium-grid-selenium-firefox-debug-84f6f484d8-wh66d 0/1 ContainerCreating 0 0s
selenium-grid-selenium-hub-f7f874cd-p5lrd 0/1 ContainerCreating 0 0s

Selenium hub will automatically start-up using port 4444 by default. You can view the status of the hub by opening a browser window and navigating to: http://localhost:4444/grid/console

Run Selenium Test

Let's run a quick Selenium test to validate our setup.

Clone this github repo:
git clone https://github.com/sayems/selenium.grid.git
Go into the project
$ cd selenium.grid
Run tests

Before you run docker-compose up, verify Selenium grid is up & running on Kubernetes cluster, you can verify by executing the following command: $ kubectl get pods

$ docker-compose up

It typically takes several minutes for docker setup for the first time, so wait for few minutes …

Debugging with VNC Viewer

It is useful to be able to view your Selenium tests running on Kubernetes cluster. This can help us to debug issues better and have more confidence in our tests. To view running tests on Kubernetes cluster.

  1. Download VNC® Viewer for Google Chrome
  2. Execute the following command to bind ports between Kubernetes cluster to the local machine:
 kubectl port-forward --namespace default \
$(kubectl get pods --namespace default \
-l app=selenium-grid-selenium-chrome-debug \
-o jsonpath='{ .items[0].metadata.name }') 5900
  1. Open VNC® Viewer for Google Chrome
    • Address: 127.0.0.1:5900
    • Password: secret

Deletes a release from Kubernetes

The helm list function will show you a list of all deployed releases.

$ helm list

List of all releases

NAME REVISION UPDATED STATUS CHART NAMESPACE
selenium-grid 1 Fri May DEPLOYED selenium default

If you want to delete selenium-grid, you can execute the following command

$ helm delete selenium-grid
release "selenium-grid" deleted

If you want to delete all Helm releases, you can pipe the output of helm ls --short to xargs, and run helm delete for each release name.

$ helm ls --short | xargs -L1 helm delete

Configuration

The following table lists the configurable parameters of the Selenium chart and their default values.

ParameterDescriptionDefault
global.nodeselectorNode label to be useed globally for scheduling of all imagesnil
hub.imageThe selenium hub imageselenium/hub
hub.tagThe selenium hub image tag3.11.0
hub.pullPolicyThe pull policy for the hub imageIfNotPresent
hub.portThe port the hub listens on4444
hub.javaOptsThe java options for the selenium hub JVM, default sets the maximum heap size to 1,000 mb-Xmx1000m
hub.resourcesThe resources for the hub container, defaults to minimum half a cpu and maximum 1,000 mb RAM{"limits":{"cpu":".5", "memory":"1000Mi"}}
hub.serviceTypeThe Service typeNodePort
hub.serviceSessionAffinityThe session affinity for the hub serviceNone
hub.gridNewSessionWaitTimeoutnil
hub.gridJettyMaxThreadsnil
hub.gridNodePollingnil
hub.gridCleanUpCyclenil
hub.gridTimeoutnil
hub.gridBrowserTimeoutnil
hub.gridMaxSessionnil
hub.gridUnregisterIfStillDownAfernil
hub.seOptsCommand line arguments to pass to hubnil
hub.timeZoneThe time zone for the containernil
hub.nodeselectorNode label to use for scheduling of the hub if set this takes precedence over the global valuenil
chrome.enabledSchedule a chrome node podfalse
chrome.imageThe selenium node chrome imageselenium/node-chrome
chrome.tagThe selenium node chrome tag3.11.0
chrome.pullPolicyThe pull policy for the node chrome imageIfNotPresent
chrome.replicasThe number of selenium node chrome pods1
chrome.javaOptsThe java options for the selenium node chrome JVM, default sets the maximum heap size to 900 mb-Xmx900m
chrome.volumeMountsAdditional volumes to mount, the default provides a larger shared memory[{"mountPath":"/dev/shm", "name":"dshm"}]
chrome.volumesAdditional volumes import, the default provides a larger shared memory[{"name":"dshm", "emptyDir":{"medium":"Memory"}}]
chrome.resourcesThe resources for the node chrome container, defaults to minimum half a cpu and maximum 1,000 mb{"limits":{"cpu":".5", "memory":"1000Mi"}}
chrome.screenWidthnil
chrome.screenHeightnil
chrome.screenDepthnil
chrome.displayThe vnc displaynil
chrome.chromeVersionThe version of chrome to usenil
chrome.nodeMaxInstancesThe maximum number of browser instancesnil
chrome.nodeMaxSessionThe maximum number of sessionsnil
chrome.nodeRegistryCycleThe number of milliseconds to wait, registering a nodenil
chrome.nodePortThe port to listen onnil
chrome.seOptsCommand line arguments to pass to nodenil
chrome.timeZoneThe time zone for the containernil
chrome.nodeselectorNode label to use for scheduling of chrome images if set this takes precedence over the global valuenil
chromeDebug.enabledSchedule a selenium node chrome debug podfalse
chromeDebug.imageThe selenium node chrome debug imageselenium/node-chrome-debug
chromeDebug.tagThe selenium node chrome debug tag3.11.0
chromeDebug.pullPolicyThe selenium node chrome debug pull policyIfNotPresent
chromeDebug.replicasThe number of selenium node chrome debug pods1
chromeDebug.javaOptsThe java options for a selenium node chrome debug JVM, default sets the max heap size to 900 mb-Xmx900m
chromeDebug.volumeMountsAdditional volumes to mount, the default provides a larger shared[{"mountPath":"/dev/shm", "name":"dshm"}]
chromeDebug.volumesAdditional volumes import, the default provides a larger shared[{"name":"dshm", "emptyDir":{"medium":"Memory"}}]
chromeDebug.resourcesThe resources for the hub container, defaults to minimum half a cpu and maximum 1,000 mb{"limits":{"cpu":".5", "memory":"1000Mi"}}
chromeDebug.screenWidthnil
chromeDebug.screenHeightnil
chromeDebug.screenDepthnil
chromeDebug.displayThe vnc displaynil
chromeDebug.chromeVersionThe version of chrome to usenil
chromeDebug.nodeMaxInstancesThe maximum number of browser instancesnil
chromeDebug.nodeMaxSessionThe maximum number of sessionsnil
chromeDebug.nodeRegistryCycleThe number of milliseconds to wait, registering a nodenil
chromeDebug.nodePortThe port to listen onnil
chromeDebug.seOptsCommand line arguments to pass to nodenil
chromeDebug.timeZoneThe time zone for the containernil
chromeDebug.nodeselectorNode label to use for scheduling of chromeDebug images if set this takes precedence over the global valuenil
firefox.enabledSchedule a selenium node firefox podfalse
firefox.imageThe selenium node firefox imageselenium/node-firefox
firefox.tagThe selenium node firefox tag3.11.0
firefox.pullPolicyThe selenium node firefox pull policyIfNotPresent
firefox.replicasThe number of selenium node firefox pods1
firefox.javaOptsThe java options for a selenium node firefox JVM, default sets the max heap size to 900 mb-Xmx900m
firefox.resourcesThe resources for the hub container, defaults to minimum half a cpu and maximum 1,000 mb{"limits":{"cpu":".5", "memory":"1000Mi"}}
firefox.screenWidthnil
firefox.screenHeightnil
firefox.screenDepthnil
firefox.displayThe vnc displaynil
firefox.firefoxVersionThe version of firefox to usenil
firefox.nodeMaxInstancesThe maximum number of browser instancesnil
firefox.nodeMaxSessionThe maximum number of sessionsnil
firefox.nodeRegistryCycleThe number of milliseconds to wait, registering a nodenil
firefox.nodePortThe port to listen onnil
firefox.seOptsCommand line arguments to pass to nodenil
firefox.timeZoneThe time zone for the containernil
firefox.nodeselectorNode label to use for scheduling of firefox images if set this takes precedence over the global valuenil
firefoxDebug.enabledSchedule a selenium node firefox debug podfalse
firefoxDebug.imageThe selenium node firefox debug imageselenium/node-firefox-debug
firefoxDebug.tagThe selenium node firefox debug tag3.11.0
firefoxDebug.pullPolicyThe selenium node firefox debug pull policyIfNotPresent
firefoxDebug.replicasThe numer of selenium node firefox debug pods1
firefoxDebug.javaOptsThe java options for a selenium node firefox debug JVM, default sets the max heap size to 900 mb-Xmx900m
firefoxDebug.resourcesThe resources for the selenium node firefox debug container, defaults to minimum half a cpu and maximum 1,000 mb{"limits":{"cpu":".5", "memory":"1000Mi"}}
firefoxDebug.screenWidthnil
firefoxDebug.screenHeightnil
firefoxDebug.screenDepthnil
firefoxDebug.displayThe vnc displaynil
firefoxDebug.firefoxVersionThe version of firefox to usenil
firefoxDebug.nodeMaxInstancesThe maximum number of browser instancesnil
firefoxDebug.nodeMaxSessionThe maximum number of sessionsnil
firefoxDebug.nodeRegistryCycleThe number of milliseconds to wait, registering a nodenil
firefoxDebug.nodePortThe port to listen onnil
firefoxDebug.seOptsCommand line arguments to pass to nodenil
firefoxDebug.timeZoneThe time zone for the containernil
firefoxDebug.nodeselectorNode label to use for scheduling of firefoxDebug images if set this takes precedence over the global valuenil

Specify each parameter using the --set key=value[,key=value] argument to helm install. For example,

$ helm install --name my-release \ --set chrome.enabled=true \ stable/selenium

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Latest commit

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Running Selenium Grid on Kubernetes cluster

In this tutorial, I’ll show you how to get Selenium Grid up and running on Kubernetes cluster using Helm package manager.

Contents

  1. Prerequisites
  2. Selenium Grid
  3. Kubernetes
  4. Selenium-Grid Installation
  5. Run Selenium tests
  6. Debugging with VNC Viewer
  7. Deletes a release

Selenium Grid

Selenium Grid makes automation execution jobs much easier. Using Selenium Grid, one can run multiple tests on multiple machines in parallel, which reduces execution times from days to hours. However, setting up our own Selenium Grid means we have to configure browsers across multiple machines, virtual or physical, and making sure each machine is running the Selenium Server correctly. This also means maintaining the Grid and making updates would be a time-consuming. This is where Kubernetes comes in and saves the day!

Kubernetes

Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications.

Helm

Helm is a package manager for Kubernetes applications, responsible for installing and managing Kubernetes applications. Helm packages all of the different Kubernetes resources (such as deployments, services, and ingress) into a chart, which may be hosted in a repository. Users can pull down charts and install them on any number of Kubernetes clusters. This is similar to Homebrew and apt-get package manager. We will use Helm to deploy selenium-grid on Kubernetes Cluster.

What We’ll Accomplish
  1. Set up a Kubernetes cluster using Docker for Mac
  2. Deploy Selenium-Grid to the cluster
  3. Running selenium test and viewing your Selenium tests running on Kubernetes cluster

Prerequisites

  • kubectl - macOS users can use brew install kubectl to install
  • Docker for Mac - Docker with Kubernetes is currently only available on Docker for Mac in the latest Edge version
  • Virtualbox - macOS users can use brew cask install virtualbox to install
  • Helm - macOS users can use brew install kubernetes-helm to install

Verify the Installation

docker --version # Docker version 17.09.0-ce, build afdb6d4
docker-compose --version # docker-compose version 1.16.1, build 6d1ac21
docker-machine --version # docker-machine version 0.12.2, build 9371605
kubectl version --client # Client Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.1", GitCommit:"f38e43b221d08850172a9a4ea785a86a3ffa3b3a", GitTreeState:"clean", BuildDate:"2017-10-12T00:45:05Z", GoVersion:"go1.9.1", Compiler:"gc", Platform:"darwin/amd64"} helm version --client # Client: &version.Version{SemVer:"v2.9.0", GitCommit:"f6025bb9ee7daf9fee0026541c90a6f557a3e0bc", GitTreeState:"clean"}

Enabling the local Kubernetes cluster

Click the Docker icon in the status bar, go to “Preferences”, and on the “Kubernetes”-tab, check “Enable Kubernetes”. This will start a single node Kubernetes cluster for you and install the kubectl command line utility. This might take a while, but the dialog will let you know once the Kubernetes cluster is ready.

Next step, you’ll need to increase Docker’s available memory to 4GB or more.

Click the Docker icon in the status bar, go to “Preferences”, and on the “Advanced”-tab, change memoery to 4GB or more.

Selenium Grid installation

To install the chart with the release name selenium-grid:

helm install --name selenium-grid stable/selenium \
--set chromeDebug.enabled=true \
--set firefoxDebug.enabled=true

The command deploys Selenium Grid on the Kubernetes cluster in the default configuration with chromeDebug and firefoxDebug enabled.

Note: You should see the following output after executing helm install ...

NAME: selenium-grid
LAST DEPLOYED: Fri May 11 23:09:29 2018
NAMESPACE: default
STATUS: DEPLOYED
RESOURCES:
==> v1/Service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
selenium-grid-selenium-hub LoadBalancer 10.110.225.161 localhost 4444:30665/TCP 0s
==> v1beta1/Deployment
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
selenium-grid-selenium-chrome-debug 1 1 1 0 0s
selenium-grid-selenium-firefox-debug 1 1 1 0 0s
selenium-grid-selenium-hub 1 1 1 0 0s
==> v1/Pod(related)
NAME READY STATUS RESTARTS AGE
selenium-grid-selenium-chrome-debug-6d8898d7c4-7psdh 0/1 ContainerCreating 0 0s
selenium-grid-selenium-firefox-debug-84f6f484d8-wh66d 0/1 ContainerCreating 0 0s
selenium-grid-selenium-hub-f7f874cd-p5lrd 0/1 ContainerCreating 0 0s

Selenium hub will automatically start-up using port 4444 by default. You can view the status of the hub by opening a browser window and navigating to: http://localhost:4444/grid/console

Run Selenium Test

Let's run a quick Selenium test to validate our setup.

Clone this github repo:
git clone https://github.com/sayems/selenium.grid.git
Go into the project
$ cd selenium.grid
Run tests

Before you run docker-compose up, verify Selenium grid is up & running on Kubernetes cluster, you can verify by executing the following command: $ kubectl get pods

$ docker-compose up

It typically takes several minutes for docker setup for the first time, so wait for few minutes …

Debugging with VNC Viewer

It is useful to be able to view your Selenium tests running on Kubernetes cluster. This can help us to debug issues better and have more confidence in our tests. To view running tests on Kubernetes cluster.

  1. Download VNC® Viewer for Google Chrome
  2. Execute the following command to bind ports between Kubernetes cluster to the local machine:
 kubectl port-forward --namespace default \
$(kubectl get pods --namespace default \
-l app=selenium-grid-selenium-chrome-debug \
-o jsonpath='{ .items[0].metadata.name }') 5900
  1. Open VNC® Viewer for Google Chrome
    • Address: 127.0.0.1:5900
    • Password: secret

Deletes a release from Kubernetes

The helm list function will show you a list of all deployed releases.

$ helm list

List of all releases

NAME REVISION UPDATED STATUS CHART NAMESPACE
selenium-grid 1 Fri May DEPLOYED selenium default

If you want to delete selenium-grid, you can execute the following command

$ helm delete selenium-grid
release "selenium-grid" deleted

If you want to delete all Helm releases, you can pipe the output of helm ls --short to xargs, and run helm delete for each release name.

$ helm ls --short | xargs -L1 helm delete

Configuration

The following table lists the configurable parameters of the Selenium chart and their default values.

ParameterDescriptionDefault
global.nodeselectorNode label to be useed globally for scheduling of all imagesnil
hub.imageThe selenium hub imageselenium/hub
hub.tagThe selenium hub image tag3.11.0
hub.pullPolicyThe pull policy for the hub imageIfNotPresent
hub.portThe port the hub listens on4444
hub.javaOptsThe java options for the selenium hub JVM, default sets the maximum heap size to 1,000 mb-Xmx1000m
hub.resourcesThe resources for the hub container, defaults to minimum half a cpu and maximum 1,000 mb RAM{"limits":{"cpu":".5", "memory":"1000Mi"}}
hub.serviceTypeThe Service typeNodePort
hub.serviceSessionAffinityThe session affinity for the hub serviceNone
hub.gridNewSessionWaitTimeoutnil
hub.gridJettyMaxThreadsnil
hub.gridNodePollingnil
hub.gridCleanUpCyclenil
hub.gridTimeoutnil
hub.gridBrowserTimeoutnil
hub.gridMaxSessionnil
hub.gridUnregisterIfStillDownAfernil
hub.seOptsCommand line arguments to pass to hubnil
hub.timeZoneThe time zone for the containernil
hub.nodeselectorNode label to use for scheduling of the hub if set this takes precedence over the global valuenil
chrome.enabledSchedule a chrome node podfalse
chrome.imageThe selenium node chrome imageselenium/node-chrome
chrome.tagThe selenium node chrome tag3.11.0
chrome.pullPolicyThe pull policy for the node chrome imageIfNotPresent
chrome.replicasThe number of selenium node chrome pods1
chrome.javaOptsThe java options for the selenium node chrome JVM, default sets the maximum heap size to 900 mb-Xmx900m
chrome.volumeMountsAdditional volumes to mount, the default provides a larger shared memory[{"mountPath":"/dev/shm", "name":"dshm"}]
chrome.volumesAdditional volumes import, the default provides a larger shared memory[{"name":"dshm", "emptyDir":{"medium":"Memory"}}]
chrome.resourcesThe resources for the node chrome container, defaults to minimum half a cpu and maximum 1,000 mb{"limits":{"cpu":".5", "memory":"1000Mi"}}
chrome.screenWidthnil
chrome.screenHeightnil
chrome.screenDepthnil
chrome.displayThe vnc displaynil
chrome.chromeVersionThe version of chrome to usenil
chrome.nodeMaxInstancesThe maximum number of browser instancesnil
chrome.nodeMaxSessionThe maximum number of sessionsnil
chrome.nodeRegistryCycleThe number of milliseconds to wait, registering a nodenil
chrome.nodePortThe port to listen onnil
chrome.seOptsCommand line arguments to pass to nodenil
chrome.timeZoneThe time zone for the containernil
chrome.nodeselectorNode label to use for scheduling of chrome images if set this takes precedence over the global valuenil
chromeDebug.enabledSchedule a selenium node chrome debug podfalse
chromeDebug.imageThe selenium node chrome debug imageselenium/node-chrome-debug
chromeDebug.tagThe selenium node chrome debug tag3.11.0
chromeDebug.pullPolicyThe selenium node chrome debug pull policyIfNotPresent
chromeDebug.replicasThe number of selenium node chrome debug pods1
chromeDebug.javaOptsThe java options for a selenium node chrome debug JVM, default sets the max heap size to 900 mb-Xmx900m
chromeDebug.volumeMountsAdditional volumes to mount, the default provides a larger shared[{"mountPath":"/dev/shm", "name":"dshm"}]
chromeDebug.volumesAdditional volumes import, the default provides a larger shared[{"name":"dshm", "emptyDir":{"medium":"Memory"}}]
chromeDebug.resourcesThe resources for the hub container, defaults to minimum half a cpu and maximum 1,000 mb{"limits":{"cpu":".5", "memory":"1000Mi"}}
chromeDebug.screenWidthnil
chromeDebug.screenHeightnil
chromeDebug.screenDepthnil
chromeDebug.displayThe vnc displaynil
chromeDebug.chromeVersionThe version of chrome to usenil
chromeDebug.nodeMaxInstancesThe maximum number of browser instancesnil
chromeDebug.nodeMaxSessionThe maximum number of sessionsnil
chromeDebug.nodeRegistryCycleThe number of milliseconds to wait, registering a nodenil
chromeDebug.nodePortThe port to listen onnil
chromeDebug.seOptsCommand line arguments to pass to nodenil
chromeDebug.timeZoneThe time zone for the containernil
chromeDebug.nodeselectorNode label to use for scheduling of chromeDebug images if set this takes precedence over the global valuenil
firefox.enabledSchedule a selenium node firefox podfalse
firefox.imageThe selenium node firefox imageselenium/node-firefox
firefox.tagThe selenium node firefox tag3.11.0
firefox.pullPolicyThe selenium node firefox pull policyIfNotPresent
firefox.replicasThe number of selenium node firefox pods1
firefox.javaOptsThe java options for a selenium node firefox JVM, default sets the max heap size to 900 mb-Xmx900m
firefox.resourcesThe resources for the hub container, defaults to minimum half a cpu and maximum 1,000 mb{"limits":{"cpu":".5", "memory":"1000Mi"}}
firefox.screenWidthnil
firefox.screenHeightnil
firefox.screenDepthnil
firefox.displayThe vnc displaynil
firefox.firefoxVersionThe version of firefox to usenil
firefox.nodeMaxInstancesThe maximum number of browser instancesnil
firefox.nodeMaxSessionThe maximum number of sessionsnil
firefox.nodeRegistryCycleThe number of milliseconds to wait, registering a nodenil
firefox.nodePortThe port to listen onnil
firefox.seOptsCommand line arguments to pass to nodenil
firefox.timeZoneThe time zone for the containernil
firefox.nodeselectorNode label to use for scheduling of firefox images if set this takes precedence over the global valuenil
firefoxDebug.enabledSchedule a selenium node firefox debug podfalse
firefoxDebug.imageThe selenium node firefox debug imageselenium/node-firefox-debug
firefoxDebug.tagThe selenium node firefox debug tag3.11.0
firefoxDebug.pullPolicyThe selenium node firefox debug pull policyIfNotPresent
firefoxDebug.replicasThe numer of selenium node firefox debug pods1
firefoxDebug.javaOptsThe java options for a selenium node firefox debug JVM, default sets the max heap size to 900 mb-Xmx900m
firefoxDebug.resourcesThe resources for the selenium node firefox debug container, defaults to minimum half a cpu and maximum 1,000 mb{"limits":{"cpu":".5", "memory":"1000Mi"}}
firefoxDebug.screenWidthnil
firefoxDebug.screenHeightnil
firefoxDebug.screenDepthnil
firefoxDebug.displayThe vnc displaynil
firefoxDebug.firefoxVersionThe version of firefox to usenil
firefoxDebug.nodeMaxInstancesThe maximum number of browser instancesnil
firefoxDebug.nodeMaxSessionThe maximum number of sessionsnil
firefoxDebug.nodeRegistryCycleThe number of milliseconds to wait, registering a nodenil
firefoxDebug.nodePortThe port to listen onnil
firefoxDebug.seOptsCommand line arguments to pass to nodenil
firefoxDebug.timeZoneThe time zone for the containernil
firefoxDebug.nodeselectorNode label to use for scheduling of firefoxDebug images if set this takes precedence over the global valuenil

Specify each parameter using the --set key=value[,key=value] argument to helm install. For example,

$ helm install --name my-release \ --set chrome.enabled=true \ stable/selenium

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Latest commit

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Running Selenium Grid on Kubernetes cluster

In this tutorial, I’ll show you how to get Selenium Grid up and running on Kubernetes cluster using Helm package manager.

Contents

  1. Prerequisites
  2. Selenium Grid
  3. Kubernetes
  4. Selenium-Grid Installation
  5. Run Selenium tests
  6. Debugging with VNC Viewer
  7. Deletes a release

Selenium Grid

Selenium Grid makes automation execution jobs much easier. Using Selenium Grid, one can run multiple tests on multiple machines in parallel, which reduces execution times from days to hours. However, setting up our own Selenium Grid means we have to configure browsers across multiple machines, virtual or physical, and making sure each machine is running the Selenium Server correctly. This also means maintaining the Grid and making updates would be a time-consuming. This is where Kubernetes comes in and saves the day!

Kubernetes

Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications.

Helm

Helm is a package manager for Kubernetes applications, responsible for installing and managing Kubernetes applications. Helm packages all of the different Kubernetes resources (such as deployments, services, and ingress) into a chart, which may be hosted in a repository. Users can pull down charts and install them on any number of Kubernetes clusters. This is similar to Homebrew and apt-get package manager. We will use Helm to deploy selenium-grid on Kubernetes Cluster.

What We’ll Accomplish
  1. Set up a Kubernetes cluster using Docker for Mac
  2. Deploy Selenium-Grid to the cluster
  3. Running selenium test and viewing your Selenium tests running on Kubernetes cluster

Prerequisites

  • kubectl - macOS users can use brew install kubectl to install
  • Docker for Mac - Docker with Kubernetes is currently only available on Docker for Mac in the latest Edge version
  • Virtualbox - macOS users can use brew cask install virtualbox to install
  • Helm - macOS users can use brew install kubernetes-helm to install

Verify the Installation

docker --version # Docker version 17.09.0-ce, build afdb6d4
docker-compose --version # docker-compose version 1.16.1, build 6d1ac21
docker-machine --version # docker-machine version 0.12.2, build 9371605
kubectl version --client # Client Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.1", GitCommit:"f38e43b221d08850172a9a4ea785a86a3ffa3b3a", GitTreeState:"clean", BuildDate:"2017-10-12T00:45:05Z", GoVersion:"go1.9.1", Compiler:"gc", Platform:"darwin/amd64"} helm version --client # Client: &version.Version{SemVer:"v2.9.0", GitCommit:"f6025bb9ee7daf9fee0026541c90a6f557a3e0bc", GitTreeState:"clean"}

Enabling the local Kubernetes cluster

Click the Docker icon in the status bar, go to “Preferences”, and on the “Kubernetes”-tab, check “Enable Kubernetes”. This will start a single node Kubernetes cluster for you and install the kubectl command line utility. This might take a while, but the dialog will let you know once the Kubernetes cluster is ready.

Next step, you’ll need to increase Docker’s available memory to 4GB or more.

Click the Docker icon in the status bar, go to “Preferences”, and on the “Advanced”-tab, change memoery to 4GB or more.

Selenium Grid installation

To install the chart with the release name selenium-grid:

helm install --name selenium-grid stable/selenium \
--set chromeDebug.enabled=true \
--set firefoxDebug.enabled=true

The command deploys Selenium Grid on the Kubernetes cluster in the default configuration with chromeDebug and firefoxDebug enabled.

Note: You should see the following output after executing helm install ...

NAME: selenium-grid
LAST DEPLOYED: Fri May 11 23:09:29 2018
NAMESPACE: default
STATUS: DEPLOYED
RESOURCES:
==> v1/Service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
selenium-grid-selenium-hub LoadBalancer 10.110.225.161 localhost 4444:30665/TCP 0s
==> v1beta1/Deployment
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
selenium-grid-selenium-chrome-debug 1 1 1 0 0s
selenium-grid-selenium-firefox-debug 1 1 1 0 0s
selenium-grid-selenium-hub 1 1 1 0 0s
==> v1/Pod(related)
NAME READY STATUS RESTARTS AGE
selenium-grid-selenium-chrome-debug-6d8898d7c4-7psdh 0/1 ContainerCreating 0 0s
selenium-grid-selenium-firefox-debug-84f6f484d8-wh66d 0/1 ContainerCreating 0 0s
selenium-grid-selenium-hub-f7f874cd-p5lrd 0/1 ContainerCreating 0 0s

Selenium hub will automatically start-up using port 4444 by default. You can view the status of the hub by opening a browser window and navigating to: http://localhost:4444/grid/console

Run Selenium Test

Let's run a quick Selenium test to validate our setup.

Clone this github repo:
git clone https://github.com/sayems/selenium.grid.git
Go into the project
$ cd selenium.grid
Run tests

Before you run docker-compose up, verify Selenium grid is up & running on Kubernetes cluster, you can verify by executing the following command: $ kubectl get pods

$ docker-compose up

It typically takes several minutes for docker setup for the first time, so wait for few minutes …

Debugging with VNC Viewer

It is useful to be able to view your Selenium tests running on Kubernetes cluster. This can help us to debug issues better and have more confidence in our tests. To view running tests on Kubernetes cluster.

  1. Download VNC® Viewer for Google Chrome
  2. Execute the following command to bind ports between Kubernetes cluster to the local machine:
 kubectl port-forward --namespace default \
$(kubectl get pods --namespace default \
-l app=selenium-grid-selenium-chrome-debug \
-o jsonpath='{ .items[0].metadata.name }') 5900
  1. Open VNC® Viewer for Google Chrome
    • Address: 127.0.0.1:5900
    • Password: secret

Deletes a release from Kubernetes

The helm list function will show you a list of all deployed releases.

$ helm list

List of all releases

NAME REVISION UPDATED STATUS CHART NAMESPACE
selenium-grid 1 Fri May DEPLOYED selenium default

If you want to delete selenium-grid, you can execute the following command

$ helm delete selenium-grid
release "selenium-grid" deleted

If you want to delete all Helm releases, you can pipe the output of helm ls --short to xargs, and run helm delete for each release name.

$ helm ls --short | xargs -L1 helm delete

Configuration

The following table lists the configurable parameters of the Selenium chart and their default values.

ParameterDescriptionDefault
global.nodeselectorNode label to be useed globally for scheduling of all imagesnil
hub.imageThe selenium hub imageselenium/hub
hub.tagThe selenium hub image tag3.11.0
hub.pullPolicyThe pull policy for the hub imageIfNotPresent
hub.portThe port the hub listens on4444
hub.javaOptsThe java options for the selenium hub JVM, default sets the maximum heap size to 1,000 mb-Xmx1000m
hub.resourcesThe resources for the hub container, defaults to minimum half a cpu and maximum 1,000 mb RAM{"limits":{"cpu":".5", "memory":"1000Mi"}}
hub.serviceTypeThe Service typeNodePort
hub.serviceSessionAffinityThe session affinity for the hub serviceNone
hub.gridNewSessionWaitTimeoutnil
hub.gridJettyMaxThreadsnil
hub.gridNodePollingnil
hub.gridCleanUpCyclenil
hub.gridTimeoutnil
hub.gridBrowserTimeoutnil
hub.gridMaxSessionnil
hub.gridUnregisterIfStillDownAfernil
hub.seOptsCommand line arguments to pass to hubnil
hub.timeZoneThe time zone for the containernil
hub.nodeselectorNode label to use for scheduling of the hub if set this takes precedence over the global valuenil
chrome.enabledSchedule a chrome node podfalse
chrome.imageThe selenium node chrome imageselenium/node-chrome
chrome.tagThe selenium node chrome tag3.11.0
chrome.pullPolicyThe pull policy for the node chrome imageIfNotPresent
chrome.replicasThe number of selenium node chrome pods1
chrome.javaOptsThe java options for the selenium node chrome JVM, default sets the maximum heap size to 900 mb-Xmx900m
chrome.volumeMountsAdditional volumes to mount, the default provides a larger shared memory[{"mountPath":"/dev/shm", "name":"dshm"}]
chrome.volumesAdditional volumes import, the default provides a larger shared memory[{"name":"dshm", "emptyDir":{"medium":"Memory"}}]
chrome.resourcesThe resources for the node chrome container, defaults to minimum half a cpu and maximum 1,000 mb{"limits":{"cpu":".5", "memory":"1000Mi"}}
chrome.screenWidthnil
chrome.screenHeightnil
chrome.screenDepthnil
chrome.displayThe vnc displaynil
chrome.chromeVersionThe version of chrome to usenil
chrome.nodeMaxInstancesThe maximum number of browser instancesnil
chrome.nodeMaxSessionThe maximum number of sessionsnil
chrome.nodeRegistryCycleThe number of milliseconds to wait, registering a nodenil
chrome.nodePortThe port to listen onnil
chrome.seOptsCommand line arguments to pass to nodenil
chrome.timeZoneThe time zone for the containernil
chrome.nodeselectorNode label to use for scheduling of chrome images if set this takes precedence over the global valuenil
chromeDebug.enabledSchedule a selenium node chrome debug podfalse
chromeDebug.imageThe selenium node chrome debug imageselenium/node-chrome-debug
chromeDebug.tagThe selenium node chrome debug tag3.11.0
chromeDebug.pullPolicyThe selenium node chrome debug pull policyIfNotPresent
chromeDebug.replicasThe number of selenium node chrome debug pods1
chromeDebug.javaOptsThe java options for a selenium node chrome debug JVM, default sets the max heap size to 900 mb-Xmx900m
chromeDebug.volumeMountsAdditional volumes to mount, the default provides a larger shared[{"mountPath":"/dev/shm", "name":"dshm"}]
chromeDebug.volumesAdditional volumes import, the default provides a larger shared[{"name":"dshm", "emptyDir":{"medium":"Memory"}}]
chromeDebug.resourcesThe resources for the hub container, defaults to minimum half a cpu and maximum 1,000 mb{"limits":{"cpu":".5", "memory":"1000Mi"}}
chromeDebug.screenWidthnil
chromeDebug.screenHeightnil
chromeDebug.screenDepthnil
chromeDebug.displayThe vnc displaynil
chromeDebug.chromeVersionThe version of chrome to usenil
chromeDebug.nodeMaxInstancesThe maximum number of browser instancesnil
chromeDebug.nodeMaxSessionThe maximum number of sessionsnil
chromeDebug.nodeRegistryCycleThe number of milliseconds to wait, registering a nodenil
chromeDebug.nodePortThe port to listen onnil
chromeDebug.seOptsCommand line arguments to pass to nodenil
chromeDebug.timeZoneThe time zone for the containernil
chromeDebug.nodeselectorNode label to use for scheduling of chromeDebug images if set this takes precedence over the global valuenil
firefox.enabledSchedule a selenium node firefox podfalse
firefox.imageThe selenium node firefox imageselenium/node-firefox
firefox.tagThe selenium node firefox tag3.11.0
firefox.pullPolicyThe selenium node firefox pull policyIfNotPresent
firefox.replicasThe number of selenium node firefox pods1
firefox.javaOptsThe java options for a selenium node firefox JVM, default sets the max heap size to 900 mb-Xmx900m
firefox.resourcesThe resources for the hub container, defaults to minimum half a cpu and maximum 1,000 mb{"limits":{"cpu":".5", "memory":"1000Mi"}}
firefox.screenWidthnil
firefox.screenHeightnil
firefox.screenDepthnil
firefox.displayThe vnc displaynil
firefox.firefoxVersionThe version of firefox to usenil
firefox.nodeMaxInstancesThe maximum number of browser instancesnil
firefox.nodeMaxSessionThe maximum number of sessionsnil
firefox.nodeRegistryCycleThe number of milliseconds to wait, registering a nodenil
firefox.nodePortThe port to listen onnil
firefox.seOptsCommand line arguments to pass to nodenil
firefox.timeZoneThe time zone for the containernil
firefox.nodeselectorNode label to use for scheduling of firefox images if set this takes precedence over the global valuenil
firefoxDebug.enabledSchedule a selenium node firefox debug podfalse
firefoxDebug.imageThe selenium node firefox debug imageselenium/node-firefox-debug
firefoxDebug.tagThe selenium node firefox debug tag3.11.0
firefoxDebug.pullPolicyThe selenium node firefox debug pull policyIfNotPresent
firefoxDebug.replicasThe numer of selenium node firefox debug pods1
firefoxDebug.javaOptsThe java options for a selenium node firefox debug JVM, default sets the max heap size to 900 mb-Xmx900m
firefoxDebug.resourcesThe resources for the selenium node firefox debug container, defaults to minimum half a cpu and maximum 1,000 mb{"limits":{"cpu":".5", "memory":"1000Mi"}}
firefoxDebug.screenWidthnil
firefoxDebug.screenHeightnil
firefoxDebug.screenDepthnil
firefoxDebug.displayThe vnc displaynil
firefoxDebug.firefoxVersionThe version of firefox to usenil
firefoxDebug.nodeMaxInstancesThe maximum number of browser instancesnil
firefoxDebug.nodeMaxSessionThe maximum number of sessionsnil
firefoxDebug.nodeRegistryCycleThe number of milliseconds to wait, registering a nodenil
firefoxDebug.nodePortThe port to listen onnil
firefoxDebug.seOptsCommand line arguments to pass to nodenil
firefoxDebug.timeZoneThe time zone for the containernil
firefoxDebug.nodeselectorNode label to use for scheduling of firefoxDebug images if set this takes precedence over the global valuenil

Specify each parameter using the --set key=value[,key=value] argument to helm install. For example,

$ helm install --name my-release \ --set chrome.enabled=true \ stable/selenium

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Latest commit

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Running Selenium Grid on Kubernetes cluster

In this tutorial, I’ll show you how to get Selenium Grid up and running on Kubernetes cluster using Helm package manager.

Contents

  1. Prerequisites
  2. Selenium Grid
  3. Kubernetes
  4. Selenium-Grid Installation
  5. Run Selenium tests
  6. Debugging with VNC Viewer
  7. Deletes a release

Selenium Grid

Selenium Grid makes automation execution jobs much easier. Using Selenium Grid, one can run multiple tests on multiple machines in parallel, which reduces execution times from days to hours. However, setting up our own Selenium Grid means we have to configure browsers across multiple machines, virtual or physical, and making sure each machine is running the Selenium Server correctly. This also means maintaining the Grid and making updates would be a time-consuming. This is where Kubernetes comes in and saves the day!

Kubernetes

Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications.

Helm

Helm is a package manager for Kubernetes applications, responsible for installing and managing Kubernetes applications. Helm packages all of the different Kubernetes resources (such as deployments, services, and ingress) into a chart, which may be hosted in a repository. Users can pull down charts and install them on any number of Kubernetes clusters. This is similar to Homebrew and apt-get package manager. We will use Helm to deploy selenium-grid on Kubernetes Cluster.

What We’ll Accomplish
  1. Set up a Kubernetes cluster using Docker for Mac
  2. Deploy Selenium-Grid to the cluster
  3. Running selenium test and viewing your Selenium tests running on Kubernetes cluster

Prerequisites

  • kubectl - macOS users can use brew install kubectl to install
  • Docker for Mac - Docker with Kubernetes is currently only available on Docker for Mac in the latest Edge version
  • Virtualbox - macOS users can use brew cask install virtualbox to install
  • Helm - macOS users can use brew install kubernetes-helm to install

Verify the Installation

docker --version # Docker version 17.09.0-ce, build afdb6d4
docker-compose --version # docker-compose version 1.16.1, build 6d1ac21
docker-machine --version # docker-machine version 0.12.2, build 9371605
kubectl version --client # Client Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.1", GitCommit:"f38e43b221d08850172a9a4ea785a86a3ffa3b3a", GitTreeState:"clean", BuildDate:"2017-10-12T00:45:05Z", GoVersion:"go1.9.1", Compiler:"gc", Platform:"darwin/amd64"} helm version --client # Client: &version.Version{SemVer:"v2.9.0", GitCommit:"f6025bb9ee7daf9fee0026541c90a6f557a3e0bc", GitTreeState:"clean"}

Enabling the local Kubernetes cluster

Click the Docker icon in the status bar, go to “Preferences”, and on the “Kubernetes”-tab, check “Enable Kubernetes”. This will start a single node Kubernetes cluster for you and install the kubectl command line utility. This might take a while, but the dialog will let you know once the Kubernetes cluster is ready.

Next step, you’ll need to increase Docker’s available memory to 4GB or more.

Click the Docker icon in the status bar, go to “Preferences”, and on the “Advanced”-tab, change memoery to 4GB or more.

Selenium Grid installation

To install the chart with the release name selenium-grid:

helm install --name selenium-grid stable/selenium \
--set chromeDebug.enabled=true \
--set firefoxDebug.enabled=true

The command deploys Selenium Grid on the Kubernetes cluster in the default configuration with chromeDebug and firefoxDebug enabled.

Note: You should see the following output after executing helm install ...

NAME: selenium-grid
LAST DEPLOYED: Fri May 11 23:09:29 2018
NAMESPACE: default
STATUS: DEPLOYED
RESOURCES:
==> v1/Service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
selenium-grid-selenium-hub LoadBalancer 10.110.225.161 localhost 4444:30665/TCP 0s
==> v1beta1/Deployment
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
selenium-grid-selenium-chrome-debug 1 1 1 0 0s
selenium-grid-selenium-firefox-debug 1 1 1 0 0s
selenium-grid-selenium-hub 1 1 1 0 0s
==> v1/Pod(related)
NAME READY STATUS RESTARTS AGE
selenium-grid-selenium-chrome-debug-6d8898d7c4-7psdh 0/1 ContainerCreating 0 0s
selenium-grid-selenium-firefox-debug-84f6f484d8-wh66d 0/1 ContainerCreating 0 0s
selenium-grid-selenium-hub-f7f874cd-p5lrd 0/1 ContainerCreating 0 0s

Selenium hub will automatically start-up using port 4444 by default. You can view the status of the hub by opening a browser window and navigating to: http://localhost:4444/grid/console

Run Selenium Test

Let's run a quick Selenium test to validate our setup.

Clone this github repo:
git clone https://github.com/sayems/selenium.grid.git
Go into the project
$ cd selenium.grid
Run tests

Before you run docker-compose up, verify Selenium grid is up & running on Kubernetes cluster, you can verify by executing the following command: $ kubectl get pods

$ docker-compose up

It typically takes several minutes for docker setup for the first time, so wait for few minutes …

Debugging with VNC Viewer

It is useful to be able to view your Selenium tests running on Kubernetes cluster. This can help us to debug issues better and have more confidence in our tests. To view running tests on Kubernetes cluster.

  1. Download VNC® Viewer for Google Chrome
  2. Execute the following command to bind ports between Kubernetes cluster to the local machine:
 kubectl port-forward --namespace default \
$(kubectl get pods --namespace default \
-l app=selenium-grid-selenium-chrome-debug \
-o jsonpath='{ .items[0].metadata.name }') 5900
  1. Open VNC® Viewer for Google Chrome
    • Address: 127.0.0.1:5900
    • Password: secret

Deletes a release from Kubernetes

The helm list function will show you a list of all deployed releases.

$ helm list

List of all releases

NAME REVISION UPDATED STATUS CHART NAMESPACE
selenium-grid 1 Fri May DEPLOYED selenium default

If you want to delete selenium-grid, you can execute the following command

$ helm delete selenium-grid
release "selenium-grid" deleted

If you want to delete all Helm releases, you can pipe the output of helm ls --short to xargs, and run helm delete for each release name.

$ helm ls --short | xargs -L1 helm delete

Configuration

The following table lists the configurable parameters of the Selenium chart and their default values.

ParameterDescriptionDefault
global.nodeselectorNode label to be useed globally for scheduling of all imagesnil
hub.imageThe selenium hub imageselenium/hub
hub.tagThe selenium hub image tag3.11.0
hub.pullPolicyThe pull policy for the hub imageIfNotPresent
hub.portThe port the hub listens on4444
hub.javaOptsThe java options for the selenium hub JVM, default sets the maximum heap size to 1,000 mb-Xmx1000m
hub.resourcesThe resources for the hub container, defaults to minimum half a cpu and maximum 1,000 mb RAM{"limits":{"cpu":".5", "memory":"1000Mi"}}
hub.serviceTypeThe Service typeNodePort
hub.serviceSessionAffinityThe session affinity for the hub serviceNone
hub.gridNewSessionWaitTimeoutnil
hub.gridJettyMaxThreadsnil
hub.gridNodePollingnil
hub.gridCleanUpCyclenil
hub.gridTimeoutnil
hub.gridBrowserTimeoutnil
hub.gridMaxSessionnil
hub.gridUnregisterIfStillDownAfernil
hub.seOptsCommand line arguments to pass to hubnil
hub.timeZoneThe time zone for the containernil
hub.nodeselectorNode label to use for scheduling of the hub if set this takes precedence over the global valuenil
chrome.enabledSchedule a chrome node podfalse
chrome.imageThe selenium node chrome imageselenium/node-chrome
chrome.tagThe selenium node chrome tag3.11.0
chrome.pullPolicyThe pull policy for the node chrome imageIfNotPresent
chrome.replicasThe number of selenium node chrome pods1
chrome.javaOptsThe java options for the selenium node chrome JVM, default sets the maximum heap size to 900 mb-Xmx900m
chrome.volumeMountsAdditional volumes to mount, the default provides a larger shared memory[{"mountPath":"/dev/shm", "name":"dshm"}]
chrome.volumesAdditional volumes import, the default provides a larger shared memory[{"name":"dshm", "emptyDir":{"medium":"Memory"}}]
chrome.resourcesThe resources for the node chrome container, defaults to minimum half a cpu and maximum 1,000 mb{"limits":{"cpu":".5", "memory":"1000Mi"}}
chrome.screenWidthnil
chrome.screenHeightnil
chrome.screenDepthnil
chrome.displayThe vnc displaynil
chrome.chromeVersionThe version of chrome to usenil
chrome.nodeMaxInstancesThe maximum number of browser instancesnil
chrome.nodeMaxSessionThe maximum number of sessionsnil
chrome.nodeRegistryCycleThe number of milliseconds to wait, registering a nodenil
chrome.nodePortThe port to listen onnil
chrome.seOptsCommand line arguments to pass to nodenil
chrome.timeZoneThe time zone for the containernil
chrome.nodeselectorNode label to use for scheduling of chrome images if set this takes precedence over the global valuenil
chromeDebug.enabledSchedule a selenium node chrome debug podfalse
chromeDebug.imageThe selenium node chrome debug imageselenium/node-chrome-debug
chromeDebug.tagThe selenium node chrome debug tag3.11.0
chromeDebug.pullPolicyThe selenium node chrome debug pull policyIfNotPresent
chromeDebug.replicasThe number of selenium node chrome debug pods1
chromeDebug.javaOptsThe java options for a selenium node chrome debug JVM, default sets the max heap size to 900 mb-Xmx900m
chromeDebug.volumeMountsAdditional volumes to mount, the default provides a larger shared[{"mountPath":"/dev/shm", "name":"dshm"}]
chromeDebug.volumesAdditional volumes import, the default provides a larger shared[{"name":"dshm", "emptyDir":{"medium":"Memory"}}]
chromeDebug.resourcesThe resources for the hub container, defaults to minimum half a cpu and maximum 1,000 mb{"limits":{"cpu":".5", "memory":"1000Mi"}}
chromeDebug.screenWidthnil
chromeDebug.screenHeightnil
chromeDebug.screenDepthnil
chromeDebug.displayThe vnc displaynil
chromeDebug.chromeVersionThe version of chrome to usenil
chromeDebug.nodeMaxInstancesThe maximum number of browser instancesnil
chromeDebug.nodeMaxSessionThe maximum number of sessionsnil
chromeDebug.nodeRegistryCycleThe number of milliseconds to wait, registering a nodenil
chromeDebug.nodePortThe port to listen onnil
chromeDebug.seOptsCommand line arguments to pass to nodenil
chromeDebug.timeZoneThe time zone for the containernil
chromeDebug.nodeselectorNode label to use for scheduling of chromeDebug images if set this takes precedence over the global valuenil
firefox.enabledSchedule a selenium node firefox podfalse
firefox.imageThe selenium node firefox imageselenium/node-firefox
firefox.tagThe selenium node firefox tag3.11.0
firefox.pullPolicyThe selenium node firefox pull policyIfNotPresent
firefox.replicasThe number of selenium node firefox pods1
firefox.javaOptsThe java options for a selenium node firefox JVM, default sets the max heap size to 900 mb-Xmx900m
firefox.resourcesThe resources for the hub container, defaults to minimum half a cpu and maximum 1,000 mb{"limits":{"cpu":".5", "memory":"1000Mi"}}
firefox.screenWidthnil
firefox.screenHeightnil
firefox.screenDepthnil
firefox.displayThe vnc displaynil
firefox.firefoxVersionThe version of firefox to usenil
firefox.nodeMaxInstancesThe maximum number of browser instancesnil
firefox.nodeMaxSessionThe maximum number of sessionsnil
firefox.nodeRegistryCycleThe number of milliseconds to wait, registering a nodenil
firefox.nodePortThe port to listen onnil
firefox.seOptsCommand line arguments to pass to nodenil
firefox.timeZoneThe time zone for the containernil
firefox.nodeselectorNode label to use for scheduling of firefox images if set this takes precedence over the global valuenil
firefoxDebug.enabledSchedule a selenium node firefox debug podfalse
firefoxDebug.imageThe selenium node firefox debug imageselenium/node-firefox-debug
firefoxDebug.tagThe selenium node firefox debug tag3.11.0
firefoxDebug.pullPolicyThe selenium node firefox debug pull policyIfNotPresent
firefoxDebug.replicasThe numer of selenium node firefox debug pods1
firefoxDebug.javaOptsThe java options for a selenium node firefox debug JVM, default sets the max heap size to 900 mb-Xmx900m
firefoxDebug.resourcesThe resources for the selenium node firefox debug container, defaults to minimum half a cpu and maximum 1,000 mb{"limits":{"cpu":".5", "memory":"1000Mi"}}
firefoxDebug.screenWidthnil
firefoxDebug.screenHeightnil
firefoxDebug.screenDepthnil
firefoxDebug.displayThe vnc displaynil
firefoxDebug.firefoxVersionThe version of firefox to usenil
firefoxDebug.nodeMaxInstancesThe maximum number of browser instancesnil
firefoxDebug.nodeMaxSessionThe maximum number of sessionsnil
firefoxDebug.nodeRegistryCycleThe number of milliseconds to wait, registering a nodenil
firefoxDebug.nodePortThe port to listen onnil
firefoxDebug.seOptsCommand line arguments to pass to nodenil
firefoxDebug.timeZoneThe time zone for the containernil
firefoxDebug.nodeselectorNode label to use for scheduling of firefoxDebug images if set this takes precedence over the global valuenil

Specify each parameter using the --set key=value[,key=value] argument to helm install. For example,

$ helm install --name my-release \ --set chrome.enabled=true \ stable/selenium

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Latest commit

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Running Selenium Grid on Kubernetes cluster

In this tutorial, I’ll show you how to get Selenium Grid up and running on Kubernetes cluster using Helm package manager.

Contents

  1. Prerequisites
  2. Selenium Grid
  3. Kubernetes
  4. Selenium-Grid Installation
  5. Run Selenium tests
  6. Debugging with VNC Viewer
  7. Deletes a release

Selenium Grid

Selenium Grid makes automation execution jobs much easier. Using Selenium Grid, one can run multiple tests on multiple machines in parallel, which reduces execution times from days to hours. However, setting up our own Selenium Grid means we have to configure browsers across multiple machines, virtual or physical, and making sure each machine is running the Selenium Server correctly. This also means maintaining the Grid and making updates would be a time-consuming. This is where Kubernetes comes in and saves the day!

Kubernetes

Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications.

Helm

Helm is a package manager for Kubernetes applications, responsible for installing and managing Kubernetes applications. Helm packages all of the different Kubernetes resources (such as deployments, services, and ingress) into a chart, which may be hosted in a repository. Users can pull down charts and install them on any number of Kubernetes clusters. This is similar to Homebrew and apt-get package manager. We will use Helm to deploy selenium-grid on Kubernetes Cluster.

What We’ll Accomplish
  1. Set up a Kubernetes cluster using Docker for Mac
  2. Deploy Selenium-Grid to the cluster
  3. Running selenium test and viewing your Selenium tests running on Kubernetes cluster

Prerequisites

  • kubectl - macOS users can use brew install kubectl to install
  • Docker for Mac - Docker with Kubernetes is currently only available on Docker for Mac in the latest Edge version
  • Virtualbox - macOS users can use brew cask install virtualbox to install
  • Helm - macOS users can use brew install kubernetes-helm to install

Verify the Installation

docker --version # Docker version 17.09.0-ce, build afdb6d4
docker-compose --version # docker-compose version 1.16.1, build 6d1ac21
docker-machine --version # docker-machine version 0.12.2, build 9371605
kubectl version --client # Client Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.1", GitCommit:"f38e43b221d08850172a9a4ea785a86a3ffa3b3a", GitTreeState:"clean", BuildDate:"2017-10-12T00:45:05Z", GoVersion:"go1.9.1", Compiler:"gc", Platform:"darwin/amd64"} helm version --client # Client: &version.Version{SemVer:"v2.9.0", GitCommit:"f6025bb9ee7daf9fee0026541c90a6f557a3e0bc", GitTreeState:"clean"}

Enabling the local Kubernetes cluster

Click the Docker icon in the status bar, go to “Preferences”, and on the “Kubernetes”-tab, check “Enable Kubernetes”. This will start a single node Kubernetes cluster for you and install the kubectl command line utility. This might take a while, but the dialog will let you know once the Kubernetes cluster is ready.

Next step, you’ll need to increase Docker’s available memory to 4GB or more.

Click the Docker icon in the status bar, go to “Preferences”, and on the “Advanced”-tab, change memoery to 4GB or more.

Selenium Grid installation

To install the chart with the release name selenium-grid:

helm install --name selenium-grid stable/selenium \
--set chromeDebug.enabled=true \
--set firefoxDebug.enabled=true

The command deploys Selenium Grid on the Kubernetes cluster in the default configuration with chromeDebug and firefoxDebug enabled.

Note: You should see the following output after executing helm install ...

NAME: selenium-grid
LAST DEPLOYED: Fri May 11 23:09:29 2018
NAMESPACE: default
STATUS: DEPLOYED
RESOURCES:
==> v1/Service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
selenium-grid-selenium-hub LoadBalancer 10.110.225.161 localhost 4444:30665/TCP 0s
==> v1beta1/Deployment
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
selenium-grid-selenium-chrome-debug 1 1 1 0 0s
selenium-grid-selenium-firefox-debug 1 1 1 0 0s
selenium-grid-selenium-hub 1 1 1 0 0s
==> v1/Pod(related)
NAME READY STATUS RESTARTS AGE
selenium-grid-selenium-chrome-debug-6d8898d7c4-7psdh 0/1 ContainerCreating 0 0s
selenium-grid-selenium-firefox-debug-84f6f484d8-wh66d 0/1 ContainerCreating 0 0s
selenium-grid-selenium-hub-f7f874cd-p5lrd 0/1 ContainerCreating 0 0s

Selenium hub will automatically start-up using port 4444 by default. You can view the status of the hub by opening a browser window and navigating to: http://localhost:4444/grid/console

Run Selenium Test

Let's run a quick Selenium test to validate our setup.

Clone this github repo:
git clone https://github.com/sayems/selenium.grid.git
Go into the project
$ cd selenium.grid
Run tests

Before you run docker-compose up, verify Selenium grid is up & running on Kubernetes cluster, you can verify by executing the following command: $ kubectl get pods

$ docker-compose up

It typically takes several minutes for docker setup for the first time, so wait for few minutes …

Debugging with VNC Viewer

It is useful to be able to view your Selenium tests running on Kubernetes cluster. This can help us to debug issues better and have more confidence in our tests. To view running tests on Kubernetes cluster.

  1. Download VNC® Viewer for Google Chrome
  2. Execute the following command to bind ports between Kubernetes cluster to the local machine:
 kubectl port-forward --namespace default \
$(kubectl get pods --namespace default \
-l app=selenium-grid-selenium-chrome-debug \
-o jsonpath='{ .items[0].metadata.name }') 5900
  1. Open VNC® Viewer for Google Chrome
    • Address: 127.0.0.1:5900
    • Password: secret

Deletes a release from Kubernetes

The helm list function will show you a list of all deployed releases.

$ helm list

List of all releases

NAME REVISION UPDATED STATUS CHART NAMESPACE
selenium-grid 1 Fri May DEPLOYED selenium default

If you want to delete selenium-grid, you can execute the following command

$ helm delete selenium-grid
release "selenium-grid" deleted

If you want to delete all Helm releases, you can pipe the output of helm ls --short to xargs, and run helm delete for each release name.

$ helm ls --short | xargs -L1 helm delete

Configuration

The following table lists the configurable parameters of the Selenium chart and their default values.

ParameterDescriptionDefault
global.nodeselectorNode label to be useed globally for scheduling of all imagesnil
hub.imageThe selenium hub imageselenium/hub
hub.tagThe selenium hub image tag3.11.0
hub.pullPolicyThe pull policy for the hub imageIfNotPresent
hub.portThe port the hub listens on4444
hub.javaOptsThe java options for the selenium hub JVM, default sets the maximum heap size to 1,000 mb-Xmx1000m
hub.resourcesThe resources for the hub container, defaults to minimum half a cpu and maximum 1,000 mb RAM{"limits":{"cpu":".5", "memory":"1000Mi"}}
hub.serviceTypeThe Service typeNodePort
hub.serviceSessionAffinityThe session affinity for the hub serviceNone
hub.gridNewSessionWaitTimeoutnil
hub.gridJettyMaxThreadsnil
hub.gridNodePollingnil
hub.gridCleanUpCyclenil
hub.gridTimeoutnil
hub.gridBrowserTimeoutnil
hub.gridMaxSessionnil
hub.gridUnregisterIfStillDownAfernil
hub.seOptsCommand line arguments to pass to hubnil
hub.timeZoneThe time zone for the containernil
hub.nodeselectorNode label to use for scheduling of the hub if set this takes precedence over the global valuenil
chrome.enabledSchedule a chrome node podfalse
chrome.imageThe selenium node chrome imageselenium/node-chrome
chrome.tagThe selenium node chrome tag3.11.0
chrome.pullPolicyThe pull policy for the node chrome imageIfNotPresent
chrome.replicasThe number of selenium node chrome pods1
chrome.javaOptsThe java options for the selenium node chrome JVM, default sets the maximum heap size to 900 mb-Xmx900m
chrome.volumeMountsAdditional volumes to mount, the default provides a larger shared memory[{"mountPath":"/dev/shm", "name":"dshm"}]
chrome.volumesAdditional volumes import, the default provides a larger shared memory[{"name":"dshm", "emptyDir":{"medium":"Memory"}}]
chrome.resourcesThe resources for the node chrome container, defaults to minimum half a cpu and maximum 1,000 mb{"limits":{"cpu":".5", "memory":"1000Mi"}}
chrome.screenWidthnil
chrome.screenHeightnil
chrome.screenDepthnil
chrome.displayThe vnc displaynil
chrome.chromeVersionThe version of chrome to usenil
chrome.nodeMaxInstancesThe maximum number of browser instancesnil
chrome.nodeMaxSessionThe maximum number of sessionsnil
chrome.nodeRegistryCycleThe number of milliseconds to wait, registering a nodenil
chrome.nodePortThe port to listen onnil
chrome.seOptsCommand line arguments to pass to nodenil
chrome.timeZoneThe time zone for the containernil
chrome.nodeselectorNode label to use for scheduling of chrome images if set this takes precedence over the global valuenil
chromeDebug.enabledSchedule a selenium node chrome debug podfalse
chromeDebug.imageThe selenium node chrome debug imageselenium/node-chrome-debug
chromeDebug.tagThe selenium node chrome debug tag3.11.0
chromeDebug.pullPolicyThe selenium node chrome debug pull policyIfNotPresent
chromeDebug.replicasThe number of selenium node chrome debug pods1
chromeDebug.javaOptsThe java options for a selenium node chrome debug JVM, default sets the max heap size to 900 mb-Xmx900m
chromeDebug.volumeMountsAdditional volumes to mount, the default provides a larger shared[{"mountPath":"/dev/shm", "name":"dshm"}]
chromeDebug.volumesAdditional volumes import, the default provides a larger shared[{"name":"dshm", "emptyDir":{"medium":"Memory"}}]
chromeDebug.resourcesThe resources for the hub container, defaults to minimum half a cpu and maximum 1,000 mb{"limits":{"cpu":".5", "memory":"1000Mi"}}
chromeDebug.screenWidthnil
chromeDebug.screenHeightnil
chromeDebug.screenDepthnil
chromeDebug.displayThe vnc displaynil
chromeDebug.chromeVersionThe version of chrome to usenil
chromeDebug.nodeMaxInstancesThe maximum number of browser instancesnil
chromeDebug.nodeMaxSessionThe maximum number of sessionsnil
chromeDebug.nodeRegistryCycleThe number of milliseconds to wait, registering a nodenil
chromeDebug.nodePortThe port to listen onnil
chromeDebug.seOptsCommand line arguments to pass to nodenil
chromeDebug.timeZoneThe time zone for the containernil
chromeDebug.nodeselectorNode label to use for scheduling of chromeDebug images if set this takes precedence over the global valuenil
firefox.enabledSchedule a selenium node firefox podfalse
firefox.imageThe selenium node firefox imageselenium/node-firefox
firefox.tagThe selenium node firefox tag3.11.0
firefox.pullPolicyThe selenium node firefox pull policyIfNotPresent
firefox.replicasThe number of selenium node firefox pods1
firefox.javaOptsThe java options for a selenium node firefox JVM, default sets the max heap size to 900 mb-Xmx900m
firefox.resourcesThe resources for the hub container, defaults to minimum half a cpu and maximum 1,000 mb{"limits":{"cpu":".5", "memory":"1000Mi"}}
firefox.screenWidthnil
firefox.screenHeightnil
firefox.screenDepthnil
firefox.displayThe vnc displaynil
firefox.firefoxVersionThe version of firefox to usenil
firefox.nodeMaxInstancesThe maximum number of browser instancesnil
firefox.nodeMaxSessionThe maximum number of sessionsnil
firefox.nodeRegistryCycleThe number of milliseconds to wait, registering a nodenil
firefox.nodePortThe port to listen onnil
firefox.seOptsCommand line arguments to pass to nodenil
firefox.timeZoneThe time zone for the containernil
firefox.nodeselectorNode label to use for scheduling of firefox images if set this takes precedence over the global valuenil
firefoxDebug.enabledSchedule a selenium node firefox debug podfalse
firefoxDebug.imageThe selenium node firefox debug imageselenium/node-firefox-debug
firefoxDebug.tagThe selenium node firefox debug tag3.11.0
firefoxDebug.pullPolicyThe selenium node firefox debug pull policyIfNotPresent
firefoxDebug.replicasThe numer of selenium node firefox debug pods1
firefoxDebug.javaOptsThe java options for a selenium node firefox debug JVM, default sets the max heap size to 900 mb-Xmx900m
firefoxDebug.resourcesThe resources for the selenium node firefox debug container, defaults to minimum half a cpu and maximum 1,000 mb{"limits":{"cpu":".5", "memory":"1000Mi"}}
firefoxDebug.screenWidthnil
firefoxDebug.screenHeightnil
firefoxDebug.screenDepthnil
firefoxDebug.displayThe vnc displaynil
firefoxDebug.firefoxVersionThe version of firefox to usenil
firefoxDebug.nodeMaxInstancesThe maximum number of browser instancesnil
firefoxDebug.nodeMaxSessionThe maximum number of sessionsnil
firefoxDebug.nodeRegistryCycleThe number of milliseconds to wait, registering a nodenil
firefoxDebug.nodePortThe port to listen onnil
firefoxDebug.seOptsCommand line arguments to pass to nodenil
firefoxDebug.timeZoneThe time zone for the containernil
firefoxDebug.nodeselectorNode label to use for scheduling of firefoxDebug images if set this takes precedence over the global valuenil

Specify each parameter using the --set key=value[,key=value] argument to helm install. For example,

$ helm install --name my-release \ --set chrome.enabled=true \ stable/selenium

Releases

Packages

Contributors

Languages