Skip to content
This repository was archived by the owner on Dec 17, 2024. It is now read-only.

Files

Latest commit

f273640 · Jan 5, 2019

History

History
273 lines (196 loc) · 9.25 KB

special-capabilities.adoc

File metadata and controls

273 lines (196 loc) · 9.25 KB

Special Capabilities

Selenoid can improve some automation aspects with custom capabilities. You can pass it in tests to enable/disable some features.

Live Browser Screen: enableVNC

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:

Type: boolean
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.

Custom Screen Resolution: screenResolution

Selenoid allows you to set custom screen resolution in containers being run:

Type: string, format: <width>x<height>x<colors-depth>
screenResolution: "1280x1024x24"
Warning
  • This capability sets only screen resolution - not browser window size. Most of browsers have some default window size value this is why your screenshot size can be smaller than screen resolution specified in capability. You should manually resize window to desired width and height.

  • So far as our containers run headless browsers in Xvfb without installed window manager maximize operation does not work. You need to use setSize method instead.

Video Recording: enableVideo, videoName, videoScreenSize, videoFrameRate, videoCodec

Note
This feature requires some preparation. Please refer to [Video Recording] section for more details.

To enable video recording for session, add:

Type: boolean
enableVideo: true
  • By default saved video files are named <session-id>.mp4 where <session-id> is a unique identifier of Selenium session. To provide custom video name specify:

    Type: string
    videoName: "my-cool-video.mp4"
    Warning
    It is important to add mp4 file extension.
  • By default the entire screen picture is being recorded. Specifying screenResolution capability changes recorded video size (width and height) accordingly. You can override video screen size by passing a capability. In case of videoScreenSize resolution is less than actual, screen on video will be trimmed starting from top-left corner:

    Type: string
    videoScreenSize: "1024x768"
  • Default video frame rate is 12 frames per second. Specifying videoFrameRate capability changes this value:

    Type: int
    videoFrameRate: 24
  • By default Selenoid is using libx264 codec for video output. If this codec is consuming too much CPU, you can change it using videoCodec capability:

    Type: string
    videoCodec: "mpeg4"

    To obtain the full list of supported values:

    $ docker run -it --rm --entrypoint /usr/bin/ffmpeg selenoid/video-recorder -codecs

Saving Session Logs: enableLog, logName

Note
This feature requires some preparation. Please refer to [Saving Session Logs] section for more details.

To enable saving logs for a session, add:

Type: boolean
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:

Type: string
logName: "my-cool-log.log"
Warning
It is important to add log file extension.

Custom Test Name: name

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:

Type: string
name: "myCoolTestName"

The main application of this capability - is debugging tests in the UI which is showing specified name for every running session.

Custom Session Timeout: sessionTimeout

Sometimes you may want to change idle timeout for selected browser session. To achieve this - pass the following capability:

Type: string
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.

Per-session Time Zone: timeZone

Some tests require particular time zone to be set in operating system. To achieve this with Selenoid use:

Type: string
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.

Per-session Environment Variables: env

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:

Type: array, format: <key>=<value>
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:

Type: array, format: <container-name>[:alias]
applicationContainers: ["spring-application-main:my-cool-app", "spring-application-gateway"]

Hosts Entries: hostsEntries

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:

Type: array, format: <hostname>:<ip-address>
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.

Custom DNS Servers: dnsServers

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:

Type: array, format: <dns-ip-address>
dnsServers: ["192.168.0.1", "192.168.0.2"]

More Docker Networks: additionalNetworks

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:

Type: array, format: <network-name>
additionalNetworks: ["my-custom-net-1", "my-custom-net-2"]

Container Labels: labels

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.

Type: map, format: "<key>": "<value>"
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.

Android Skin: skin

For [Android] containers you can select emulator skin with capabilities. List of available skins:

Table 1. Available Android 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:

Type: string, format: <desired-skin>
skin: "WXGA720"

You can also pass desired screen resolution as follows:

Type: string, format: <desired-screen-resolution>
skin: "720x1280"

S3 Key Pattern: s3KeyPattern

This capability allows to override S3 key pattern (specified by -s3-key-pattern flag) used when uploading files to S3.

Type: string
s3KeyPattern: "$quota/$fileType$fileExtension"

The same key placeholders are supported. Please refer to [Uploading Files To S3] section for more details.

Specifying Capabilities via Protocol Extensions

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:

Passing Capabilities as Usually
{"browserName": "firefox", "version": "57.0", "screenResolution": "1280x1024x24"}

Selenoid is using selenoid:options key to read protocol extension capabilities:

Passing Capabilities using Protocol Extensions
{"browserName": "firefox", "version": "57.0", "selenoid:options": {"screenResolution": "1280x1024x24"}}