Skip to content
This repository was archived by the owner on Jun 30, 2021. It is now read-only.

Commit 393bcbe

Browse files
committed
Test offline site (mocked http server)
1 parent a925f3d commit 393bcbe

14 files changed

+96
-44
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Note image ids also change after scm-source.json has being updated which trigger
1515
+ Add docs/share-host.md and docs/jenkins.md (WIP)
1616
+ Chore: Add `WORKDIR ${NORMAL_USER_HOME}`
1717
+ Chore: Add `docker exec grid cat HUB_PORT #=> 24444`
18+
+ Chore: Test offline site (mocked http server)
1819
+ Image tag details:
1920
+ Selenium: vTBD_SELENIUM_VERSION (TBD_SELENIUM_REVISION)
2021
+ Chrome stable: TBD_CHROME_STABLE

Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ ENV DEBIAN_FRONTEND=noninteractive \
4141
RUN apt-key adv --recv-keys --keyserver keyserver.ubuntu.com \
4242
3B4FE6ACC0B21F32 \
4343
40976EAF437D05B5 \
44-
2EA8F35793D8809A
44+
2EA8F35793D8809A \
45+
&& apt-key update -qqy
4546

4647
#========================
4748
# Miscellaneous packages
@@ -893,6 +894,7 @@ ADD **/etc/supervisor/conf.d/* /etc/supervisor/conf.d/
893894
#==============================================
894895
# See: SeleniumHQ/docker-selenium/issues/14
895896
RUN apt-get update -qqy \
897+
&& apt-key update -qqy \
896898
&& apt-get -qqy install \
897899
haveged rng-tools \
898900
&& service haveged start \
@@ -975,7 +977,7 @@ ENV FIREFOX_VERSION="${FF_VER}" \
975977
# How often in ms the node will try to register itself again.
976978
# Allow to restart the hub without having to restart the nodes.
977979
# (node) in ms. Selenium default: 5000
978-
SELENIUM_NODE_REGISTER_CYCLE="0" \
980+
SELENIUM_NODE_REGISTER_CYCLE="5000" \
979981
# To taggle issue #58 see https://goo.gl/fz6RTu
980982
CHROME_ARGS="--no-sandbox" \
981983
# e.g. CHROME_ARGS="--no-sandbox --ignore-certificate-errors" \

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ See [docker-compose](./docs/docker-compose.md)
100100
See [jenkins](./docs/jenkins.md)
101101

102102
### Parallel
103-
This image is designed to run one test on each docker container but if you still want to run multiple tests in parallel you can still do, there are some ways to do this:
103+
This image is designed to run one test on each docker container but if you still want to run multiple tests in parallel you can still do so, there are some ways to do this:
104104

105-
1. The recommended way is via [docker-compose](./docs/docker-compose.md)
105+
1. The recommended way is via [docker-compose](./docs/docker-compose.md) and you should replace `adwords_mock` with your web service under test within the [docker-compose.yml][] file.
106106

107-
SELENIUM_HUB_PORT=4444 docker-compose -p selenium scale hub=1 chrome=3 firefox=3
107+
SELENIUM_HUB_PORT=4444 docker-compose -p selenium scale adwords_mock=1 hub=1 chrome=3 firefox=3
108108

109109
1. The _(not recommended)_ way is by increasing `MAX_INSTANCES` and `MAX_SESSIONS` which now [defaults](https://github.com/elgalu/docker-selenium/blob/2.53.1a/Dockerfile#L967) to 1.
110110

@@ -499,3 +499,4 @@ Powered by Supervisor, the container leaves many logs;
499499
[sauce]: https://saucelabs.com/selenium/selenium-grid
500500
[BrowserStack]: https://www.browserstack.com/automate
501501
[xvfb-electron]: http://electron.atom.io/docs/tutorial/testing-on-headless-ci
502+
[docker-compose.yml]: ./docker-compose.yml

docker-compose-host.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ services:
1111
- GRID=true
1212
- CHROME=false
1313
- FIREFOX=false
14+
- MOCK_SERVER_PORT=33001
1415

1516
chrome:
1617
image: elgalu/selenium
17-
depends_on:
18-
- hub
1918
network_mode: host
2019
shm_size: 1g
2120
environment:
@@ -25,11 +24,10 @@ services:
2524
- GRID=false
2625
- CHROME=true
2726
- FIREFOX=false
27+
- MOCK_SERVER_PORT=33001
2828

2929
firefox:
3030
image: elgalu/selenium
31-
depends_on:
32-
- hub
3331
network_mode: host
3432
environment:
3533
- SELENIUM_HUB_PORT
@@ -38,6 +36,13 @@ services:
3836
- GRID=false
3937
- CHROME=false
4038
- FIREFOX=true
39+
- MOCK_SERVER_PORT=33001
40+
41+
adwords_mock:
42+
image: elgalu/google_adwords_mock
43+
network_mode: host
44+
environment:
45+
- MOCK_SERVER_PORT=33001
4146

4247
#-- Notes --#
4348
# shm_size: 1g

docker-compose.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ services:
1212
- GRID=true
1313
- CHROME=false
1414
- FIREFOX=false
15+
- MOCK_SERVER_PORT=33001
1516

1617
chrome:
1718
image: elgalu/selenium
@@ -24,6 +25,7 @@ services:
2425
- GRID=false
2526
- CHROME=true
2627
- FIREFOX=false
28+
- MOCK_SERVER_PORT=33001
2729

2830
firefox:
2931
image: elgalu/selenium
@@ -35,6 +37,14 @@ services:
3537
- GRID=false
3638
- CHROME=false
3739
- FIREFOX=true
40+
- MOCK_SERVER_PORT=33001
41+
42+
adwords_mock:
43+
image: elgalu/google_adwords_mock
44+
network_mode: "service:hub"
45+
environment:
46+
- MOCK_SERVER_PORT=33001
47+
3848

3949
#-- Notes --#
4050
# shm_size: 1g

docs/docker-compose.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Either clone this repository or download the file [docker-compose.yml][] using `
1313

1414
### Run
1515
Start it with `docker-compose up` then **scale** it:
16+
You should replace `adwords_mock` with your web service under test within the [docker-compose.yml][] file.
1617

1718
export SELENIUM_HUB_PORT=4444 NODES=3
1819
docker-compose -p selenium up -d
@@ -29,8 +30,8 @@ Wait until the grid starts properly before starting the tests _(Optional but rec
2930
### Test
3031
You can now run your tests by using the `--seleniumUrl="http://localhost:4444/wd/hub"`.
3132

32-
However if your web application under test is running in localhost, e.g. `--appHost=localhost`
33-
you should instead either dockerize your application and add it to the [docker-compose.yml][] file as another [service](https://docs.docker.com/compose/compose-file/#/service-configuration-reference) or somehow replace `--appHost=localhost` with `--appHost=d.host.loc.dev` in the config file of your testing framework. The string `d.host.loc.dev` is a place holder inside the docker container that points to the IP of your localhost.
33+
However if your web application under test is running in localhost, e.g. `--appHost=localhost` or is publicly not accessible
34+
you should instead either dockerize your application as shown in the example [adwords_mock](https://github.com/elgalu/google_adwords_mock) within the [docker-compose.yml][]. Its there shown as another [service](https://docs.docker.com/compose/compose-file/#/service-configuration-reference). Another option (if you don't want to dockerize your app yet) is to somehow replace `--appHost=localhost` with `--appHost=d.host.loc.dev` in the config file of your testing framework. The string `d.host.loc.dev` is a place holder inside the docker container that points to the IP of your localhost.
3435

3536
### Cleanup
3637
Once your tests are done you can clean up:

docs/share-host.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@ For using it non-Linux machines or, in general, by not sharing the host (localho
66
For requirements check [README#requisites](../README.md#requisites)
77

88
## Usage
9-
Either clone this repository or download the file [docker-compose-host.yml](../docker-compose-host.yml) using `wget`
9+
Either clone this repository or download the file [docker-compose-host.yml][] using `wget`
1010

1111
wget -nv "https://raw.githubusercontent.com/elgalu/docker-selenium/master/docker-compose-host.yml"
1212
mv -f docker-compose-host.yml docker-compose.yml
1313
docker-compose -p selenium down #ensure is not already running
1414

1515
### Run
1616
Either start with `docker-compose ... scale` as shown in below example or you can also use `docker-compose up` and scale after in a second command.
17+
You should replace `adwords_mock` with your web service under test within the [docker-compose-host.yml][] file..
1718

1819
export SELENIUM_HUB_PORT=4444 NODES=3
19-
docker-compose -p selenium scale hub=1 chrome=${NODES} firefox=${NODES}
20+
docker-compose -p selenium scale adwords_mock=1 hub=1 chrome=${NODES} firefox=${NODES}
2021

2122
Wait until the grid starts properly before starting the tests _(Optional but recommended)_
2223

@@ -36,3 +37,5 @@ Once your tests are done you can clean up:
3637
docker-compose -p selenium down
3738

3839
The `down` compose command stops and remove containers, networks, volumes, and images created by `up` or `scale`
40+
41+
[docker-compose-host.yml]: ../docker-compose-host.yml

misc/misc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Miscellaneous internal notes, do not read!
33
## Build
44

55
time (docker build -t elgalu/selenium . ;echo $?;beep)
6-
docker run --rm -ti -m 3000M --name=local -p=4444:24444 -p=5900:25900 -e VIDEO=true -v /dev/shm:/dev/shm elgalu/selenium
6+
docker run --rm -ti -m 3000M --name=local -e SELENIUM_HUB_PORT=4444 -p=4444:4444 -p=5900:25900 -e VIDEO=true -e VNC_PASSWORD=hola -v /dev/shm:/dev/shm elgalu/selenium
77

88
### Wait
99
Wait and get versions

test/after_script

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@ set -e
77
docker exec grid stop || true
88
docker stop grid || true
99
docker rm grid || true
10-
11-
# fast wait
12-
# docker rm -vf grid || true
10+
# quick destroy
11+
docker rm -vf grid_adwords_mock || true

test/compose-test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ if [ "${DO_COMPOSE_UP}" = "true" ]; then
3333
fi
3434

3535
# Compose scale!
36-
docker-compose -f ${COMPOSE_FILE} -p selenium scale hub=1 chrome=${NUM_NODES} firefox=${NUM_NODES}
36+
docker-compose -f ${COMPOSE_FILE} -p selenium scale adwords_mock=1 hub=1 chrome=${NUM_NODES} firefox=${NUM_NODES}
3737

3838
# FIXME: We still need to wait a bit because the nodes registration is not
3939
# being waited on wait_all_done script :(

0 commit comments

Comments
 (0)