Enhanced Selenium/Appium Grid for automating Android and iOS devices including TVs (Android, Tizen, Apple) and emulators/simulators. It is a Selenium 3 hub with a mobile proxy (MobileRemoteProxy) and capability matcher (MobileCapabilityMatcher): one Appium node is one device, devices are reserved in STF for the time of a session.
Feel free to support the development with a donation for the next improvements.
Follow the installation and configuration guide in MCloud to reuse this image effectively.
make build VERSION=3.1 # public.ecr.aws/zebrunner/mcloud-grid:3.1 in the local docker make push VERSION=3.1 # built by docker buildx and pushed: docker login public.ecr.aws first
make build builds the image for the platform of this machine, make push builds linux/amd64 and linux/arm64 (PLATFORMS) with docker buildx and pushes them as one multi-platform image. IMAGE_REPO sets another repository (e.g. IMAGE_REPO=registry.example.com/mcloud-grid), VERSION is the tag and the
org.opencontainers.image.version label (dev by default, required by push). make push uses the buildx builder
mcloud (docker-container driver), which it creates once; another platform than the one of the machine needs QEMU
(docker run --privileged --rm tonistiigi/binfmt --install all).
The image build compiles and packages the hub; tests and linters run separately (see Development).
The file VERSION is the release in work (bumped by hand after a release, CONVENTIONS.md#versions), and the version of pom.xml with it (PomVersionTest checks it). The publish job of CI pushes the image of every merge into develop after all the checks passed: public.ecr.aws/zebrunner/mcloud-grid:<VERSION>-develop-<sha> (7 characters of the commit) and <VERSION>-develop-latest, the newest commit of develop. Each platform is built on a runner of its own (arm64 on an arm64 runner) and pushed by digest, with the cache of GitHub Actions (PUSH_OUTPUT and PUSH_CACHE of make push), then the job merges them into the image.
docker run -d -p 4444:4444 -e GRID_NEW_SESSION_WAIT_TIMEOUT=240000 \ -e GRID_TIMEOUT=60 -e GRID_BROWSER_TIMEOUT=60 \ -e STF_URL=http://stf.example.com -e STF_TOKEN=<token> \ --name mcloud-grid public.ecr.aws/zebrunner/mcloud-grid:<tag>
<tag> is a release (e.g. 2.6) or a build of develop (<VERSION>-develop-latest, e.g. 3.1-develop-latest, or <VERSION>-develop-<sha>), see Build; the image has no latest tag.
The hub runs as an unprivileged user and stops gracefully on docker stop. STF_URL and STF_TOKEN (the access token of an STF admin) are required: the nodes register with their node tokens, which the hub verifies with STF (see Node registration); without them the hub starts, logs STF_URL and STF_TOKEN are not set (SEVERE) and refuses every node, as on the first start of MCloud before an admin of STF has an access token. The first log line is the banner of the image with its version (IMAGE_VERSION, the VERSION of the build).
| Variable | Default | Description |
|---|---|---|
GRID_NEW_SESSION_WAIT_TIMEOUT |
600000 |
How long a new session request waits in the queue, ms |
GRID_TIMEOUT |
150 |
Client inactivity timeout of a session, s; it replaces the one of the nodes (0 keeps the one of the nodes) |
GRID_BROWSER_TIMEOUT |
900 |
Timeout of a command on the node, s (0 = none); it replaces the one of the nodes (zebrunner/appium sends 0): a hung command fails after it and the device is released, instead of staying busy until the restart of the hub |
GRID_CLEAN_UP_CYCLE |
5000 |
How often the hub checks timed out sessions, ms; it replaces the one of the nodes (zebrunner/appium sends 5000) |
GRID_THROW_ON_CAPABILITY_NOT_PRESENT |
true |
Reject requests no registered device can serve; see Queueing |
GRID_JETTY_MAX_THREADS |
-1 |
Jetty threads of the hub (-1 = default) |
GRID_DEBUG |
false |
Debug logging of the hub |
GRID_CAPABILITY_MATCHER |
com.zebrunner.mcloud.grid.MobileCapabilityMatcher |
Class of the capability matcher; the class of the proxy is named by every node itself, the hub registers only MobileRemoteProxy (and its subclasses), see Node registration; GRID_PROXY of the older images is ignored |
JAVA_HEAP_OPTS |
-Xms1G -Xmx4G |
JVM heap of the hub |
JAVA_OPTS |
Other JVM options | |
JAVA_HOME, PATH, LANG |
/opt/java/openjdk, its bin first, C.UTF-8 |
The Java runtime of the image (Temurin 11, the modules of the hub only) and the UTF-8 locale |
SE_OPTS |
Extra hub options, e.g. -debug; -servlets replaces the servlets of the hub config |
|
CHECK_NODE_REACHABILITY |
true |
Reject the registration of a node the hub cannot connect to |
NODE_REACHABILITY_TIMEOUT |
2 |
Connection timeout of that check, s |
NODE_ALLOWED_NETWORKS |
Comma separated CIDR ranges or IPs nodes may register from, e.g. 10.0.0.0/8, 192.168.1.15; the address a node registers with is checked; not set = any node (an invalid value rejects every node) |
|
MAX_NEW_COMMAND_TIMEOUT |
Upper limit of appium:newCommandTimeout, s; bigger and disabled (0) values are limited (no limit when not set or 0) |
|
PLAYWRIGHT_ENABLED |
false |
Run the Playwright sessions: the option of the farm, see Playwright |
PLAYWRIGHT_IDLE_TIMEOUT |
120 |
A side of a Playwright WebSocket that answers no ping for it is closed with the other side, s; see Playwright |
MCLOUD_LOG_LEVEL |
INFO |
Log level of the grid code, FINE for details; Selenium logs stay as they are. It is set when the hub starts, with the [CONFIGURATION] log of the settings, before the first node registers |
The variables of the hub config (GRID_*) are validated before the hub starts, see Exit codes and health: the numbers are whole numbers (GRID_NEW_SESSION_WAIT_TIMEOUT and GRID_JETTY_MAX_THREADS at least -1, GRID_TIMEOUT and GRID_BROWSER_TIMEOUT at least 0, GRID_CLEAN_UP_CYCLE at least 1), the booleans true or false.
STF_URL and STF_TOKEN are required for the nodes: without them the hub starts but refuses every node.
| Variable | Default | Description |
|---|---|---|
STF_URL |
Required: STF address | |
STF_TOKEN |
Required: access token of the STF admin that reserves devices for automation and verifies the node tokens of the nodes with the node registry of STF; a device that does not answer the reservation (STF answers 504 after 5 s, the hub waits 10 s for the reservation, the return and remoteConnect, 3 s for the other requests) is also marked unhealthy in STF and returned in case its reservation completes later |
|
STF_TIMEOUT |
3600 |
Reservation timeout of a device in STF, s: STF ends a reservation after this time without a message for the device; the hub keeps the reservation of a running session (below), so the timeout ends the reservations of the sessions the hub lost (e.g. a hub that stopped) |
GRID_AUTH_SECRET |
The secret of stf-proxy of MCloud, at least 32 characters without whitespace: turns on the authentication of the users, the hub then takes the requests of the users of stf-proxy only; not set = anyone who reaches the hub uses it (logged as a warning) | |
CHECK_APPIUM_STATUS |
false |
Check /status-adb (Android) or /status-wda (iOS) of the node before a session |
APPIUM_STATUS_TIMEOUT |
10 |
How long the hub waits for the Appium status check, s; zebrunner/appium gives WebDriverAgent 3 s and a second attempt, adb 5 s |
UNHEALTHY_MOBILE_TIMEOUT |
60 |
A device failing the Appium status check is skipped for, s |
INACTIVITY_RELEASE_TIMEOUT |
60 |
A device whose session timed out before it started is skipped for, s |
STF_DEVICE_INVALID_RESPONSE_IGNORE_TIMEOUT |
600 |
A device with an invalid STF status or failed reservation is skipped for, s |
STF_DEVICE_UNAUTHORIZED_IGNORE_TIMEOUT |
600 |
A device unauthorized in STF is skipped for, s |
STF_DEVICE_UNHEALTHY_IGNORE_TIMEOUT |
60 |
An unhealthy or not ready device is skipped for, s |
STF_DEVICE_MANUALLY_RESERVED_TIMEOUT |
180 |
A device reserved in STF by another user is skipped for, s |
STF_DEVICE_LOW_BATTERY_THRESHOLD |
15 |
A present and ready device charged below this level (%) in STF (Android and iOS) is skipped by automation; 0 disables the check |
STF_DEVICE_LOW_BATTERY_IGNORE_TIMEOUT |
3600 |
A device with a low battery is skipped for, s; it is checked again by the next request after that |
The _TIMEOUT variables in seconds of this table (but STF_TIMEOUT, a positive number) and NODE_REACHABILITY_TIMEOUT, MAX_NEW_COMMAND_TIMEOUT, PLAYWRIGHT_IDLE_TIMEOUT are whole numbers, 0 or more: an invalid or negative value is logged (WARNING) and the default is used.
A session sends no message for its device to STF, which ends a reservation after its timeout (STF_TIMEOUT, zebrunner:STF_TIMEOUT) without one: the hub keeps the reservation of every running session (POST /api/v1/user/devices/<udid>/keepalive of STF, with the token the device is reserved with) every third of its timeout, from 30 s to 5 minutes. When STF answers that the device is not reserved by that user any more (403: released in STF, or reserved by another user after the reservation ended) the session ends at once (The device is not reserved in STF by the user of the session ... any more), its device is not returned; another answer is logged and tried again, an STF without the route (404) is skipped.
A request that leaves the queue without a device (newSessionWaitTimeout or a gone client) is logged as a warning with the
matching devices: busy, down and ignored ones with the reason (e.g. low battery: 12% (discharging), below 15%).
| Capability | Meaning |
|---|---|
platformName |
Android, iOS, ... |
appium:platformVersion |
Exact (13), range (11-13), minimum (12+) or list (12,14); 7 matches 7.0 |
appium:deviceName, appium:udid |
One value or a comma separated list (the spaces around the values are ignored) |
zebrunner:deviceType |
phone, tablet, tv, tvOS, ...; tvOS devices get platformName=tvOS |
zebrunner:STF_TOKEN |
Personal STF token: the device is reserved as that user and is not returned after the session; the hub does not pass it to Appium. With the authentication of the users the token of the URL of the hub is used, the capability is refused when it is another token |
zebrunner:STF_TIMEOUT |
Reservation timeout in STF for this session, s |
zebrunner:enableAdb |
Android: wait for the remote ADB connection of STF before the session; the hub starts the remote ADB (remoteURL of zebrunner:slotCapabilities) of every Android device, by the platform of its node, also for a request without platformName (e.g. by appium:udid only) |
The node capabilities of the reserved device are passed to the session as zebrunner:slotCapabilities.
A node registers with the hub through /grid/register, which answers anyone who reaches the hub, and gets the sessions of its device with their commands and capabilities. So the hub registers a node only when:
- its proxy is
MobileRemoteProxy(the registry of the hub config,MobileGridRegistry, rejects the others): a node with another class would skip the checks below; - it sends its node token in
customof its configuration ("custom": {"registrationToken": "<node token>"}), which zebrunner/appium does with itsNODE_REGISTRATION_TOKEN(MCLOUD_NODE_TOKENof mcloud-agent), and STF verifies the token for the address of the node; the hub takes the token out of the configuration it keeps, so the console and the logs do not show it; - its address is in
NODE_ALLOWED_NETWORKS(checked before the request to STF) and reachable (CHECK_NODE_REACHABILITY), and STF has its device bound to the node of the token (nodeof the device in STF: STF binds a device to the enrolled node whose device container proved its registration with the node token), so a node cannot register the device of another node to get its sessions and its remote ADB address.
A node gets its node token mcn1.<label>.<secret> when it joins the farm with an invite of the admin (./zebrunner.sh node-invite <label> <address> of mcloud on the server, ./zebrunner.sh join of mcloud-agent on the node): STF keeps the node (its label and the address of the invite) in its node registry, and only the SHA-256 of the token. The hub accepts a node token only when STF verifies it for the host of the node URL: POST /api/v1/nodes/verify with the token and the host, authorized by STF_TOKEN, answers 200 only for an active node whose registered address is that host. The answers of STF (200 and 403) are cached for 30 s by the SHA-256 of the token and the host, so the retries of a rejected node do not load STF. The nodes of a host share its node token: the verifications of the same token and host at the same time make one request to STF. While STF does not answer (or answers something else than 200 and 403, e.g. while it starts with the hub) the hub does not ask it again for 5 s: the nodes are rejected at once and register again later. The tokens STF did not answer about recently are verified within a limit: 10 node tokens of a host (of the node URL; its nodes share one) and 1000 of all the hosts in 30 s. Beyond it a node is rejected before the check of NODE_ALLOWED_NETWORKS and the request to STF and registers again later, so requests with ever new tokens do not make the hub resolve their host and ask STF every time.
- The hub sends the node token of a node only to that node, in the header
X-MCloud-Node-Tokenof its requests (the commands of the sessions, the status polling, the Appium status checks); zebrunner/appium answers only such requests and the ones of its own container. So the Appium of a device is used through the hub only, which reserves the device in STF. - STF verifies the node token of every registered node again every 60 s, without the cache: a node whose token it rejects (
403: the node is revoked, joined again with a new token, or its address is another one) is unregistered at once, its sessions end and their devices are returned in STF. While STF does not answer, the node is kept for up to 10 minutes since its last verification, then it is unregistered too. The logs name the node by its label, never by its token. - A rejected node gets the reason in the answer of
/grid/register(zebrunner/appium logs it), and the hub logs it once in 10 minutes; see Troubleshooting. The messages never contain a token. - The hub checks a node (the requests to STF and to the node above) in one of 8 threads of the registrations, not in the thread of the request, and answers the node within 25 s (below the 60 s of stf-proxy): a registration that is not done by then is answered
503(Retry-After: 5) and goes on, the node is added when it is done. A node whose registration still runs, and every node while the 8 threads are busy and 32 registrations wait, is answered503at once. So a registration that hangs (e.g. a request without an answer) holds one thread of the registrations, never the threads of the hub: the hub keeps answering the users, the status and the healthcheck. A registration that runs longer than 25 s is logged with the stack of its thread ([NODE REGISTRATION] A registration of a node has been running for ...), one that runs longer than 3 minutes makes the hub unhealthy, see Exit codes and health.com.zebrunner.mcloud.grid.servlets.NodeRegistrationanswers/grid/registerin place ofRegistrationServletof Selenium (the same registration, the request is limited to 1 MiB). - A registered node asks
GET /grid/api/proxy?id=<node id>every few seconds whether it is still registered and registers again when it is not. The hub answers about that id only (an exact match of the id of a registered node, zebrunner/appium uses its URL) withsuccess,msgandid, never with the configuration or the capabilities of a node; without an id or for an unknown onesuccessisfalse.com.zebrunner.mcloud.grid.servlets.ProxyInfoanswers it in place of the node API of Selenium (ProxyStatusServlet), which answered with the registration request of the node (its URL and its devices); onlyGETis answered. - The error pages of the hub (e.g. the
500of a rejected registration) have the status and the message only: no stack trace, exception class or servlet, and no version of Jetty (also not in theServerheader). The hub logs the errors.
A node that registers again at the same address (e.g. after the hub restarted) is checked for its token only. The registry replaces a registered node with the same id and ends its sessions, so a node may take the id of a registered node only at the same host (checked as a new node); a node of another host with that id is rejected (registers with the id '...' of the node ... at another host): zebrunner/appium uses the URL of the node as its id.
The hub does not pass zebrunner:STF_TOKEN of a session to the node, so it is in no log of Appium; the hub masks it, the registration token and any node token (mcn1.<label>.*****) in its own logs, e.g. the session requests and the registration requests Selenium logs with -debug.
/lifecycle-manager of Selenium, which shuts the hub down for anyone, is turned off in the hub config (withoutServlets).
With GRID_AUTH_SECRET the hub takes the requests of the users of MCloud only: stf-proxy asks STF about every request of the grid (GET /api/v1/zebrunner/hub-auth, see ZEBRUNNER.md of STF) and passes the user STF answered on in X-MCloud-User (the email), X-MCloud-Admin and X-MCloud-Token (the STF access token of the request), with the secret in X-MCloud-Auth. The hub trusts these headers with the secret only (compared in constant time). A test gives its STF access token in the URL of the hub: https://<user>:<token>@<host>/mcloud/wd/hub, <user> is any name without @ (the clients of Selenium, Appium and WebdriverIO send it as Authorization: Basic).
| Routes | Who |
|---|---|
/wd/hub/status, /status, /grid/register, /grid/api/proxy, /grid/api/health (the nodes, which have their node tokens, and the healthcheck) |
anyone |
/wd/hub/*, /grid/console, /grid/resources, /grid/admin/DevicesServlet, /grid/admin/AllSessionsServlet, /grid/admin/TerminateSessionServlet, /grid/admin/PlaywrightServlet |
a user |
the others: /grid/admin/MetricsServlet, /grid/api/hub, /grid/api/sessions, ... |
an admin of STF |
- A request without the user of stf-proxy is answered
401, a user on an admin route403, both with a WebDriver error the clients show. - A session belongs to the user of its request: a command or the Playwright WebSocket of the session of another user is answered
404(invalid session id), as an unknown session; an admin uses any session. The devices (DevicesServlet, the console) show the email of the user of a session to everyone, its id, its last command and its capabilities (AllSessionsServlet) to its user and the admins only. - The device of a session is reserved in STF with the token of its user, so the groups and the permissions of STF apply to the user; the hub needs the token for a session (
A session needs the STF access token of its user). A device the user had reserved in STF before the session (in the UI) stays reserved after it; a reservation through the API (usage: automation, e.g. one of a hub that stopped) is returned after the session. The hub returns the reservations of the grid user only when it starts: the ones of the users of a hub that stopped are not told from the ones of other clients of STF, they expire in STF (STF_TIMEOUT) as nobody keeps them any more. TerminateSessionServletreleases the device with the token of the request: a user terminates the own sessions, an admin any.- The nodes never get
Authorization,Cookieor theX-MCloud-*headers of a request: the hub copies the headers of a command to the node of its session. - The hub of Selenium 3 has no setting for a filter: the main class of the image,
com.zebrunner.mcloud.grid.HubLauncher, addsHubAuthFilterto the Jetty context of the hub once it is started (afterProxyInfoand the error pages, see Node registration), and stops the hub when it cannot. Until then the registry refuses the new sessions without a user.
The hub matches the queued requests to the devices in the order of the queue: it claims a free matching device for a request, then prepares it (the Appium status check of CHECK_APPIUM_STATUS, the reservation in STF) without the lock of the registry, the devices of several requests in parallel. A slow STF or node delays only its request, not the queueing, the end of the sessions and the registration of the nodes. A device that fails a request (not ready, not reserved in STF) is skipped by this request for 10 s, the request gets the next device at once. A device prepared for a request that is gone meanwhile (timed out) or on a node lost meanwhile is returned in STF. A device is not claimed while it is being returned in STF (its session ended, was abandoned, or its node was lost or registered again): the grid user reuses its own reservation of a device, so the late return would end the reservation of the next session.
The hub asks every node for its status (/wd/hub/status of the node) every nodePolling of the node: it waits 2 s for the connection and nodeStatusCheckTimeout of the node for the answer (in whole seconds, at least 1 s; Selenium 3 took the milliseconds of it as seconds). A node that fails downPollingLimit times in a row is down (it gets no new session) and is lost when it is still down after unregisterIfStillDownAfter: with the node config of zebrunner/appium (nodePolling 5000, nodeStatusCheckTimeout 5000, downPollingLimit 3, unregisterIfStillDownAfter 3000 ms) a node that is gone is lost in about 30 s, a node that does not answer (frozen) in about 40 s. The console asks every node the same way; /wd/hub/status asks no node, it answers with the state of this polling.
When the hub loses a node (it is down for unregisterIfStillDownAfter of the node, or registers again) its sessions end and their devices are returned in STF. An invalid zebrunner:STF_TIMEOUT (not a whole number of seconds) is logged and the default timeout is used.
With GRID_THROW_ON_CAPABILITY_NOT_PRESENT=true a request for a device that is not registered fails at once (cannot find : Capabilities {...}, or Empty pool of VM for setup when no device is registered at all). With false it waits in the queue for up to GRID_NEW_SESSION_WAIT_TIMEOUT and gets a device that registers meanwhile (a restarted device, a new emulator), otherwise it fails with Request timed out waiting for a node to become available.
A Playwright session is an Appium session of the Playwright automation of zebrunner/appium (appium:automationName: Playwright): the hub queues it, reserves the device in STF and releases it as any other session. The driver serves the Playwright server of the device on the WebSocket /mcloud/playwright/<session id> of the node, PlaywrightServlet passes the WebSocket of the client on to it: ws://hub:4444/grid/admin/PlaywrightServlet/<Appium session id> (/mcloud/playwright/<session id> of MCloud).
- The Playwright sessions are an option of the farm, off by default:
PLAYWRIGHT_ENABLED=trueturns them on. Without it the hub refuses a new session of thePlaywrightautomation before the queue (Playwright sessions are not enabled on this grid, as a device it does not have: no device is reserved) and the WebSocket with501; the other sessions are not affected. - The hub connects to the node first, with the node token of the node and the headers Playwright checks (
User-Agent, its version) or uses (x-playwright-*), never the other headers of the client: an unknown session is404, a session the node does not serve (another automation) is502. - The frames are passed on in parts as they come, a message of any size (screenshots, traces).
- While a WebSocket of the session is open the session does not time out: the client sends no WebDriver commands then. Playwright sends no pings, the hub pings both sides every 30 s; a side that answers nothing for
PLAYWRIGHT_IDLE_TIMEOUT(a client that is gone without a close) is closed with the other one. - When the last WebSocket of a session is closed the inactivity of the session counts from then: a session the client did not delete (
DELETE /wd/hub/session/<id>) is released afterGRID_TIMEOUTas any session without commands.
| Endpoint | Content |
|---|---|
/grid/console |
Selenium grid console, with the UDID of every device; the values of the nodes and of the queued requests are escaped, the secrets of the queued requests are masked |
/grid/admin/DevicesServlet |
Devices as JSON: platform, type, node, status free/busy/ignored/down, why and until when a device is ignored, its session (Appium session id, start, inactivity, last command) |
/grid/admin/AllSessionsServlet |
Active sessions as JSON with the requested capabilities and the device; secrets are masked as *****: zebrunner:STF_TOKEN, remoteURL of zebrunner:slotCapabilities (the remote ADB address), capabilities named like a token, password, secret, key or credential, and the user info and such query parameters of URLs (e.g. appium:app) |
/grid/admin/PlaywrightServlet/<session id> |
The WebSocket of a Playwright session, see Playwright |
/grid/admin/MetricsServlet |
Prometheus metrics: mcloud_grid_devices{platform,status}, mcloud_grid_sessions, mcloud_grid_new_session_requests (the queue) |
POST /grid/admin/TerminateSessionServlet?udid=<udid> or ?sessionId=<id> |
Terminates the session of a device and releases it in STF, see below |
/wd/hub/status, /status |
Hub status: ready while a node that is not down (the status polling of the hub, see Matching) has a free device; it asks no node |
/grid/api/health |
The health of the hub, the healthcheck of the image: 200 {"healthy": true}, or 503 with the reason, see Exit codes and health |
curl -X POST -H "Authorization: Bearer <STF access token>" "http://grid:4444/grid/admin/TerminateSessionServlet?udid=emulator-5554"
The hub releases the device in STF with the given key first and terminates the session only when STF allows it. STF releases a device for the user it is reserved by or for an STF admin. Devices are reserved by the grid user (STF_TOKEN), so the key of a regular STF user may not work (403, the session keeps running) unless the session was started with that user's zebrunner:STF_TOKEN; an STF admin key works. With the authentication of the users the key is the token of the request (/mcloud/grid/admin/TerminateSessionServlet of MCloud with Authorization: Bearer <token>), and the devices are reserved by the users of the sessions: a user terminates the own sessions. A session that ends meanwhile is not released again (404): its device may be reserved by the next session already.
The servlets are registered in the hub config by generate_config. com.zebrunner.mcloud.grid.servlets.ProxyInfo is the node API /grid/api/proxy and NodeRegistration the registration /grid/register (see Node registration), HubStatus the status /wd/hub/status and /status (in place of HubW3CStatusServlet of Selenium, which asked every node in the request) and HubHealth the health /grid/api/health: HubLauncher maps them.
docker logs mcloud-grid outputs JSON Lines: one JSON object per event, including Selenium, grid and startup/shutdown logs. Common fields are timestamp (UTC), level, logger, component, category and message. Device events also have udid and sessionId (the hub's internal session ID):
{"timestamp":"2026-10-09T12:00:00Z","level":"INFO","logger":"com.zebrunner.mcloud.grid.MobileRemoteProxy","component":"mcloud-grid","category":"device","udid":"emulator-5554","sessionId":"0f85...","message":"Device 'Pixel 7' (ANDROID 14) is selected for the session, starting the Appium session."}Use docker logs mcloud-grid 2>&1 | jq -c 'select(.udid == "emulator-5554")' to see one device, select(.category == "grid") for hub-wide events or select(.component == "selenium") for Selenium itself. Selenium's own records have no device ID unless Selenium supplies it. Exceptions are escaped into one JSON field. MCLOUD_LOG_LEVEL=FINE adds grid details (skipped devices, STF device data, remoteConnect steps); SE_OPTS=-debug turns on Selenium's debug logs without changing the grid log level; the registration requests of the nodes it logs have the node token masked. The generated config remains available at /opt/selenium/config.json, but is not dumped to logs.
For interactive viewing of history and live logs with lnav:
docker logs --follow --timestamps mcloud-grid 2>&1 | lnav
The node gets the reason in the answer of /grid/register (the log of the appium container of the node), the hub logs it with [NODE REGISTRATION]: docker logs mcloud-grid 2>&1 | grep 'NODE REGISTRATION'. The node registers again every few seconds, so it is registered as soon as the cause is fixed.
| Message | Cause and fix |
|---|---|
has no node token |
The node is not joined: NODE_REGISTRATION_TOKEN of its appium container is empty. Create an invite on the server (./zebrunner.sh node-invite <label> <address>) and join the node with it (./zebrunner.sh join), which sets its node token. |
has a token that is not a node token or has a malformed node token |
The node sends something else than mcn1.<label>.<secret> (e.g. a truncated or edited value). Join the node again. |
has an unknown or revoked node token |
STF answered 403: the node is revoked or deleted, joined again elsewhere (a new join replaces the token at once), or the host of the node URL (printed in the message) is not the address of the invite. The host is the address the node registers with (STF_PROVIDER_HOST of mcloud-agent) and must be the address of the invite exactly (an IP and a hostname are different addresses). Check the node in STF (./zebrunner.sh nodes check <label> of mcloud on the server, ./zebrunner.sh doctor of mcloud-agent on the node), then join the node again with an invite for the right address. |
has a node token, but STF could not verify it (STF did not answer) |
The hub does not reach STF_URL: check the address, the STF containers and the network between them. A registered node is kept for 10 minutes without the answers of STF. |
has a node token, but STF could not verify it (HTTP 401) or (HTTP 404) |
STF_TOKEN of the hub is not the token of an STF admin (401), or STF has no node registry (404): update STF and set the admin token. The hub logs these once in 10 minutes. |
is not in NODE_ALLOWED_NETWORKS, is not reachable from the hub |
The address of the node is outside NODE_ALLOWED_NETWORKS, or the hub cannot connect to it. |
Could not find device with udid '...' in STF or is not bound to a node in STF yet |
The device of the node is not in STF yet, or STF has not bound it to the node yet; it registers once STF has it. A device that stays unbound was rejected by STF (Rejected the registration of device in the log of the STF processor): check STF_NODE_TOKEN and STF_PROVIDER_HOST of the device container with ./zebrunner.sh doctor of mcloud-agent. |
is bound to another node in STF |
The UDID of the node is a device of another node in STF: the node registers a device of another host (a wrong DEVICE_UDID, or a device moved to another host without the restart of the device container there). |
A registered node that disappears with [NODE TOKEN] STF does not accept the node token of node ... any more was revoked, joined again or moved: join it again.
STF_URL and STF_TOKEN are not set in the log of the start (SEVERE) and STF_URL and STF_TOKEN of the hub are not set for every node: set both and restart the hub, it verifies the node tokens with STF.
The nodes are answered 503 (The hub did not register the node within 25s, The hub is still registering this node, The hub registers 8 nodes at once) while the registrations of the nodes do not finish: [NODE REGISTRATION] A registration of a node has been running for ... in the log of the hub has the stack of the thread, where it waits (e.g. a request to STF or to a node). A registration that runs longer than 3 minutes makes the hub unhealthy ([HEALTH] The hub is not healthy in the log, unhealthy in docker ps): restart it, docker restart mcloud-grid, and report the stack.
- The entrypoint validates the variables of the hub config (
GRID_*) first: every invalid one is logged (SEVERE, e.g.GRID_TIMEOUT '1h' is not a whole number of at least 0.), then the container exits with0, so a restart policy does not restart it: a restart does not fix the configuration. Fix the variables and start the container again. GRID_AUTH_SECRETis validated with them: empty, or at least 32 characters without whitespace (the log tells its length, never the secret).1:/opt/selenium/config.jsoncould not be written, a restart may fix it; or the authentication of the users ([AUTHENTICATION] ... the hub is stopped.), the node API or the error pages of the hub ([CONFIGURATION] ... the hub is stopped.) could not be added to the started hub: the hub does not run without them.- Otherwise the container runs the hub until it stops:
docker stopstops it gracefully (shutdown completein the log). - The healthcheck of the image is
GET /grid/api/healthof the hub every 30 s (curl --max-time 4, timeout 5 s, 3 retries, start period 30 s). A thread of Jetty answers it like the requests of the users and the nodes, without a user, asking no node and no STF:200{"healthy": true}, or503with the reason ({"healthy": false, "message": ...}, logged once as[HEALTH] The hub is not healthy) while a registration of a node runs longer than 3 minutes (see Node registration), the lock of the registry is not free within 2 s or its matcher stopped. A hub whose threads are all busy does not answer it in time either. So a hub that answers nothing (no status, no registration) turnsunhealthywithin about 2 minutes. - Docker does not restart an
unhealthycontainer (restartpolicies apply to a container that exits): restart it withdocker restart mcloud-grid(./zebrunner.sh doctorof mcloud reports the unhealthy grid).
Requirements: docker, python 3 (for the linters), hadolint on macOS (brew install hadolint). tests/mvn.sh runs the pinned Maven + JDK toolchain in maven:3.9.16-eclipse-temurin-11, so host-wide mvn and Java installs are optional.
make check # everything CI runs make lint # yaml, GitHub workflows, Dockerfile, markdown, shell scripts, the text files, checkstyle, spotbugs make test # unit and STF integration tests, coverage in target/site/jacoco make docker # docker image checks: user, the start without STF (every node refused), config generation, options, endpoints, node registration with a fake STF, graceful shutdown make load # short load test of the image with fake Appium nodes and a fake STF
tests/lint.sh and tests/docker_test.sh write JUnit XML into $JUNIT_DIR when it is set, maven writes it into target/surefire-reports. Tests with STF enabled (TestNG group stf) run in their own JVM against a WireMock STF stub. Load tests against real grids are described in LOAD_TESTING.md. CI (.github/workflows/ci.yml) runs the same checks on pushes and pull requests: jobs lint, tests and docker (the image checks and a load test with fake Appium nodes and a fake STF; its builds of the image keep their layers, also the Maven dependencies of the build stage, in the cache of GitHub Actions through DOCKER_BUILD_OPTS of tests/docker_test.sh and tests/load_local.sh); dependabot proposes updates weekly.
The conventions of the style, the formatting and the tooling of this repository are in CONVENTIONS.md, the same in all the MCloud repositories.
