0
0
Selenium Pythontesting~10 mins

Docker containers for test execution in Selenium Python - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test opens a web page inside a Docker container running Selenium WebDriver. It verifies the page title to confirm the browser inside the container works correctly.

Test Code - unittest
Selenium Python
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
import unittest

class TestDockerSelenium(unittest.TestCase):
    def setUp(self):
        chrome_options = Options()
        chrome_options.add_argument('--headless')
        chrome_options.add_argument('--no-sandbox')
        chrome_options.add_argument('--disable-dev-shm-usage')
        self.driver = webdriver.Remote(
            command_executor='http://localhost:4444/wd/hub',
            options=chrome_options
        )

    def test_open_example(self):
        self.driver.get('https://example.com')
        title = self.driver.title
        self.assertEqual(title, 'Example Domain')

    def tearDown(self):
        self.driver.quit()

if __name__ == '__main__':
    unittest.main()
Execution Trace - 4 Steps
StepActionSystem StateAssertionResult
1Test starts and sets up Selenium WebDriver to connect to Docker container at localhost:4444Docker container with Selenium Grid is running and ready to accept connections-PASS
2Browser inside Docker container opens URL 'https://example.com'Browser navigates to example.com page inside container-PASS
3Test retrieves the page title from the browserPage title is 'Example Domain'Check if page title equals 'Example Domain'PASS
4Test closes the browser and ends sessionBrowser session inside Docker container is closed-PASS
Failure Scenario
Failing Condition: Docker container with Selenium is not running or unreachable at localhost:4444
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify inside the Docker container?
AThe page URL contains 'docker'
BThe page title is 'Example Domain'
CThe browser version is Chrome
DThe container has internet access
Key Result
Using Docker containers for test execution isolates browser environments, making tests consistent and easy to run on any machine without local browser setup.