Selenoid can improve some automation aspects with custom capabilities. You can pass it in tests to enable/disable some features.
Selenoid supports showing browser screen during test execution. This works with containers having VNC server installed (VNC column of [Browser Image information]). To see browser screen:
enableVNC: true
Then launch Selenoid UI to see the screen.
This works by proxying VNC port from started container to http://localhost:4444/vnc/<session-id>; to WebSocket, where <session-id> is Selenium session ID.
Selenoid allows you to set custom screen resolution in containers being run:
screenResolution: "1280x1024x24"
|
Warning
|
|
|
Note
|
This feature requires some preparation. Please refer to [Video Recording] section for more details. |
To enable video recording for session, add:
enableVideo: true
-
By default saved video files are named
<session-id>.mp4where<session-id>is a unique identifier of Selenium session. To provide custom video name specify:Type: stringvideoName: "my-cool-video.mp4"
WarningIt is important to add mp4file extension. -
By default the entire screen picture is being recorded. Specifying
screenResolutioncapability changes recorded video size (width and height) accordingly. You can override video screen size by passing a capability. In case ofvideoScreenSizeresolution is less than actual, screen on video will be trimmed starting from top-left corner:Type: stringvideoScreenSize: "1024x768"
-
Default video frame rate is
12frames per second. SpecifyingvideoFrameRatecapability changes this value:Type: intvideoFrameRate: 24
-
By default Selenoid is using
libx264codec for video output. If this codec is consuming too much CPU, you can change it usingvideoCodeccapability:Type: stringvideoCodec: "mpeg4"
To obtain the full list of supported values:
$ docker run -it --rm --entrypoint /usr/bin/ffmpeg selenoid/video-recorder -codecs
|
Note
|
This feature requires some preparation. Please refer to [Saving Session Logs] section for more details. |
To enable saving logs for a session, add:
enableLog: true
If you wish to automatically save logs for all sessions, you can enable this behavior globally with Selenoid -save-all-logs flag.
By default saved log files are named <session-id>.log where <session-id> is a unique identifier of Selenium session.
To provide custom log file name specify:
logName: "my-cool-log.log"
|
Warning
|
It is important to add log file extension.
|
For debugging purposes it is often useful to give a distinct name to every test case. When working with Selenoid you can set test case name by passing the following capability:
name: "myCoolTestName"
The main application of this capability - is debugging tests in the UI which is showing specified name for every running session.
Sometimes you may want to change idle timeout for selected browser session. To achieve this - pass the following capability:
sessionTimeout: 30m
Timeout is specified Golang duration format e.g. 30m or 10s or 1h5m and can be no more than the value set by -max-timeout flag.
Some tests require particular time zone to be set in operating system. To achieve this with Selenoid use:
timeZone: "Europe/Moscow"
You can find most of available time zones here. Without this capability launched browser containers will have the same timezone as Selenoid one.
Sometimes you may want to set some environment variables for every test case (for example to test with different default locales). To achieve this pass one more capability:
env: ["LANG=ru_RU.UTF-8", "LANGUAGE=ru:en", "LC_ALL=ru_RU.UTF-8"]
Environment variables from this capability are appended to variables from configuration file.
Sometimes you may need to link browser container to application container running on the same host machine.
This allows you to use cool URLs like http://my-cool-app/ in tests.
To achieve this simply pass information about one or more desired links via capability:
applicationContainers: ["spring-application-main:my-cool-app", "spring-application-gateway"]
Although you can configure a separate list of /etc/hosts entries for every browser image in [Browsers Configuration File]
sometimes you may need to add more entries for particular test cases. This can be easily achieved with:
hostsEntries: ["example.com:192.168.0.1", "test.com:192.168.0.2"]
Entries will be inserted to /etc/hosts before entries from browsers configuration file.
Thus entries from capabilities override entries from configuration file if some hosts are equal.
By default Selenoid browser containers are using global DNS settings of Docker daemon. Sometimes you may need to override used DNS servers list for particular test cases. This can be easily achieved with:
dnsServers: ["192.168.0.1", "192.168.0.2"]
By default Selenoid browser containers are started in Docker network specified by -container-network flag. If you tested application is running in another network you may need to connect browser container to this network:
additionalNetworks: ["my-custom-net-1", "my-custom-net-2"]
In big clusters you may want to pass additional metadata to every browser session: environment, VCS revision, build number and so on. These labels can be then used to enrich session logs and send them to a centralized log storage. Later this metadata can be used for more efficient search through logs.
labels: {"environment": "testing", "build-number": "14353"}
Labels from this capability override labels from browsers configuration file. When name capability is specified - it is automatically added as a label to container.
For [Android] containers you can select emulator skin with capabilities. List of available skins:
| Skin | Screen Resolution | DPI |
|---|---|---|
QVGA |
240x320 |
120 |
WQVGA400 |
240x400 |
120 |
WQVGA432 |
240x432 |
120 |
HVGA |
320x480 |
160 |
WVGA800 |
480x800 |
240 |
WVGA854 |
480x854 |
240 |
WSVGA |
1024x600 |
160 |
WXGA720 |
720x1280 |
320 |
WXGA800 |
1280x800 |
160 |
WXGA800-7in |
800x1280 |
213 |
To select a skin - set skin capability:
skin: "WXGA720"
You can also pass desired screen resolution as follows:
skin: "720x1280"
This capability allows to override S3 key pattern (specified by -s3-key-pattern flag) used when uploading files to S3.
s3KeyPattern: "$quota/$fileType$fileExtension"
The same key placeholders are supported. Please refer to [Uploading Files To S3] section for more details.
Some Selenium clients allow passing only a limited number of capabilities specified in WebDriver specification. For such cases Selenoid supports reading capabilities using WebDriver protocol extensions feature. The following two examples deliver the same result. Usually capabilities are passed like this:
{"browserName": "firefox", "version": "57.0", "screenResolution": "1280x1024x24"}
Selenoid is using selenoid:options key to read protocol extension capabilities:
{"browserName": "firefox", "version": "57.0", "selenoid:options": {"screenResolution": "1280x1024x24"}}