Skip to content

Commit 24527c6

Browse files
authored
[feat][test]: add env vars to generate config for Relay in node-base (#2254)
1 parent 739ebea commit 24527c6

16 files changed

+260
-21
lines changed

.github/workflows/build-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
- name: Set Selenium base version
5454
if: contains(toJson(github.event.commits), '[deploy]') == false
5555
run: |
56-
make set_nightly_env
56+
make set_build_nightly
5757
cat .env | xargs -I {} echo {} >> $GITHUB_ENV
5858
- name: Sets build date
5959
run: |

.github/workflows/test-video.yml renamed to .github/workflows/docker-test.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ on:
2323
pull_request:
2424
paths-ignore:
2525
- '**.md'
26-
schedule:
27-
- cron: '0 0 * * *'
2826

2927
permissions:
3028
contents: read
@@ -45,6 +43,8 @@ jobs:
4543
test-video: true
4644
- test-strategy: test_parallel
4745
test-video: false
46+
- test-strategy: test_node_relay
47+
test-video: false
4848
steps:
4949
- uses: actions/checkout@main
5050
- name: Set up QEMU
@@ -61,6 +61,12 @@ jobs:
6161
with:
6262
python-version: '3.11'
6363
check-latest: true
64+
- name: Enable KVM
65+
if: matrix.test-strategy == 'test_node_relay'
66+
run: |
67+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
68+
sudo udevadm control --reload-rules
69+
sudo udevadm trigger --name-match=kvm
6470
- name: Get branch name (only for push to branch)
6571
if: github.event_name == 'push'
6672
run: echo "BRANCH=$(echo ${PUSH_BRANCH##*/})" >> $GITHUB_ENV
@@ -76,7 +82,7 @@ jobs:
7682
- name: Set Selenium base version
7783
if: contains(toJson(github.event.commits), '[deploy]') == false
7884
run: |
79-
make set_nightly_env
85+
make set_build_nightly
8086
cat .env | xargs -I {} echo {} >> $GITHUB_ENV
8187
- name: Sets build date
8288
run: |

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ on:
2323
description: 'Test parameter for different log level'
2424
required: false
2525
default: 'FINE'
26-
schedule:
27-
- cron: '0 0 * * *'
2826

2927
permissions:
3028
contents: read
@@ -111,7 +109,7 @@ jobs:
111109
- name: Set Selenium base version
112110
if: contains(toJson(github.event.commits), '[deploy]') == false
113111
run: |
114-
make set_nightly_env
112+
make set_build_nightly
115113
cat .env | xargs -I {} echo {} >> $GITHUB_ENV
116114
- name: Sets build date
117115
run: |

.github/workflows/nightly.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@ on:
55
- cron: '0 1 * * *'
66

77
jobs:
8+
docker-test:
9+
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
10+
uses: ./.github/workflows/docker-test.yml
11+
12+
helm-chart-test:
13+
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
14+
uses: ./.github/workflows/helm-chart-test.yml
15+
816
deploy:
17+
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
918
name: Nightly build
1019
runs-on: ubuntu-latest
1120
permissions: write-all

Makefile

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ all: hub \
3838
standalone_docker \
3939
video
4040

41-
set_nightly_env:
41+
set_build_nightly:
4242
echo BASE_VERSION=$(BASE_VERSION_NIGHTLY) > .env ; \
4343
echo BASE_RELEASE=$(BASE_RELEASE_NIGHTLY) >> .env ;
44+
echo "Execute 'source .env' to set the environment variables"
4445

4546
docker_buildx_setup:
4647
sudo apt-get install --upgrade docker-buildx-plugin
@@ -484,6 +485,27 @@ test_video: video hub chrome firefox edge
484485
done
485486
make test_video_integrity
486487

488+
test_node_relay: hub node_base standalone_firefox
489+
sudo rm -rf ./tests/tests
490+
for node in Android NodeFirefox ; do \
491+
cd ./tests || true ; \
492+
echo TAG=$(TAG_VERSION) > .env ; \
493+
echo LOG_LEVEL=$(or $(LOG_LEVEL), "INFO") >> .env ; \
494+
echo REQUEST_TIMEOUT=$(or $(REQUEST_TIMEOUT), 300) >> .env ; \
495+
echo SESSION_TIMEOUT=$(or $(SESSION_TIMEOUT), 300) >> .env ; \
496+
echo ANDROID_BASED_NAME=$(or $(ANDROID_BASED_NAME),budtmo) >> .env ; \
497+
echo ANDROID_BASED_IMAGE=$(or $(ANDROID_BASED_IMAGE),docker-android) >> .env ; \
498+
echo ANDROID_BASED_TAG=$(or $(ANDROID_BASED_TAG),emulator_14.0) >> .env ; \
499+
echo ANDROID_PLATFORM_API=$(or $(ANDROID_PLATFORM_API),14) >> .env ; \
500+
echo TEST_DELAY_AFTER_TEST=$(or $(TEST_DELAY_AFTER_TEST), 15) >> .env ; \
501+
echo NODE=$$node >> .env ; \
502+
echo TEST_NODE_RELAY=$$node >> .env ; \
503+
echo UID=$$(id -u) >> .env ; \
504+
echo BINDING_VERSION=$(BINDING_VERSION) >> .env ; \
505+
docker compose -f docker-compose-v3-test-node-relay.yml up --no-log-prefix --exit-code-from tests --build ; \
506+
if [ $$? -ne 0 ]; then exit 1; fi ; \
507+
done
508+
487509
test_node_docker: hub standalone_docker standalone_chrome standalone_firefox standalone_edge video
488510
sudo rm -rf ./tests/tests
489511
sudo rm -rf ./tests/videos; mkdir -p ./tests/videos/Downloads

NodeBase/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ COPY --chown="${SEL_UID}:${SEL_GID}" start-selenium-node.sh \
143143
start-xvfb.sh \
144144
start-vnc.sh \
145145
start-novnc.sh \
146-
generate_config /opt/bin/
146+
generate_config generate_relay_config /opt/bin/
147147

148148
# Selenium Grid logo as wallpaper for Fluxbox
149149
COPY selenium_grid_logo.png /usr/share/images/fluxbox/ubuntu-light.png

NodeBase/generate_config

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,34 @@ echo "session-timeout = \"${SE_NODE_SESSION_TIMEOUT}\"" >> "$FILENAME"
4848
echo "override-max-sessions = ${SE_NODE_OVERRIDE_MAX_SESSIONS}" >> "$FILENAME"
4949
echo "detect-drivers = false" >> "$FILENAME"
5050
echo "drain-after-session-count = ${DRAIN_AFTER_SESSION_COUNT:-$SE_DRAIN_AFTER_SESSION_COUNT}" >> "$FILENAME"
51-
echo "max-sessions = ${SE_NODE_MAX_SESSIONS}
51+
# When node is handled both browser and relay, SE_NODE_MAX_CONCURRENCY is used to configure max concurrency based on sum of them
52+
echo "max-sessions = ${SE_NODE_MAX_CONCURRENCY:-${SE_NODE_MAX_SESSIONS}}
5253
" >> "$FILENAME"
5354

54-
SE_NODE_BROWSER_NAME=$(cat /opt/selenium/browser_name)
55-
SE_NODE_BROWSER_VERSION=$(short_version $(cat /opt/selenium/browser_version))
56-
SE__BROWSER_BINARY_LOCATION=$(cat /opt/selenium/browser_binary_location)
55+
if [ -f /opt/selenium/browser_name ]; then
56+
SE_NODE_BROWSER_NAME=$(cat /opt/selenium/browser_name)
57+
fi
58+
if [ -f /opt/selenium/browser_version ]; then
59+
SE_NODE_BROWSER_VERSION=$(short_version $(cat /opt/selenium/browser_version))
60+
fi
61+
if [ -f /opt/selenium/browser_binary_location ]; then
62+
SE__BROWSER_BINARY_LOCATION=$(cat /opt/selenium/browser_binary_location)
63+
fi
5764

58-
if [[ -z "$SE_NODE_STEREOTYPE" ]]; then
65+
# 'browserName' is mandatory for default stereotype
66+
if [[ -z "${SE_NODE_STEREOTYPE}" ]] && [[ -n "${SE_NODE_BROWSER_NAME}" ]]; then
5967
SE_NODE_STEREOTYPE="{\"browserName\": \"${SE_NODE_BROWSER_NAME}\", \"browserVersion\": \"${SE_NODE_BROWSER_VERSION}\", \"platformName\": \"Linux\", ${SE__BROWSER_BINARY_LOCATION}}"
6068
else
61-
SE_NODE_STEREOTYPE="$SE_NODE_STEREOTYPE"
69+
SE_NODE_STEREOTYPE="${SE_NODE_STEREOTYPE}"
6270
fi
6371

64-
echo "[[node.driver-configuration]]" >> "$FILENAME"
65-
echo "display-name = \"${SE_NODE_BROWSER_NAME}\"" >> "$FILENAME"
66-
echo "stereotype = '${SE_NODE_STEREOTYPE}'" >> "$FILENAME"
67-
echo "max-sessions = ${SE_NODE_MAX_SESSIONS}
68-
" >> "$FILENAME"
69-
72+
# 'stereotype' setting is mandatory
73+
if [[ -n "${SE_NODE_STEREOTYPE}" ]]; then
74+
echo "[[node.driver-configuration]]" >> "$FILENAME"
75+
echo "display-name = \"${SE_NODE_BROWSER_NAME}\"" >> "$FILENAME"
76+
echo "stereotype = '${SE_NODE_STEREOTYPE}'" >> "$FILENAME"
77+
echo "max-sessions = ${SE_NODE_MAX_SESSIONS}
78+
" >> "$FILENAME"
79+
fi
7080

7181

NodeBase/generate_relay_config

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
if [[ -z "$CONFIG_FILE" ]]; then
4+
FILENAME="/opt/selenium/config.toml"
5+
else
6+
FILENAME="$CONFIG_FILE"
7+
fi
8+
9+
if [[ -n "${SE_NODE_RELAY_URL}" ]]; then
10+
echo "[relay]" >> "$FILENAME"
11+
echo "url = \"${SE_NODE_RELAY_URL}\"" >> "$FILENAME"
12+
if [[ -z "${SE_NODE_RELAY_STATUS_ENDPOINT}" ]]; then
13+
echo "status-endpoint = \"/status\"" >> "$FILENAME"
14+
else
15+
echo "status-endpoint = \"${SE_NODE_RELAY_STATUS_ENDPOINT}\"" >> "$FILENAME"
16+
fi
17+
if [[ -n "${SE_NODE_RELAY_PROTOCOL_VERSION}" ]]; then
18+
echo "protocol-version = \"${SE_NODE_RELAY_PROTOCOL_VERSION}\"" >> "$FILENAME"
19+
fi
20+
echo "configs = [
21+
\"${SE_NODE_RELAY_MAX_SESSIONS}\", \"{\\\"browserName\\\": \\\"${SE_NODE_RELAY_BROWSER_NAME}\\\", \\\"platformName\\\": \\\"${SE_NODE_RELAY_PLATFORM_NAME}\\\", \\\"appium:platformVersion\\\": \\\"${SE_NODE_RELAY_PLATFORM_VERSION}\\\"}\"
22+
]
23+
" >> "$FILENAME"
24+
fi

