Skip to content

Commit e56a1fc

Browse files
authored
Feature run selenium tests grid on kubernetes via helm chart (#2027)
* 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
1 parent bbef734 commit e56a1fc

File tree

8 files changed

+133
-9
lines changed

8 files changed

+133
-9
lines changed

.github/workflows/helm-chart-test.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ on:
99
- 'charts/selenium-grid/**'
1010
workflow_dispatch:
1111

12+
permissions:
13+
contents: read
14+
1215
jobs:
1316
lint-test:
17+
name: "Lint Tests with ct"
1418
runs-on: ubuntu-latest
1519
steps:
1620
- name: Checkout
@@ -45,6 +49,69 @@ jobs:
4549

4650
- name: Create kind cluster
4751
uses: helm/[email protected]
52+
with:
53+
config: ./tests/kind-cluster-config.yaml
4854

4955
- name: Run chart-testing (install)
5056
run: ct install --all --config tests/chart-test.yaml
57+
58+
deploy-grid-selenium-tests:
59+
name: "Run Selenium Tests on K8s"
60+
runs-on: ubuntu-latest
61+
strategy:
62+
fail-fast: false
63+
matrix:
64+
browser: [NodeChrome,NodeEdge,NodeFirefox]
65+
steps:
66+
67+
- name: Checkout
68+
uses: actions/checkout@v4
69+
with:
70+
fetch-depth: 0
71+
72+
- name: Set up Helm
73+
uses: azure/setup-helm@v3
74+
with:
75+
version: v3.13.2
76+
77+
- name: Set up Python
78+
uses: actions/setup-python@v4
79+
with:
80+
python-version: '3.10'
81+
check-latest: true
82+
83+
- name: Create kind cluster
84+
uses: helm/[email protected]
85+
with:
86+
config: ./tests/kind-cluster-config.yaml
87+
88+
# 👋 Documentation link for Ingress Installation on kind k8s cluster https://kind.sigs.k8s.io/docs/user/ingress
89+
- name: Install ingress-nginx on kind kubernetes cluster
90+
run: |
91+
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml
92+
kubectl wait --namespace ingress-nginx \
93+
--for=condition=ready pod \
94+
--selector=app.kubernetes.io/component=controller \
95+
--timeout=90s
96+
97+
- name: Deploy Selenium Grid Chart
98+
run: |
99+
helm repo add kedacore https://kedacore.github.io/charts
100+
helm repo update
101+
helm dependency build charts/selenium-grid
102+
helm upgrade --install selenium-grid -f ./tests/override-kind-auth-${{matrix.browser}}-values.yaml charts/selenium-grid --namespace selenium-grid-test --create-namespace
103+
kubectl get ingress --all-namespaces
104+
105+
- name: Verify Post Deployment Grid Health and k8s pods status
106+
run: |
107+
sleep 20 # Allow Kubernetes to pull Docker Images and start Pods
108+
python ./tests/K8sSmokeTest.py "http://localhost"
109+
kubectl get pods -n selenium-grid-test
110+
kubectl get events -n selenium-grid-test
111+
112+
- name: Run Selenium Tests Against Kubernetes
113+
run: |
114+
export SELENIUM_GRID_HOST=localhost
115+
export SELENIUM_GRID_PORT=80
116+
export RUN_IN_DOCKER_COMPOSE=true
117+
./tests/bootstrap.sh ${{matrix.browser}}

charts/selenium-grid/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ helm install selenium-grid --set ingress.hostname=selenium-grid.k8s.local docker
3636
Selenium Grid has the ability to autoscale browser nodes up/down based on the pending requests in the
3737
session queue.
3838

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

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

tests/SeleniumTests/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from selenium.webdriver.chrome.options import Options as ChromeOptions
1010

1111
SELENIUM_GRID_HOST = os.environ.get('SELENIUM_GRID_HOST', 'localhost')
12-
12+
SELENIUM_GRID_PORT = os.environ.get('SELENIUM_GRID_PORT', '4444')
1313

1414
class SeleniumGenericTests(unittest.TestCase):
1515

@@ -70,22 +70,22 @@ class ChromeTests(SeleniumGenericTests):
7070
def setUp(self):
7171
self.driver = webdriver.Remote(
7272
options=ChromeOptions(),
73-
command_executor="http://%s:4444" % SELENIUM_GRID_HOST
73+
command_executor="http://%s:%s" % (SELENIUM_GRID_HOST,SELENIUM_GRID_PORT)
7474
)
7575

7676
class EdgeTests(SeleniumGenericTests):
7777
def setUp(self):
7878
self.driver = webdriver.Remote(
7979
options=EdgeOptions(),
80-
command_executor="http://%s:4444" % SELENIUM_GRID_HOST
80+
command_executor="http://%s:%s" % (SELENIUM_GRID_HOST,SELENIUM_GRID_PORT)
8181
)
8282

8383

8484
class FirefoxTests(SeleniumGenericTests):
8585
def setUp(self):
8686
self.driver = webdriver.Remote(
8787
options=FirefoxOptions(),
88-
command_executor="http://%s:4444" % SELENIUM_GRID_HOST
88+
command_executor="http://%s:%s" % (SELENIUM_GRID_HOST,SELENIUM_GRID_PORT)
8989
)
9090

9191
def test_title_and_maximize_window(self):

tests/SmokeTests/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from urllib.request import urlopen
1010

1111
SELENIUM_GRID_HOST = os.environ.get('SELENIUM_GRID_HOST', 'localhost')
12-
12+
SELENIUM_GRID_PORT = os.environ.get('SELENIUM_GRID_PORT', '4444')
1313

1414
class SmokeTests(unittest.TestCase):
1515
def smoke_test_container(self, port):
@@ -35,4 +35,4 @@ def smoke_test_container(self, port):
3535

3636
class GridTest(SmokeTests):
3737
def test_grid_is_up(self):
38-
self.smoke_test_container(4444)
38+
self.smoke_test_container('%s' % SELENIUM_GRID_PORT)

tests/kind-cluster-config.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# This Config is required for KIND cluster to enable ingress. Documented here https://kind.sigs.k8s.io/docs/user/ingress
2+
kind: Cluster
3+
apiVersion: kind.x-k8s.io/v1alpha4
4+
nodes:
5+
- role: control-plane
6+
kubeadmConfigPatches:
7+
- |
8+
kind: InitConfiguration
9+
nodeRegistration:
10+
kubeletExtraArgs:
11+
node-labels: "ingress-ready=true"
12+
extraPortMappings:
13+
- containerPort: 80
14+
hostPort: 80
15+
protocol: TCP
16+
- containerPort: 443
17+
hostPort: 443
18+
protocol: TCP
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# This is used in Helm chart testing. This disables the basic auth on seleneium grid
2+
# Basic auth settings for Selenium Grid
3+
basicAuth:
4+
# Enable or disable basic auth
5+
enabled: false
6+
# Configuration for edge nodes
7+
edgeNode:
8+
# Enable edge nodes
9+
enabled: false
10+
# Configuration for firefox nodes
11+
firefoxNode:
12+
# Enable firefox nodes
13+
enabled: false
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# This is used in Helm chart testing. This disables the basic auth on seleneium grid
2+
# Basic auth settings for Selenium Grid
3+
basicAuth:
4+
# Enable or disable basic auth
5+
enabled: false
6+
# Configuration for chrome nodes
7+
chromeNode:
8+
# Enable chrome nodes
9+
enabled: false
10+
# Configuration for firefox nodes
11+
firefoxNode:
12+
# Enable firefox nodes
13+
enabled: false
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# This is used in Helm chart testing. This disables the basic auth on seleneium grid
2+
# Basic auth settings for Selenium Grid
3+
basicAuth:
4+
# Enable or disable basic auth
5+
enabled: false
6+
# Configuration for chrome nodes
7+
chromeNode:
8+
# Enable chrome nodes
9+
enabled: false
10+
# Configuration for edge nodes
11+
edgeNode:
12+
# Enable edge nodes
13+
enabled: false

0 commit comments

Comments
 (0)