Docker Service
wdio-docker-service is a 3rd party package, for more information please see GitHub | npm
This service is intended for use with WebdriverIO and it helps run functional/integration tests against/using containerized applications. It uses popular Docker service (installed separately) to run containers.
#
Why use it?Ideally your tests would run in some variety of CI/CD pipeline where often there are no "real" browsers and other resources your application depends on. With advent of Docker practically all necessary application dependencies can be containerized. With this service you may run your application container or a docker-selenium in your CI and in complete isolation (assuming CI can have Docker installed as a dependency). Same may apply to local development if your application needs to have a level of isolation from your main OS.
#
How it worksService will run an existing docker image and once its ready, will initiate WebdriverIO tests that should run against your containerized application.
#
InstallationRun:
Instructions on how to install WebdriverIO can be found here.
#
ConfigurationBy default, Google Chrome, Firefox and PhantomJS are available when installed on the host system.
In order to use the service you need to add docker
to your service array:
#
Options#
dockerOptionsVarious options required to run docker container
Type: Object
Default: {
options: {
rm: true
}
}
Example:
#
dockerOptions.imageDocker container name tag. Could be local or from Docker HUB.
Type: String
Required: true
#
dockerOptions.healthCheckConfiguration which checks your containers' readiness before initiating tests. Normally this would be a localhost url. If healthCheck is not configured, Webdriver will start running tests immediately after Docker container starts, which maybe too early considering that it takes time for web service to start inside a Docker container.
Type: String|Object
Options for Object use:
- url - url to an app running inside your container
- maxRetries - number of retries until healthcheck fails. Default: 10
- inspectInterval - interval between each retry in ms. Default: 500
- startDelay - initial delay to begin healthcheck in ms. Default: 0
Example 1 (String): healthCheck: 'http://localhost:4444'
Example 2 (Object):
#
dockerOptions.optionsMap of options used by docker run
command. For more details on run
command click here.
Any single-letter option will be converted to -[option]
(i.e. d: true
-> -d
).
Any option of two-character or more will
be converted to --[option]
(i.e. rm: true
-> --rm
).
For options that may be used more than once
(i.e. -e
,-add-host
, --expose
, etc.), please use array notation (i.e. e: ["NODE_ENV=development", "FOO=bar"]
).
Type: Object
Example:
#
dockerOptions.argsAny arguments you may want to pass into container. Corresponds to [ARG...]
in Docker run CLI.
Type: String
#
dockerOptions.commandAny command you may want to pass into container. Corresponds to [COMMAND]
in Docker run CLI.
Type: String
#
onDockerReadyA callback method which is called when Docker application is ready. Readiness is determined by ability to ping healthCheck
url.
Type: Function
#
dockerLogsPath to where logs from docker container should be stored
Type: String
#
Testing Use Cases / RecipesPlease visit our Wiki for more details.