NodeBase/start-selenium-node.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ fi
9898
if [ "$GENERATE_CONFIG" = true ]; then
9999
echo "Generating Selenium Config"
100100
/opt/bin/generate_config
101+
/opt/bin/generate_relay_config
101102
fi
102103

103104
EXTRA_LIBS=""

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,35 @@ $ docker run -d \
940940
--shm-size="2g" selenium/node-chrome:4.20.0-20240505
941941
```
942942

943+
### Node configuration relay commands
944+
945+
Relaying commands to a service endpoint that supports WebDriver.
946+
It is useful to connect an external service that supports WebDriver to Selenium Grid. An example of such service could be a cloud provider or an Appium server.
947+
In this way, Grid can enable more coverage to platforms and versions not present locally.
948+
949+
The following is an en example of configuration relay commands.
950+
951+
[docker-compose-v3-test-node-relay.yml](tests/docker-compose-v3-test-node-relay.yml)
952+
953+
If you want to relay commands only, `selenium/node-base` is suitable and lightweight for this purpose.
954+
In case you want to configure node with both browsers and relay commands, respective node images can be used.
955+
956+
To use environment variables for generate relay configs, set `SE_NODE_RELAY_URL` and other variables as below
957+
958+
```toml
959+
[relay]
960+
url = "${SE_NODE_RELAY_URL}"
961+
status-endpoint = "${SE_NODE_RELAY_STATUS_ENDPOINT}"
962+
protocol-version = "${SE_NODE_RELAY_PROTOCOL_VERSION}"
963+
configs = [ '${SE_NODE_RELAY_MAX_SESSIONS}', '{"browserName": "${SE_NODE_RELAY_BROWSER_NAME}", "platformName": "${SE_NODE_RELAY_PLATFORM_NAME}", "appium:platformVersion": "${SE_NODE_RELAY_PLATFORM_VERSION}"}' ]
964+
```
965+
966+
To run a sample test with the relayed node, you can clone the project and try below command:
967+
968+
```bash
969+
make test_node_relay
970+
```
971+
943972
### Setting Sub Path
944973

945974
By default, Selenium is reachable at `http://127.0.0.1:4444/`. Selenium can be configured to use a custom subpath by specifying the `SE_SUB_PATH`

0 commit comments

Comments
 (0)