|
| 1 | +# Selenoud |
| 2 | +Microservice acting like Selenium Hub, but launching Selenium nodes within Docker containers per session request. |
| 3 | + |
| 4 | + |
| 5 | +## Quick Start Guide |
| 6 | +1. Install [Docker](https://www.docker.com/). |
| 7 | +2. Create ```/etc/selenoud/images.json``` file. This file maps browser versions to Docker containers. The file must have the following structure: |
| 8 | + ```json |
| 9 | + { |
| 10 | + "images": { |
| 11 | + "chrome": { "image": "selenium/node-chrome:latest", "path": "/wd/hub/"}, |
| 12 | + "chrome:50.0.2661.86": { "image": "selenium/node-chrome:latest" }, |
| 13 | + "chrome:50.0": {"image": "selenium/node-chrome:latest" }, |
| 14 | + "chrome:50": { "image": "selenium/node-chrome:latest" }, |
| 15 | + "firefox": { "image": "selenium/node-firefox:latest" }, |
| 16 | + "firefox:45.0.2": { "image": "selenium/node-firefox:latest" }, |
| 17 | + "firefox:45": { "image": "selenium/node-firefox:latest" } |
| 18 | + }, |
| 19 | + "environment": [ |
| 20 | + "HUB_PORT_4444_TCP_ADDR=$hubHost", |
| 21 | + "HUB_PORT_4444_TCP_PORT=$hubPort", |
| 22 | + "REMOTE_HOST=$name", |
| 23 | + "SE_OPTS=-port $port -Djava.security.egd=file:/dev/random", |
| 24 | + "DISPLAY=:$port" |
| 25 | + ] |
| 26 | + } |
| 27 | + ``` |
| 28 | + In this file: |
| 29 | + * `images` section specifies the list of used Docker images (every image will be pulled from repo upon start). An optional ```path``` parameter allows you to specify base URL used to create Selenium sessions (e.g. ```/wd/hub/``` for standard Selenium server). |
| 30 | + * `environment` section represents the array of environment variables, that will be passed to the launching docker container. |
| 31 | + You can use the following variables here: `$hubHost`, `$hubPort`, `$name`, `$port`, that represent host of this service, |
| 32 | + port of this service, name of a launching container and port of a launching container. |
| 33 | + |
| 34 | +3. Create ```/etc/selenoud/log4j.properties``` file. This is the logging configuration: |
| 35 | + ``` |
| 36 | + # suppress inspection "UnusedProperty" for whole file |
| 37 | + log4j.rootLogger=INFO, logger, selenoud |
| 38 | + |
| 39 | + # Enable lines below for debug purposes |
| 40 | + #log4j.logger.ru.qatools.selenoud=TRACE |
| 41 | + #log4j.selenoud.ru.qatools.selenoud=TRACE |
| 42 | + |
| 43 | + # CONSOLE appender not used by default |
| 44 | + log4j.appender.logger=org.apache.log4j.ConsoleAppender |
| 45 | + log4j.appender.logger.layout=org.apache.log4j.PatternLayout |
| 46 | + log4j.appender.logger.layout.ConversionPattern=%d [%-10.10t] %-5p %c{1} - %m%n |
| 47 | + |
| 48 | + log4j.appender.selenoud=org.apache.log4j.DailyRollingFileAppender |
| 49 | + log4j.appender.selenoud.MaxFileSize=2GB |
| 50 | + log4j.appender.selenoud.File=/var/log/selenoud/selenoud.log |
| 51 | + log4j.appender.selenoud.bufferSize=5242880 |
| 52 | + log4j.appender.selenoud.MaxBackupIndex=7 |
| 53 | + log4j.appender.selenoud.layout=org.apache.log4j.PatternLayout |
| 54 | + log4j.appender.selenoud.layout.ConversionPattern=%d [%-30.30t] %-5p %-30.30c{1} - %m%n |
| 55 | + ``` |
| 56 | + |
| 57 | +4. Start Selenoud container: |
| 58 | + ``` |
| 59 | + $ docker run \ |
| 60 | + -v /etc/selenoud/:/etc/selenoud:ro \ |
| 61 | + -v /var/log/selenoud/:/var/log/selenoud \ |
| 62 | + -v /var/run/docker.sock:/var/run/docker.sock \ |
| 63 | + --name selenoud \ |
| 64 | + --privileged \ |
| 65 | + --restart=always \ |
| 66 | + --net host \ |
| 67 | + --log-opt max-size=1g \ |
| 68 | + --log-opt max-file=2 \ |
| 69 | + -e JAVA_OPTS="-Dlog4j.configuration=file:/etc/selenoud/log4j.properties |
| 70 | + -DimagesFile=/etc/selenoud/images.json |
| 71 | + -Dlogs.dir=/var/log/selenoud/logs" \ |
| 72 | + -d seleniumkit/selenoud:latest |
| 73 | + ``` |
| 74 | + |
| 75 | +5. Run your tests using the following Selenium URL: |
| 76 | + ``` |
| 77 | + http://localhost:4444/wd/hub |
| 78 | + ``` |
| 79 | +6. See log files for each session in ```/var/log/selenoud/logs```. |
| 80 | + |
| 81 | +## Configuration |
| 82 | + |
| 83 | +Selenoud supports the following System properties: |
| 84 | +```properties |
| 85 | +host=localhost # host to listen on (for node to connect to) |
| 86 | +port=4444 # port to listen on |
| 87 | +limit.threads=200 # how many threads will be used |
| 88 | +limit.bodyLength=10485760 # maximum request body size (bytes) |
| 89 | +limit.count=0 # max containers (0 - unlimited) |
| 90 | +limit.startupSec=60 # max node startup (sec) |
| 91 | +limit.inactivitySec=120 # max node inactivity (sec) |
| 92 | +limit.readTimeoutSec=60 # timeout to read from node (sec) |
| 93 | +limit.connectTimeoutSec=10 # timeout to connect to node (sec) |
| 94 | +limit.watcherIntervalMs=5000 # interval(ms) of freezed containers watcher |
| 95 | +cloud.host=172.17.0.1 # host to connect |
| 96 | +container.port=4455 # port to use inside container (when network is bridge) |
| 97 | +docker.network=bridge # docker network driver (default: bridge) |
| 98 | +docker.endpoint=unix:///var/run/docker.sock # default docker endpoint |
| 99 | +docker.pull.enabled=false # should we pull image per request? |
| 100 | +log4j.configuration=file:/etc/selenoud/log4j.properties # config for log4j |
| 101 | +imagesFile=/etc/selenoud/images.json # images config file |
| 102 | +logsCollector=ru.qatools.selenoud.docker.ToFileDockerLogCollector # containers logs collector |
| 103 | +logs.dir=/tmp/selenoud/logs # where to put all the containers logs |
| 104 | +``` |
| 105 | + |
| 106 | +## Development |
| 107 | +### Building code |
| 108 | + |
| 109 | +``` |
| 110 | +$ ./gradlew clean build |
| 111 | +``` |
| 112 | + |
| 113 | +Then you can find the distribution under `build/distributions` directory. |
| 114 | + |
| 115 | +### Running |
| 116 | +To start the basic app type: |
| 117 | +``` |
| 118 | +$ ./gradlew run |
| 119 | +``` |
| 120 | +To run Selenoud in production mode: |
| 121 | + |
| 122 | +```$ JAVA_OPTS="-Dport=4444 -Dthreads=1000" ./bin/selenoud``` |
| 123 | + |
| 124 | +### Building Docker image |
| 125 | + |
| 126 | +``` |
| 127 | +$ ./gradlew clean build docker |
| 128 | +``` |
0 commit comments