Skip to content

Commit

Permalink
Feature run selenium tests grid on kubernetes via helm chart (#2027)
Browse files Browse the repository at this point in the history
* feat(k8stests): added kubernetes tests cases

* docs(keda): updated readme to keda version 2.12

* chore(optimize): matrix strategy in workflow

* chore(docker): allow time to docker pull images

* fix(dry-principle): Reusing existing test.py
  • Loading branch information
amardeep2006 authored Nov 27, 2023
1 parent bbef734 commit e56a1fc
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 9 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/helm-chart-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ on:
- 'charts/selenium-grid/**'
workflow_dispatch:

permissions:
contents: read

jobs:
lint-test:
name: "Lint Tests with ct"
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down Expand Up @@ -45,6 +49,69 @@ jobs:

- name: Create kind cluster
uses: helm/kind-action@v1.8.0
with:
config: ./tests/kind-cluster-config.yaml

- name: Run chart-testing (install)
run: ct install --all --config tests/chart-test.yaml

deploy-grid-selenium-tests:
name: "Run Selenium Tests on K8s"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
browser: [NodeChrome,NodeEdge,NodeFirefox]
steps:

- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Helm
uses: azure/setup-helm@v3
with:
version: v3.13.2

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
check-latest: true

- name: Create kind cluster
uses: helm/kind-action@v1.8.0
with:
config: ./tests/kind-cluster-config.yaml

# 👋 Documentation link for Ingress Installation on kind k8s cluster https://kind.sigs.k8s.io/docs/user/ingress
- name: Install ingress-nginx on kind kubernetes cluster
run: |
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml
kubectl wait --namespace ingress-nginx \
--for=condition=ready pod \
--selector=app.kubernetes.io/component=controller \
--timeout=90s
- name: Deploy Selenium Grid Chart
run: |
helm repo add kedacore https://kedacore.github.io/charts
helm repo update
helm dependency build charts/selenium-grid
helm upgrade --install selenium-grid -f ./tests/override-kind-auth-${{matrix.browser}}-values.yaml charts/selenium-grid --namespace selenium-grid-test --create-namespace
kubectl get ingress --all-namespaces
- name: Verify Post Deployment Grid Health and k8s pods status
run: |
sleep 20 # Allow Kubernetes to pull Docker Images and start Pods
python ./tests/K8sSmokeTest.py "http://localhost"
kubectl get pods -n selenium-grid-test
kubectl get events -n selenium-grid-test
- name: Run Selenium Tests Against Kubernetes
run: |
export SELENIUM_GRID_HOST=localhost
export SELENIUM_GRID_PORT=80
export RUN_IN_DOCKER_COMPOSE=true
./tests/bootstrap.sh ${{matrix.browser}}
6 changes: 3 additions & 3 deletions charts/selenium-grid/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ helm install selenium-grid --set ingress.hostname=selenium-grid.k8s.local docker
Selenium Grid has the ability to autoscale browser nodes up/down based on the pending requests in the
session queue.

To do this [KEDA](https://keda.sh/docs/2.10/scalers/selenium-grid-scaler/) is used. When enabling
To do this [KEDA](https://keda.sh/docs/2.12/scalers/selenium-grid-scaler/) is used. When enabling
autoscaling using `autoscaling.enabling` KEDA is installed automatically. To instead use an existing
installation of KEDA you can enable autoscaling with `autoscaling.enableWithExistingKEDA` instead.

KEDA can scale either with
[deployments](https://keda.sh/docs/2.10/concepts/scaling-deployments/#scaling-of-deployments-and-statefulsets)
or [jobs](https://keda.sh/docs/2.10/concepts/scaling-jobs/) and the charts support both types. This
[deployments](https://keda.sh/docs/2.12/concepts/scaling-deployments/#scaling-of-deployments-and-statefulsets)
or [jobs](https://keda.sh/docs/2.12/concepts/scaling-jobs/) and the charts support both types. This
chart support both modes. It is controlled with `autoscaling.scalingType` that can be set to either
job (default) or deployment.

Expand Down
8 changes: 4 additions & 4 deletions tests/SeleniumTests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from selenium.webdriver.chrome.options import Options as ChromeOptions

SELENIUM_GRID_HOST = os.environ.get('SELENIUM_GRID_HOST', 'localhost')

SELENIUM_GRID_PORT = os.environ.get('SELENIUM_GRID_PORT', '4444')

class SeleniumGenericTests(unittest.TestCase):

Expand Down Expand Up @@ -70,22 +70,22 @@ class ChromeTests(SeleniumGenericTests):
def setUp(self):
self.driver = webdriver.Remote(
options=ChromeOptions(),
command_executor="http://%s:4444" % SELENIUM_GRID_HOST
command_executor="http://%s:%s" % (SELENIUM_GRID_HOST,SELENIUM_GRID_PORT)
)

class EdgeTests(SeleniumGenericTests):
def setUp(self):
self.driver = webdriver.Remote(
options=EdgeOptions(),
command_executor="http://%s:4444" % SELENIUM_GRID_HOST
command_executor="http://%s:%s" % (SELENIUM_GRID_HOST,SELENIUM_GRID_PORT)
)


class FirefoxTests(SeleniumGenericTests):
def setUp(self):
self.driver = webdriver.Remote(
options=FirefoxOptions(),
command_executor="http://%s:4444" % SELENIUM_GRID_HOST
command_executor="http://%s:%s" % (SELENIUM_GRID_HOST,SELENIUM_GRID_PORT)
)

def test_title_and_maximize_window(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/SmokeTests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from urllib.request import urlopen

SELENIUM_GRID_HOST = os.environ.get('SELENIUM_GRID_HOST', 'localhost')

SELENIUM_GRID_PORT = os.environ.get('SELENIUM_GRID_PORT', '4444')

class SmokeTests(unittest.TestCase):
def smoke_test_container(self, port):
Expand All @@ -35,4 +35,4 @@ def smoke_test_container(self, port):

class GridTest(SmokeTests):
def test_grid_is_up(self):
self.smoke_test_container(4444)
self.smoke_test_container('%s' % SELENIUM_GRID_PORT)
18 changes: 18 additions & 0 deletions tests/kind-cluster-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# This Config is required for KIND cluster to enable ingress. Documented here https://kind.sigs.k8s.io/docs/user/ingress
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
kubeadmConfigPatches:
- |
kind: InitConfiguration
nodeRegistration:
kubeletExtraArgs:
node-labels: "ingress-ready=true"
extraPortMappings:
- containerPort: 80
hostPort: 80
protocol: TCP
- containerPort: 443
hostPort: 443
protocol: TCP
13 changes: 13 additions & 0 deletions tests/override-kind-auth-NodeChrome-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This is used in Helm chart testing. This disables the basic auth on seleneium grid
# Basic auth settings for Selenium Grid
basicAuth:
# Enable or disable basic auth
enabled: false
# Configuration for edge nodes
edgeNode:
# Enable edge nodes
enabled: false
# Configuration for firefox nodes
firefoxNode:
# Enable firefox nodes
enabled: false
13 changes: 13 additions & 0 deletions tests/override-kind-auth-NodeEdge-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This is used in Helm chart testing. This disables the basic auth on seleneium grid
# Basic auth settings for Selenium Grid
basicAuth:
# Enable or disable basic auth
enabled: false
# Configuration for chrome nodes
chromeNode:
# Enable chrome nodes
enabled: false
# Configuration for firefox nodes
firefoxNode:
# Enable firefox nodes
enabled: false
13 changes: 13 additions & 0 deletions tests/override-kind-auth-NodeFirefox-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This is used in Helm chart testing. This disables the basic auth on seleneium grid
# Basic auth settings for Selenium Grid
basicAuth:
# Enable or disable basic auth
enabled: false
# Configuration for chrome nodes
chromeNode:
# Enable chrome nodes
enabled: false
# Configuration for edge nodes
edgeNode:
# Enable edge nodes
enabled: false

0 comments on commit e56a1fc

Please sign in to comment.