Bird
Raised Fist0
Selenium Pythontesting~20 mins

Docker-based Grid in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Docker Grid Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of Selenium Grid Node Registration Log
You start a Selenium Grid node using Docker with the command:
docker run -d --net=host -e SE_EVENT_BUS_HOST=localhost -e SE_EVENT_BUS_PUBLISH_PORT=4442 -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 selenium/node-chrome:latest

What will be the expected output in the node's Docker logs indicating successful registration?
AERROR - Could not connect to the hub at http://localhost:4444
BINFO - Registered a node with the hub: http://localhost:4444
CWARN - Node is running but not registered to any hub
DFATAL - Missing environment variables for event bus
Attempts:
2 left
💡 Hint
Look for logs that confirm successful connection to the hub.
❓ assertion
intermediate
2:00remaining
Correct Assertion for Node Availability in Selenium Grid
You want to write a test to assert that a Selenium Grid node is available and ready to accept sessions. Which assertion correctly checks the node's readiness using Selenium Python bindings?
Selenium Python
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

driver = webdriver.Remote(
    command_executor='http://localhost:4444/wd/hub',
    desired_capabilities=DesiredCapabilities.CHROME)

# Which assertion below correctly verifies the node is ready?
Aassert driver.session_id is not None
Bassert driver is None
Cassert driver.title == ''
Dassert driver.current_url == 'about:blank'
Attempts:
2 left
💡 Hint
A valid session_id means the node accepted the session.
🔧 Debug
advanced
2:00remaining
Debugging Selenium Grid Node Connection Failure
You run a Selenium Grid hub and a node in Docker containers on the same machine. The node fails to register with the hub. The node's Docker logs show:
ERROR - Could not connect to the hub at http://localhost:4444

What is the most likely cause?
AThe node image is outdated and incompatible with the hub.
BThe hub is not running on port 4444.
CDocker network is misconfigured to block all traffic.
DThe node container cannot reach the hub at localhost because localhost refers to itself inside the container.
Attempts:
2 left
💡 Hint
Remember how localhost behaves inside Docker containers.
❓ framework
advanced
2:00remaining
Best Practice for Scaling Selenium Grid with Docker
You want to scale your Selenium Grid to run multiple Chrome and Firefox nodes using Docker Compose. Which approach correctly defines the services for scaling nodes?
Selenium Python
version: '3'
services:
  selenium-hub:
    image: selenium/hub:latest
    ports:
      - '4444:4444'
  chrome:
    image: selenium/node-chrome:latest
    depends_on:
      - selenium-hub
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub
      - SE_EVENT_BUS_PUBLISH_PORT=4442
      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
  firefox:
    image: selenium/node-firefox:latest
    depends_on:
      - selenium-hub
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub
      - SE_EVENT_BUS_PUBLISH_PORT=4442
      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
AManually start multiple containers with different ports mapped.
BRun multiple docker-compose files separately for each node.
CAdd 'deploy: replicas: 3' under chrome and firefox services to scale nodes.
DUse 'scale' command in docker-compose CLI to add nodes dynamically.
Attempts:
2 left
💡 Hint
Docker Compose version 3 supports replicas for scaling services.
🧠 Conceptual
expert
2:00remaining
Understanding Event Bus Ports in Selenium Grid Docker Setup
In a Docker-based Selenium Grid setup, the environment variables SE_EVENT_BUS_HOST, SE_EVENT_BUS_PUBLISH_PORT, and SE_EVENT_BUS_SUBSCRIBE_PORT are set for nodes. What is the primary purpose of these event bus ports?
AThey enable communication between the hub and nodes for session management and status updates.
BThey expose the browser debugging ports for remote inspection.
CThey are used to forward HTTP traffic from the hub to the nodes.
DThey configure the ports for Selenium WebDriver commands to reach the browsers.
Attempts:
2 left
💡 Hint
Think about how the hub and nodes coordinate in a distributed grid.

Practice

(1/5)
1. What is the main purpose of using a Docker-based Selenium Grid?
easy
A. To run tests only on the local machine without network
B. To write test scripts without any browser
C. To replace Selenium WebDriver with a new tool
D. To run browser tests in isolated containers for better scalability

Solution

  1. Step 1: Understand Docker-based Grid concept

    Docker-based Grid runs browsers inside containers, isolating tests and allowing many tests to run in parallel.
  2. Step 2: Compare options with this concept

    Only To run browser tests in isolated containers for better scalability correctly describes running tests in isolated containers for scalability.
  3. Final Answer:

    To run browser tests in isolated containers for better scalability -> Option D
  4. Quick Check:

    Docker Grid = isolated, scalable browser tests [OK]
