Test Overview
This test opens a web browser and navigates to a specific URL. It verifies that the page title matches the expected title to confirm the correct page loaded.
This test opens a web browser and navigates to a specific URL. It verifies that the page title matches the expected title to confirm the correct page loaded.
from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.common.by import By import unittest class TestOpenURL(unittest.TestCase): def setUp(self): service = Service() self.driver = webdriver.Chrome(service=service) self.driver.implicitly_wait(10) def test_open_url_and_check_title(self): url = "https://example.com" expected_title = "Example Domain" self.driver.get(url) actual_title = self.driver.title self.assertEqual(actual_title, expected_title, f"Page title should be '{expected_title}'") def tearDown(self): self.driver.quit() if __name__ == '__main__': unittest.main()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and WebDriver Chrome instance is created | Chrome browser window opens, ready for commands | — | PASS |
| 2 | Browser navigates to 'https://example.com' using driver.get() | Browser loads the Example Domain page | — | PASS |
| 3 | Retrieve the page title using driver.title | Page title is 'Example Domain' | Check if actual title equals 'Example Domain' | PASS |
| 4 | Assert that the page title matches expected title | Title matches expected | assertEqual passes | PASS |
| 5 | Test ends and browser is closed with driver.quit() | Browser window closes | — | PASS |
driver.get(url) do in a test script?driver.get(url)driver.quit(), refreshing by driver.refresh(), and finding elements by driver.find_element().get(), used as driver.get(url).from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.google.com")
print(driver.title)
driver.quit()get(), prints the page title, then closes the browser with quit().from selenium import webdriver
driver = webdriver.Firefox()
driver.get("www.example.com")
driver.quit()driver.get() multiple times in a row opens each URL sequentially in the same browser window.Pass the test and this pattern moves unknown