Skip to content

Commit 0ba9433

Browse files
authored
WIP Adding noVNC to docker-selenium (#1253)
1 parent 4ce1f7b commit 0ba9433

File tree

7 files changed

+158
-81
lines changed

7 files changed

+158
-81
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
NAME := $(or $(NAME),$(NAME),selenium)
22
CURRENT_DATE := $(shell date '+%Y%m%d')
33
BUILD_DATE := $(or $(BUILD_DATE),$(BUILD_DATE),$(CURRENT_DATE))
4-
VERSION := $(or $(VERSION),$(VERSION),4.0.0-beta-2)
4+
VERSION := $(or $(VERSION),$(VERSION),4.0.0-beta-3)
55
TAG_VERSION := $(VERSION)-$(BUILD_DATE)
66
NAMESPACE := $(or $(NAMESPACE),$(NAMESPACE),$(NAME))
77
AUTHORS := $(or $(AUTHORS),$(AUTHORS),SeleniumHQ)

NodeBase/Dockerfile.txt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,25 @@ RUN apt-get -qqy update \
8181
&& rm -rf /var/lib/apt/lists/* \
8282
&& apt-get -qyy clean
8383

84+
########################################
85+
# noVNC exposes VNC through a web page #
86+
########################################
87+
# Download https://github.com/novnc/noVNC dated 2021-03-30 commit 84f102d6a9ffaf3972693d59bad5c6fddb6d7fb0
88+
# Download https://github.com/novnc/websockify dated 2021-03-22 commit c5d365dd1dbfee89881f1c1c02a2ac64838d645f
89+
ENV NOVNC_SHA="84f102d6a9ffaf3972693d59bad5c6fddb6d7fb0" \
90+
WEBSOCKIFY_SHA="c5d365dd1dbfee89881f1c1c02a2ac64838d645f"
91+
RUN wget -nv -O noVNC.zip \
92+
"https://github.com/novnc/noVNC/archive/${NOVNC_SHA}.zip" \
93+
&& unzip -x noVNC.zip \
94+
&& mv noVNC-${NOVNC_SHA} /opt/bin/noVNC \
95+
&& cp /opt/bin/noVNC/vnc.html /opt/bin/noVNC/index.html \
96+
&& rm noVNC.zip \
97+
&& wget -nv -O websockify.zip \
98+
"https://github.com/novnc/websockify/archive/${WEBSOCKIFY_SHA}.zip" \
99+
&& unzip -x websockify.zip \
100+
&& rm websockify.zip \
101+
&& mv websockify-${WEBSOCKIFY_SHA} /opt/bin/noVNC/utils/websockify
102+
84103
#===================================================
85104
# Run the following commands as non-privileged user
86105
#===================================================
@@ -115,9 +134,10 @@ RUN sudo chmod -R 777 ${HOME} \
115134
&& sudo chmod -R g=u ${HOME}
116135

117136
#==============================
118-
# Scripts to run fluxbox and x11vnc
137+
# Scripts to run fluxbox, x11vnc and noVNC
119138
#==============================
120139
COPY start-vnc.sh \
140+
start-novnc.sh \
121141
/opt/bin/
122142

123143
#==============================

NodeBase/selenium.conf

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
; Documentation of this file format -> http://supervisord.org/configuration.html
22

3-
; Priority 0 - xvfb, 5 - fluxbox, 10 - x11vnc, 15 - selenium-node
3+
; Priority 0 - xvfb & fluxbox, 5 - x11vnc, 10 - noVNC, 15 - selenium-node
44

55
[program:xvfb]
66
priority=0
@@ -22,7 +22,7 @@ stdout_capture_maxbytes=50MB
2222
stderr_capture_maxbytes=50MB
2323

2424
[program:vnc]
25-
priority=10
25+
priority=5
2626
command=/opt/bin/start-vnc.sh
2727
autostart=true
2828
autorestart=false
@@ -40,6 +40,25 @@ stderr_logfile_backups=5
4040
stdout_capture_maxbytes=50MB
4141
stderr_capture_maxbytes=50MB
4242

43+
[program:novnc]
44+
priority=10
45+
command=/opt/bin/start-novnc.sh
46+
autostart=true
47+
autorestart=false
48+
startsecs=0
49+
startretries=0
50+
51+
;Logs
52+
redirect_stderr=false
53+
stdout_logfile=/var/log/supervisor/novnc-stdout.log
54+
stderr_logfile=/var/log/supervisor/novnc-stderr.log
55+
stdout_logfile_maxbytes=50MB
56+
stderr_logfile_maxbytes=50MB
57+
stdout_logfile_backups=5
58+
stderr_logfile_backups=5
59+
stdout_capture_maxbytes=50MB
60+
stderr_capture_maxbytes=50MB
61+
4362
[program:selenium-node]
4463
priority=15
4564
command=/opt/bin/start-selenium-node.sh

NodeBase/start-novnc.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
#
3+
# IMPORTANT: Change this file only in directory NodeBase!
4+
5+
if [ "${START_XVFB}" = true ] ; then
6+
/opt/bin/noVNC/utils/launch.sh --listen 7900 --vnc localhost:5900
7+
else
8+
echo "noVNC won't start because Xvfb is configured to not start."
9+
fi

NodeBase/start-vnc.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@
44

55
if [ "${START_XVFB}" = true ] ; then
66
# Centering wallpaper
7-
echo "Centering wallpaper"
8-
/usr/bin/fbsetbg -c /usr/share/images/fluxbox/ubuntu-light.png
7+
for i in $(seq 1 10)
8+
do
9+
sleep 0.5
10+
echo "Centering wallpaper"
11+
/usr/bin/fbsetbg -c /usr/share/images/fluxbox/ubuntu-light.png
12+
if [ $? -eq 0 ]; then
13+
break
14+
fi
15+
done
916

1017
if [ ! -z $VNC_NO_PASSWORD ]; then
1118
echo "Starting VNC server without password authentication"

README.md

Lines changed: 76 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ and made the source code freely available under the [Apache License 2.0](LICENSE
77
![Deployments](https://github.com/SeleniumHQ/docker-selenium/workflows/Deploys/badge.svg)
88

99
# :point_right: Status: Grid 4 is under development and on a [Beta stage](https://en.wikipedia.org/wiki/Software_release_life_cycle#Beta)
10-
We are doing prereleases on a regular basis to get early feedback. This means that all other Selenium components
11-
can be currently at a different alpha version (e.g. bindings on Beta 1, and Docker images on prerelease Beta 2).
10+
Prereleases are happening on a regular basis to get early feedback. This means that all other Selenium components
11+
can be currently at a different beta version (e.g. bindings on Beta 2, and Docker images on prerelease Beta 3).
1212

1313
Docker images for Grid 4 come with a handful of tags to simplify its usage, have a look at them in one of
14-
our [prereleases](https://github.com/SeleniumHQ/docker-selenium/releases/tag/4.0.0-beta-3-prerelease-20210329)
14+
our [releases](https://github.com/SeleniumHQ/docker-selenium/releases/tag/4.0.0-beta-3-prerelease-20210329)
1515

16-
To get notifications of new prereleases, add yourself as a watcher of "Releases only".
16+
To get notifications of new prereleases, add yourself as a "Releases only" watcher.
1717

18-
Doubts or questions? Please get in touch through the different communication channels available in the **Community** section.
18+
Doubts? Questions? Get in touch through the different communication channels available in the **Community** section.
1919

2020
Looking for Grid 3? Head to the [Selenium 3 branch](https://github.com/SeleniumHQ/docker-selenium/tree/selenium-3). This branch
21-
will be having new browser releases until Grid 4 has its major release.
21+
will be having new browser releases until Grid 4 has had its major release.
2222

2323
## Community
2424

@@ -31,32 +31,30 @@ https://www.selenium.dev/support/
3131
1. Start a Docker container with Firefox
3232

3333
``` bash
34-
$ docker run -d -p 4444:4444 --shm-size 2g selenium/standalone-firefox:4.0.0-beta-3-prerelease-20210329
34+
$ docker run -d -p 4444:4444 -p 7900:7900 --shm-size 2g selenium/standalone-firefox:4.0.0-beta-3-prerelease-20210329
3535
# OR
36-
$ docker run -d -p 4444:4444 -v /dev/shm:/dev/shm selenium/standalone-firefox:4.0.0-beta-3-prerelease-20210329
36+
$ docker run -d -p 4444:4444 -p 7900:7900 -v /dev/shm:/dev/shm selenium/standalone-firefox:4.0.0-beta-3-prerelease-20210329
3737
```
3838

3939
2. Point your WebDriver tests to http://localhost:4444/wd/hub
4040

4141
3. That's it!
4242

43-
To inspect visually the browser activity, see the [Debugging](#debugging) section for details.
43+
4. (Optional) To see what is happening inside the container, head to http://localhost:7900 (password is `secret`).
44+
45+
More details about visualising the container activity, check the [Debugging](#debugging) section.
4446

4547
:point_up: When executing `docker run` for an image that contains a browser please either mount
4648
`-v /dev/shm:/dev/shm` or use the flag `--shm-size=2g` to use the host's shared memory.
4749

48-
> Why is `-v /dev/shm:/dev/shm` or `--shm-size 2g` necessary?
49-
> This is a known workaround to avoid the browser crashing inside a docker container, here are the documented issues for
50-
[Chrome](https://code.google.com/p/chromium/issues/detail?id=519952) and [Firefox](https://bugzilla.mozilla.org/show_bug.cgi?id=1338771#c10).
51-
The shm size of 2gb is arbitrary but known to work well, your specific use case might need a different value, it is recommended
52-
to tune this value according to your needs. Along the examples `-v /dev/shm:/dev/shm` will be used, but both are known to work.
53-
5450
:point_up: Always use a Docker image with a full tag to pin a specific browser and Grid version.
5551
See [Tagging Conventions](https://github.com/SeleniumHQ/docker-selenium/wiki/Tagging-Convention) for details.
5652

5753
___
5854

59-
## Standalone
55+
## Execution modes
56+
57+
### Standalone
6058

6159
![Firefox](https://raw.githubusercontent.com/alrra/browser-logos/main/src/firefox/firefox_24x24.png) Firefox
6260
``` bash
@@ -82,11 +80,11 @@ _Note: Only one Standalone container can run on port_ `4444` _at the same time._
8280

8381
___
8482

85-
## Selenium Grid Hub and Nodes
83+
### Hub and Nodes
8684

8785
There are different ways to run the images and create a Grid with a Hub and Nodes, check the following options.
8886

89-
### Docker networking
87+
#### Docker networking
9088
The Hub and Nodes will be created in the same network and they will recognize each other by their container name.
9189
A Docker [network](https://docs.docker.com/engine/reference/commandline/network_create/) needs to be created as a first step.
9290

@@ -122,7 +120,7 @@ When you are done using the Grid, and the containers have exited, the network ca
122120
$ docker network rm grid
123121
```
124122

125-
### Using different machines/VMs
123+
#### Using different machines/VMs
126124
The Hub and Nodes will be created on different machines/VMs, they need to know each other's IPs to
127125
communicate properly.
128126

@@ -175,26 +173,26 @@ $ docker run -d -p 5555:5555
175173
selenium/node-opera:4.0.0-beta-3-prerelease-20210329
176174
```
177175

178-
### Docker Compose
176+
#### Docker Compose
179177
[Docker Compose](https://docs.docker.com/compose/) is the simplest way to start a Grid. Use the
180178
linked resources below, save them locally, and check the execution instructions on top of each file.
181179

182-
#### Version 2
180+
##### Version 2
183181
[`docker-compose-v2.yml`](docker-compose-v2.yml)
184182

185-
#### Version 3
183+
##### Version 3
186184
[`docker-compose-v3.yml`](docker-compose-v3.yml)
187185

188186
To stop the Grid and cleanup the created containers, run `docker-compose down`.
189187

190-
#### Version 3 with Swarm support
188+
##### Version 3 with Swarm support
191189
[`docker-compose-v3-swarm.yml`](docker-compose-v3-swarm.yml)
192190

193191
___
194192

195-
## Selenium Grid - Router, Distributor, EventBus, SessionMap and Nodes
193+
### Fully distributed mode - Router, Queue, Distributor, EventBus, SessionMap and Nodes
196194

197-
It is possible to start a Selenium Grid with its five components apart. For simplicity, only an
195+
It is possible to start a Selenium Grid with all its components apart. For simplicity, only an
198196
example with docker-compose will be provided. Save the file locally, and check the execution
199197
instructions on top of it.
200198

@@ -204,7 +202,7 @@ ___
204202

205203
## Video recording ![BETA](https://img.shields.io/badge/beta!-blue?style=for-the-badge)
206204

207-
It is possible to record your tests running in containers by using the `selenium/video:ffmpeg-4.3.1-20210329`
205+
Tests execution can be recorded by using the `selenium/video:ffmpeg-4.3.1-20210329`
208206
Docker image. One container is needed per each container where a browser is running. This means if you are
209207
running 5 Nodes/Standalone containers, you will need 5 video containers, the mapping is 1-1.
210208

@@ -422,8 +420,8 @@ Grid has a default session timeout of 300 seconds, where the session can be on a
422420
### Running in Headless mode
423421

424422
[Firefox](https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Headless_mode),
425-
[Chrome](https://developers.google.com/web/updates/2017/04/headless-chrome) and
426-
[Opera](https://forums.opera.com/topic/20375/opera-cli-switches-and-headless) support running tests in the headless mode.
423+
[Chrome](https://developers.google.com/web/updates/2017/04/headless-chrome),
424+
[Opera](https://forums.opera.com/topic/20375/opera-cli-switches-and-headless) and Edge support running tests in the headless mode.
427425
When using headless mode, there's no need for the [Xvfb](https://en.wikipedia.org/wiki/Xvfb) server to be started.
428426

429427
To avoid starting the server you can set the `START_XVFB` environment variable to `false`
@@ -455,31 +453,6 @@ $ BUILD_ARGS="--build-arg http_proxy=http://acme:3128 --build-arg https_proxy=ht
455453
_Note: Omitting_ `VERSION=local` _will build the images with the released version but replacing the date for the
456454
current one._
457455

458-
## Using the images
459-
460-
### Example: Spawn a container for testing in Firefox ![Firefox](https://raw.githubusercontent.com/alrra/browser-logos/main/src/firefox/firefox_24x24.png)
461-
462-
``` bash
463-
$ docker network create grid
464-
$ docker run -d -p 4442-4444:4442-4444 --net grid --name selenium-hub selenium/hub:4.0.0-beta-3-prerelease-20210329
465-
$ docker run -d --net grid -e SE_EVENT_BUS_HOST=selenium-hub \
466-
-e SE_EVENT_BUS_PUBLISH_PORT=4442 -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 \
467-
-v /dev/shm:/dev/shm \
468-
-v /e2e/uploads:/e2e/uploads selenium/node-firefox:4.0.0-beta-3-prerelease-20210329
469-
```
470-
471-
_Note:_ `-v /e2e/uploads:/e2e/uploads` _is optional in case you are testing browser uploads on your
472-
web app you will probably need to share a directory for this._
473-
474-
This command line for Opera or Chrome is almost the same, only remember to replace the image name for
475-
`node-opera` or `node-chrome`. Remember that the Selenium running container is able to launch either
476-
Chrome, Opera or Firefox, the idea around having 3 separate containers, one for each browser is for convenience plus
477-
avoiding certain `:focus` issues your web app may encounter during end-to-end test automation.
478-
479-
_Note: Since a Docker container should not preserve state and spawning a new one takes less than 3 seconds you
480-
will likely want to remove containers after each end-to-end test with_ `--rm` _command. You need to think of your
481-
Docker containers as single processes, not as running virtual machines._
482-
483456
___
484457

485458
## Waiting for the Grid to be ready
@@ -603,37 +576,34 @@ ___
603576

604577
## Debugging
605578

606-
In the event you wish to see what the browser is doing, you can check what is going inside by connecting to the VNC
607-
server running on port 5900 inside the browser container.
579+
This project uses [x11vnc](https://github.com/LibVNC/x11vnc) as VNC server to allow users inspect what is happening
580+
inside the container. Users can connect to this server in two ways:
581+
582+
### Using a VNC client
608583

609-
You are free to map that port to any free external port that you wish. Keep in mind that you will only be able to run
610-
one node per port. If you wish to include a second node (or more), you will have to use different ports.
584+
The VNC server is listening to port 5900, you can use a VNC client and connect to it. Feel free to map port 5900 to
585+
any free external port that you wish.
611586

612-
The internal 5900 port will need to remain the same because that is the configured port for the VNC server
613-
running inside the container.
587+
The internal 5900 port remains the same because that is the configured port for the VNC server running inside the container.
614588

615589
Here is an example with the standalone images, the same concept applies to the node images.
616590
``` bash
617591
$ docker run -d -p 4444:4444 -p 5900:5900 -v /dev/shm:/dev/shm selenium/standalone-chrome:4.0.0-beta-3-prerelease-20210329
618-
$ docker run -d -p 4444:4444 -p 5900:5900 -v /dev/shm:/dev/shm selenium/standalone-edge:4.0.0-beta-3-prerelease-20210329
619-
$ docker run -d -p 4445:4444 -p 5901:5900 -v /dev/shm:/dev/shm selenium/standalone-firefox:4.0.0-beta-3-prerelease-20210329
620-
$ docker run -d -p 4446:4444 -p 5902:5900 -v /dev/shm:/dev/shm selenium/standalone-opera:4.0.0-beta-3-prerelease-20210329
592+
$ docker run -d -p 4444:4444 -p 5901:5900 -v /dev/shm:/dev/shm selenium/standalone-edge:4.0.0-beta-3-prerelease-20210329
593+
$ docker run -d -p 4445:4444 -p 5902:5900 -v /dev/shm:/dev/shm selenium/standalone-firefox:4.0.0-beta-3-prerelease-20210329
594+
$ docker run -d -p 4446:4444 -p 5903:5900 -v /dev/shm:/dev/shm selenium/standalone-opera:4.0.0-beta-3-prerelease-20210329
621595
```
622596

623597
Then, you would use in your VNC client:
624598
- Port 5900 to connect to the Chrome container
625-
- Port 5901 to connect to the Firefox container
626-
- Port 5902 to connect to the Opera container
599+
- Port 5901 to connect to the Edge container
600+
- Port 5902 to connect to the Firefox container
601+
- Port 5903 to connect to the Opera container
627602

628-
In case you have [RealVNC](https://www.realvnc.com/) binary `vnc` in your path, you can always take a look, select view
629-
only to avoid messing around your tests with an unintended mouse click or keyboard interrupt:
630-
``` bash
631-
$ ./bin/vncview 127.0.0.1:5900
632-
```
633-
634-
When you are prompted for the password it is `secret`. If you wish to change this then you should either change
603+
If you get a prompt asking for a password, it is: `secret`. If you wish to change this, you should either change
635604
it in the `/NodeBase/Dockerfile` and build the images yourself, or you can define a Docker image that derives from
636605
the posted ones which reconfigures it:
606+
637607
``` dockerfile
638608
#FROM selenium/node-chrome:4.0.0-beta-3-prerelease-20210329
639609
#FROM selenium/node-edge:4.0.0-beta-3-prerelease-20210329
@@ -646,6 +616,30 @@ RUN x11vnc -storepasswd <your-password-here> /home/seluser/.vnc/passwd
646616

647617
If you want to run VNC without password authentication you can set the environment variable `VNC_NO_PASSWORD=1`.
648618

619+
### Using your browser (no VNC client is needed)
620+
621+
This project uses [noVNC](https://github.com/novnc/noVNC) to allow users inspect visually container activity with
622+
their browser. This might come handy if you cannot install a VNC client on your machine. Port 7900 is used to start
623+
noVNC, so you will need to connect to that port with your browser.
624+
625+
Similarly to the previous section, feel free to map port 5900 to any free external port that you wish.
626+
627+
Here is an example with the standalone images, the same concept applies to the node images.
628+
``` bash
629+
$ docker run -d -p 4444:4444 -p 7900:7900 -v /dev/shm:/dev/shm selenium/standalone-chrome:4.0.0-beta-3-prerelease-20210329
630+
$ docker run -d -p 4444:4444 -p 7901:7900 -v /dev/shm:/dev/shm selenium/standalone-edge:4.0.0-beta-3-prerelease-20210329
631+
$ docker run -d -p 4445:4444 -p 7902:7900 -v /dev/shm:/dev/shm selenium/standalone-firefox:4.0.0-beta-3-prerelease-20210329
632+
$ docker run -d -p 4446:4444 -p 7903:7900 -v /dev/shm:/dev/shm selenium/standalone-opera:4.0.0-beta-3-prerelease-20210329
633+
```
634+
635+
Then, you would use in your browser:
636+
- http://localhost:7900/ to connect to the Chrome container
637+
- http://localhost:7901/ to connect to the Edge container
638+
- http://localhost:7902/ to connect to the Firefox container
639+
- http://localhost:7903/ to the Opera container
640+
641+
If you get a prompt asking for a password, it is: `secret`.
642+
649643
___
650644

651645
## Troubleshooting
@@ -655,11 +649,20 @@ All output gets sent to stdout, so it can be inspected by running:
655649
$ docker logs -f <container-id|container-name>
656650
```
657651

658-
You can turn on debugging by passing environment variable to the hub and the nodes containers:
652+
You can increase the log output by passing environment variable to the containers:
659653
```
660-
GRID_DEBUG=true
654+
SE_OPTS="--log-level FINE"
661655
```
662656

657+
### `-v /dev/shm:/dev/shm` or `--shm-size 2g`
658+
659+
Why is `-v /dev/shm:/dev/shm` or `--shm-size 2g` necessary?
660+
> This is a known workaround to avoid the browser crashing inside a docker container, here are the documented issues for
661+
[Chrome](https://code.google.com/p/chromium/issues/detail?id=519952) and [Firefox](https://bugzilla.mozilla.org/show_bug.cgi?id=1338771#c10).
662+
The shm size of 2gb is arbitrary but known to work well, your specific use case might need a different value, it is recommended
663+
to tune this value according to your needs. Along the examples `-v /dev/shm:/dev/shm` will be used, but both are known to work.
664+
665+
663666
### Headless
664667

665668
If you see the following selenium exceptions:

0 commit comments

Comments
 (0)