Hint: Docker Grid isolates browsers to run many tests fast [OK]
Common Mistakes:
  • Thinking Docker replaces Selenium WebDriver
  • Believing tests run only locally without network
  • Confusing Docker Grid with test script writing
2. Which Python code snippet correctly creates a Remote WebDriver session to connect to a Docker-based Selenium Grid at URL http://localhost:4444/wd/hub for Chrome browser?
easy
A. driver = webdriver.Remote('http://localhost:4444/wd/hub', browser='chrome')
B. driver = webdriver.Chrome('http://localhost:4444/wd/hub')
C. driver = webdriver.Remote(command_executor='http://localhost:4444/wd/hub', options=webdriver.ChromeOptions())
D. driver = webdriver.ChromeOptions().Remote('http://localhost:4444/wd/hub')

Solution

  1. Step 1: Recall correct Remote WebDriver syntax

    Remote WebDriver requires command_executor URL and browser options object, e.g., ChromeOptions.
  2. Step 2: Match options with correct syntax

    driver = webdriver.Remote(command_executor='http://localhost:4444/wd/hub', options=webdriver.ChromeOptions()) uses webdriver.Remote with command_executor and ChromeOptions correctly; others misuse classes or parameters.
  3. Final Answer:

    driver = webdriver.Remote(command_executor='http://localhost:4444/wd/hub', options=webdriver.ChromeOptions()) -> Option C
  4. Quick Check:

    Remote WebDriver needs command_executor and options [OK]
Hint: Use webdriver.Remote with command_executor and options [OK]
Common Mistakes:
  • Using webdriver.Chrome instead of webdriver.Remote for grid
  • Passing URL directly to webdriver.Chrome constructor
  • Incorrect chaining of ChromeOptions and Remote
3. Given this Python code connecting to a Docker Selenium Grid, what will print(driver.title) output if the page at https://example.com has title "Example Domain"?
from selenium import webdriver

driver = webdriver.Remote(
    command_executor='http://localhost:4444/wd/hub',
    options=webdriver.FirefoxOptions()
)
driver.get('https://example.com')
print(driver.title)
driver.quit()
medium
A. Example Domain
B. https://example.com
C. None
D. Error: NoSuchWindowException

Solution

  1. Step 1: Understand code flow with Remote WebDriver

    The code opens Firefox browser via Docker Grid, navigates to example.com, then prints the page title.
  2. Step 2: Recall page title for https://example.com

    The official example.com page title is "Example Domain", so print(driver.title) outputs this string.
  3. Final Answer:

    Example Domain -> Option A
  4. Quick Check:

    driver.title = page title = "Example Domain" [OK]
Hint: Page title prints exactly what the website sets [OK]
Common Mistakes:
  • Confusing URL with page title
  • Expecting None if using Remote WebDriver
  • Assuming an error without browser session
4. You run this Python test script with Docker Selenium Grid but get a connection error. What is the likely cause?
from selenium import webdriver

driver = webdriver.Remote(
    command_executor='http://localhost:5555/wd/hub',
    options=webdriver.ChromeOptions()
)
driver.get('https://example.com')
medium
A. Docker Selenium Grid is not running on port 5555
B. ChromeOptions cannot be used with Remote WebDriver
C. The URL 'https://example.com' is invalid
D. webdriver.Remote requires a local Chrome browser

Solution

  1. Step 1: Analyze connection error cause

    Connection errors usually mean the Selenium Grid server is unreachable at the given URL and port.
  2. Step 2: Check port and server status

    Port 5555 is uncommon; default Docker Grid uses 4444. If Grid is not running on 5555, connection fails.
  3. Final Answer:

    Docker Selenium Grid is not running on port 5555 -> Option A
  4. Quick Check:

    Connection error = wrong port or server down [OK]
Hint: Check Docker Grid port matches command_executor URL [OK]
Common Mistakes:
  • Thinking ChromeOptions can't be used remotely
  • Blaming website URL for connection errors
  • Assuming Remote needs local browser installed
