Skip to content

Commit 679435c

Browse files
authored
SE_NODE_RELAY_STEREOTYPE_EXTRA to append custom capabilities to default Relay stereotype (#2625)
[skip ci] Signed-off-by: Viet Nguyen Duc <[email protected]>
1 parent 8848360 commit 679435c

File tree

9 files changed

+38
-17
lines changed

9 files changed

+38
-17
lines changed

ENV_VARIABLES.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@
125125
| SE_NODE_BROWSER_NAME | | | |
126126
| SE_NODE_CONTAINER_NAME | | | |
127127
| SE_NODE_HOST | | | |
128-
| SE_NODE_MAX_CONCURRENCY | | When node is handled both browser and relay, SE_NODE_MAX_CONCURRENCY is used to configure max concurrency based on sum of them | |
129128
| SE_NODE_RELAY_BROWSER_NAME | | | |
130129
| SE_NODE_RELAY_MAX_SESSIONS | | | |
131130
| SE_NODE_RELAY_PLATFORM_NAME | | | |
@@ -142,3 +141,5 @@
142141
| SE_SESSIONS_MAP_EXTERNAL_JDBC_USER | | | |
143142
| SE_SESSIONS_MAP_EXTERNAL_PORT | | | |
144143
| SE_SESSIONS_MAP_EXTERNAL_SCHEME | | | |
144+
| SE_NODE_RELAY_STEREOTYPE | | Capabilities in JSON string to overwrite the default Node relay stereotype | |
145+
| SE_NODE_RELAY_STEREOTYPE_EXTRA | | Extra capabilities in JSON string that wants to merge to the default Node relay stereotype | |

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ set_containerd_image_store:
7272
docker info -f '{{ .DriverStatus }}'
7373

7474
format_shell_scripts:
75-
sudo apt-get update -qq ; \
76-
sudo apt-get install -yq shfmt ; \
75+
sudo apt-get update -qq || true ; \
76+
sudo apt-get install -yq shfmt || true ; \
7777
shfmt -l -w -d $${PWD}/*.sh $${PWD}/**/*.sh $$PWD/**.sh $$PWD/**/generate_** $$PWD/**/wrap_* ; \
7878
git diff --stat --exit-code ; \
7979
EXIT_CODE=$$? ; \

NodeBase/generate_config

+1-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ 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-
# 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}}
51+
echo "max-sessions = ${SE_NODE_MAX_SESSIONS}
5352
" >>"$FILENAME"
5453

5554
if [ -f /opt/selenium/browser_name ]; then

NodeBase/generate_relay_config

+15-4
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,19 @@ if [[ -n "${SE_NODE_RELAY_URL}" ]]; then
1717
if [[ -n "${SE_NODE_RELAY_PROTOCOL_VERSION}" ]]; then
1818
echo "protocol-version = \"${SE_NODE_RELAY_PROTOCOL_VERSION}\"" >>"$FILENAME"
1919
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"
20+
if [[ -z "${SE_NODE_RELAY_STEREOTYPE}" ]]; then
21+
SE_NODE_RELAY_STEREOTYPE="{\"browserName\": \"${SE_NODE_RELAY_BROWSER_NAME}\", \"platformName\": \"${SE_NODE_RELAY_PLATFORM_NAME}\", \"appium:platformVersion\": \"${SE_NODE_RELAY_PLATFORM_VERSION}\"}"
22+
else
23+
SE_NODE_RELAY_STEREOTYPE="${SE_NODE_RELAY_STEREOTYPE}"
24+
fi
25+
if [[ -n "${SE_NODE_RELAY_STEREOTYPE_EXTRA}" ]]; then
26+
echo "Merging SE_NODE_RELAY_STEREOTYPE_EXTRA=${SE_NODE_RELAY_STEREOTYPE_EXTRA} to main relay stereotype"
27+
SE_NODE_RELAY_STEREOTYPE="$(python3 /opt/bin/json_merge.py "${SE_NODE_RELAY_STEREOTYPE}" "${SE_NODE_RELAY_STEREOTYPE_EXTRA}")"
28+
if [[ $? -ne 0 ]]; then
29+
echo "Failed to merge SE_NODE_RELAY_STEREOTYPE_EXTRA. Please check the format of the JSON string. Keep using main relay stereotype."
30+
else
31+
echo "Merged relay stereotype: ${SE_NODE_RELAY_STEREOTYPE}"
32+
fi
33+
fi
34+
echo "configs = ['${SE_NODE_RELAY_MAX_SESSIONS}', '${SE_NODE_RELAY_STEREOTYPE}']" >>"$FILENAME"
2435
fi

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,7 @@ The following is an en example of configuration relay commands.
11801180
If you want to relay commands only, `selenium/node-base` is suitable and lightweight for this purpose.
11811181
In case you want to configure node with both browsers and relay commands, respective node images can be used.
11821182
1183-
To use environment variables for generate relay configs, set `SE_NODE_RELAY_URL` and other variables as below
1183+
To use environment variables for generate relay configs, set `SE_NODE_RELAY_URL` and other variables as below. Those will be used to generate the default relay config in TOML format looks like below.
11841184
11851185
```toml
11861186
[relay]
@@ -1190,6 +1190,10 @@ protocol-version = "${SE_NODE_RELAY_PROTOCOL_VERSION}"
11901190
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}"}' ]
11911191
```
11921192
1193+
Instead of input value for each environment variable to construct the default relay stereotype, you can use the `SE_NODE_RELAY_STEREOTYPE` environment variable to overwrite the default relay stereotype with your custom stereotype.
1194+
1195+
In another case, if you want to retain the default relay stereotype and append additional capabilities, you can use the `SE_NODE_RELAY_STEREOTYPE_EXTRA` environment variable to set your capabilities. Those will be merged to the default relay stereotype.
1196+
11931197
To run a sample test with the relayed node, you can clone the project and try below command:
11941198
11951199
```bash

scripts/generate_list_env_vars/description.yaml

+7-4
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,6 @@
378378
- name: SE_NODE_HOST
379379
description: ''
380380
cli: ''
381-
- name: SE_NODE_MAX_CONCURRENCY
382-
description: When node is handled both browser and relay, SE_NODE_MAX_CONCURRENCY
383-
is used to configure max concurrency based on sum of them
384-
cli: ''
385381
- name: SE_NODE_RELAY_BROWSER_NAME
386382
description: ''
387383
cli: ''
@@ -431,3 +427,10 @@
431427
- name: SE_SESSIONS_MAP_EXTERNAL_SCHEME
432428
description: ''
433429
cli: ''
430+
- name: SE_NODE_RELAY_STEREOTYPE
431+
description: Capabilities in JSON string to overwrite the default Node relay stereotype
432+
cli: ''
433+
- name: SE_NODE_RELAY_STEREOTYPE_EXTRA
434+
description: Extra capabilities in JSON string that wants to merge to the default
435+
Node relay stereotype
436+
cli: ''

scripts/generate_list_env_vars/value.yaml

+4-2
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@
9696
default: '30'
9797
- name: SE_NODE_HOST
9898
default: ''
99-
- name: SE_NODE_MAX_CONCURRENCY
100-
default: ''
10199
- name: SE_NODE_MAX_SESSIONS
102100
default: '1'
103101
- name: SE_NODE_OVERRIDE_MAX_SESSIONS
@@ -124,6 +122,10 @@
124122
default: ''
125123
- name: SE_NODE_RELAY_STATUS_ENDPOINT
126124
default: ''
125+
- name: SE_NODE_RELAY_STEREOTYPE
126+
default: ''
127+
- name: SE_NODE_RELAY_STEREOTYPE_EXTRA
128+
default: ''
127129
- name: SE_NODE_RELAY_URL
128130
default: ''
129131
- name: SE_NODE_SESSION_TIMEOUT

tests/docker-compose-v3-test-node-relay.yml

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ services:
6868
- SE_NODE_RELAY_PLATFORM_NAME=Android
6969
- SE_NODE_RELAY_PLATFORM_VERSION=${ANDROID_PLATFORM_API}
7070
- SE_NODE_RELAY_BROWSER_NAME=chrome
71+
- SE_NODE_RELAY_STEREOTYPE_EXTRA={"myApp:version":"beta","myApp:publish":"public"}
7172
- SE_NODE_RELAY_WEB_VNC=ws://emulator:6080/websockify
7273

7374
emulator:

tests/relay_config.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ max-sessions = 1
1313
url = "http://standalone:4444/wd/hub"
1414
status-endpoint = "/status"
1515
configs = [
16-
'1', '{"browserName":"${BROWSER_NAME}","platformName":"linux"}'
16+
'3', '{"browserName":"${BROWSER_NAME}","platformName":"linux"}'
1717
]

0 commit comments

Comments
 (0)