You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<!-- Thanks for sending us a PR to improve this project! If you are adding a
2
+
feature or fixing a bug, and this needs more documentation, please add it to your PR. -->
3
+
4
+
1
5
-[ ] By placing an `X` in the preceding checkbox, I verify that I have signed the [Contributor License Agreement](https://github.com/SeleniumHQ/docker-selenium/blob/master/CONTRIBUTING.md#contributing-code-to-selenium)
Copy file name to clipboardExpand all lines: Base/Dockerfile
+14Lines changed: 14 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -25,6 +25,8 @@ RUN apt-get -qqy update \
25
25
sudo \
26
26
unzip \
27
27
wget \
28
+
jq \
29
+
curl \
28
30
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/* \
29
31
&& sed -i 's/securerandom\.source=file:\/dev\/random/securerandom\.source=file:\/dev\/urandom/' ./usr/lib/jvm/java-8-openjdk-amd64/jre/lib/security/java.security
Copy file name to clipboardExpand all lines: README.md
+95Lines changed: 95 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -269,6 +269,101 @@ $ FF=$(docker run --rm --name=fx \
269
269
270
270
_Note: Since a Docker container is not meant to preserve state and spawning a new one takes less than 3 seconds you will likely want to remove containers after each end-to-end test with_ `--rm` _command. You need to think of your Docker containers as single processes, not as running virtual machines, in case you are familiar with [Vagrant](https://www.vagrantup.com/)._
271
271
272
+
## Waiting for the Grid to be ready
273
+
274
+
It is a good practice to check first if the Grid is up and ready to receive requests, this can be done by checking the `/wd/hub/status` endpoint.
275
+
276
+
A Grid that is ready, composed by a hub and a node, could look like this:
277
+
278
+
```json
279
+
{
280
+
"status": 0,
281
+
"value": {
282
+
"ready": true,
283
+
"message": "Hub has capacity",
284
+
"build": {
285
+
"revision": "aacccce0",
286
+
"time": "2018-08-02T20:13:22.693Z",
287
+
"version": "3.14.0"
288
+
},
289
+
"os": {
290
+
"arch": "amd64",
291
+
"name": "Linux",
292
+
"version": "4.9.93-linuxkit-aufs"
293
+
},
294
+
"java": {
295
+
"version": "1.8.0_181"
296
+
}
297
+
}
298
+
}
299
+
```
300
+
301
+
The `"ready": true` value indicates that the Grid is ready to receive requests. This status can be polled through a
302
+
script before running any test, or it can be added as a [HEALTHCHECK](https://docs.docker.com/engine/reference/run/#healthcheck)
303
+
when the docker container is started.
304
+
305
+
### Adding a [HEALTHCHECK](https://docs.docker.com/engine/reference/run/#healthcheck) to the Grid
306
+
307
+
The script [check-grid.sh](Base/check-grid.sh), which is included in the images, can be used to poll the Grid status.
308
+
309
+
This example checks the status of the Grid every 15 seconds, it has a timeout of 30 seconds when the check is done,
310
+
and it retries up to 5 times until the container is marked as unhealthy. Please use adjusted values to fit your needs,
311
+
(if needed) replace the `--host` and `--port` parameters for the ones used in your environment.
A common problem known in docker is that a running container does not always mean that the application inside it is ready.
335
+
A simple way to tackle this is by using a "wait-for-it" script, more information can be seen [here](https://docs.docker.com/compose/startup-order/).
336
+
337
+
The following script is an example of how this can be done using bash, but the same principle applies if you want to do this with the programming language used to write the tests.
338
+
339
+
```bash
340
+
#!/bin/bash
341
+
# wait-for-grid.sh
342
+
343
+
set -e
344
+
345
+
cmd="$@"
346
+
347
+
while ! curl -sSL "http://localhost:4444/wd/hub/status" 2>&1 \
348
+
| jq -r '.value.ready' 2>&1 | grep "true" >/dev/null; do
349
+
echo 'Waiting for the Grid'
350
+
sleep 1
351
+
done
352
+
353
+
>&2 echo "Selenium Grid is up - executing tests"
354
+
exec $cmd
355
+
```
356
+
**Note:** If needed, replace `localhost` and `4444` for the correct values in your environment. Also, this script is polling indefinitely, you might want
357
+
to tweak it and establish a timeout.
358
+
359
+
Let's say that the normal command to execute your tests is `mvn clean test`. Here is a way to use the above script and execute your tests:
360
+
361
+
```bash
362
+
$ ./wait-for-grid.sh mvn clean test
363
+
```
364
+
365
+
Like this, the script will poll until the Grid is ready, and then your tests will start.
366
+
272
367
## Debugging
273
368
274
369
In the event you wish to visually see what the browser is doing you will want to run the `debug` variant of node or standalone images. A VNC server will run on port 5900. You are free to map that to any free external port that you wish. Keep in mind that you will only be able to run one node per port so if you wish to include a second node, or more, you will have to use different ports, the 5900 as the internal port will have to remain the same though as thats the VNC service on the node. The second example below shows how to run multiple nodes and with different VNC ports open:
0 commit comments