5. You want to run tests on Chrome and Firefox browsers simultaneously using Docker Selenium Grid. Which Docker Compose service setup is correct to start both browser nodes connected to the hub?
hard
A. version: '3' services: selenium-hub: image: selenium/hub:4.10.0-20230628 ports: - '4444:4444' chrome: image: selenium/node-chrome:4.10.0-20230628 environment: - SE_EVENT_BUS_HOST=selenium-hub firefox: image: selenium/node-firefox:4.10.0-20230628 environment: - SE_EVENT_BUS_HOST=selenium-hub
B. version: '3' services: selenium-hub: image: selenium/hub:4.10.0-20230628 ports: - '4444:4444' chrome: image: selenium/node-chrome:4.10.0-20230628 depends_on: - selenium-hub environment: - SE_EVENT_BUS_HOST=selenium-hub - SE_EVENT_BUS_PUBLISH_PORT=4442 - SE_EVENT_BUS_SUBSCRIBE_PORT=4443 firefox: image: selenium/node-firefox:4.10.0-20230628 depends_on: - selenium-hub environment: - SE_EVENT_BUS_HOST=selenium-hub - SE_EVENT_BUS_PUBLISH_PORT=4442 - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
C. version: '3' services: selenium-hub: image: selenium/hub:4.10.0-20230628 ports: - '4444:4444' chrome: image: selenium/node-chrome:4.10.0-20230628 depends_on: - selenium-hub firefox: image: selenium/node-firefox:4.10.0-20230628 depends_on: - selenium-hub
D. version: '3' services: selenium-hub: image: selenium/hub:4.10.0-20230628 ports: - '4444:4444' chrome: image: selenium/node-chrome:4.10.0-20230628 depends_on: - selenium-hub environment: - SE_EVENT_BUS_HOST=selenium-hub - SE_EVENT_BUS_PUBLISH_PORT=4443 - SE_EVENT_BUS_SUBSCRIBE_PORT=4442 firefox: image: selenium/node-firefox:4.10.0-20230628 depends_on: - selenium-hub environment: - SE_EVENT_BUS_HOST=selenium-hub - SE_EVENT_BUS_PUBLISH_PORT=4442 - SE_EVENT_BUS_SUBSCRIBE_PORT=4443

Solution

  1. Step 1: Understand Docker Compose setup for Selenium Grid

    The hub service exposes port 4444. Each node (chrome, firefox) must depend on hub and set environment variables for event bus host and ports.
  2. Step 2: Check environment variables and dependencies

    version: '3' services: selenium-hub: image: selenium/hub:4.10.0-20230628 ports: - '4444:4444' chrome: image: selenium/node-chrome:4.10.0-20230628 depends_on: - selenium-hub environment: - SE_EVENT_BUS_HOST=selenium-hub - SE_EVENT_BUS_PUBLISH_PORT=4442 - SE_EVENT_BUS_SUBSCRIBE_PORT=4443 firefox: image: selenium/node-firefox:4.10.0-20230628 depends_on: - selenium-hub environment: - SE_EVENT_BUS_HOST=selenium-hub - SE_EVENT_BUS_PUBLISH_PORT=4442 - SE_EVENT_BUS_SUBSCRIBE_PORT=4443 correctly sets SE_EVENT_BUS_HOST, SE_EVENT_BUS_PUBLISH_PORT=4442, and SE_EVENT_BUS_SUBSCRIBE_PORT=4443 for both nodes, matching Selenium Grid docs.
  3. Final Answer:

    version: '3' services: selenium-hub: image: selenium/hub:4.10.0-20230628 ports: - '4444:4444' chrome: image: selenium/node-chrome:4.10.0-20230628 depends_on: - selenium-hub environment: - SE_EVENT_BUS_HOST=selenium-hub - SE_EVENT_BUS_PUBLISH_PORT=4442 - SE_EVENT_BUS_SUBSCRIBE_PORT=4443 firefox: image: selenium/node-firefox:4.10.0-20230628 depends_on: - selenium-hub environment: - SE_EVENT_BUS_HOST=selenium-hub - SE_EVENT_BUS_PUBLISH_PORT=4442 - SE_EVENT_BUS_SUBSCRIBE_PORT=4443 -> Option B
  4. Quick Check:

    Correct event bus ports and depends_on = version: '3' services: selenium-hub: image: selenium/hub:4.10.0-20230628 ports: - '4444:4444' chrome: image: selenium/node-chrome:4.10.0-20230628 depends_on: - selenium-hub environment: - SE_EVENT_BUS_HOST=selenium-hub - SE_EVENT_BUS_PUBLISH_PORT=4442 - SE_EVENT_BUS_SUBSCRIBE_PORT=4443 firefox: image: selenium/node-firefox:4.10.0-20230628 depends_on: - selenium-hub environment: - SE_EVENT_BUS_HOST=selenium-hub - SE_EVENT_BUS_PUBLISH_PORT=4442 - SE_EVENT_BUS_SUBSCRIBE_PORT=4443 [OK]
Hint: Set SE_EVENT_BUS_HOST and ports exactly as docs show [OK]
Common Mistakes:
  • Omitting depends_on causing nodes to start before hub
  • Wrong or missing event bus port environment variables
  • Swapping publish and subscribe port numbers
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard