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.
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.
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()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and sets up Selenium WebDriver to connect to Docker container at localhost:4444 | Docker container with Selenium Grid is running and ready to accept connections | - | PASS |
| 2 | Browser inside Docker container opens URL 'https://example.com' | Browser navigates to example.com page inside container | - | PASS |
| 3 | Test retrieves the page title from the browser | Page title is 'Example Domain' | Check if page title equals 'Example Domain' | PASS |
| 4 | Test closes the browser and ends session | Browser session inside Docker container is closed | - | PASS |