0
0
Selenium Pythontesting~10 mins

First Selenium script in Selenium Python - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test opens a browser, goes to example.com, checks the page title, and closes the browser. It verifies the page loaded correctly by checking the title text.

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 TestExampleDotCom(unittest.TestCase):
    def setUp(self):
        options = Options()
        options.add_argument('--headless')  # Run browser in headless mode
        service = Service()
        self.driver = webdriver.Chrome(service=service, options=options)

    def test_title(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 - 7 Steps
StepActionSystem StateAssertionResult
1Test starts - unittest framework initializes test caseNo browser open yet-PASS
2Browser opens in headless mode using ChromeDriverChrome browser running without UI-PASS
3Navigates to 'https://example.com'Browser loads example.com homepage-PASS
4Reads page titlePage title is 'Example Domain'Check if title equals 'Example Domain'PASS
5Assertion checks title equalityTitle matches expected textassertEqual(title, 'Example Domain')PASS
6Browser closesNo browser running-PASS
7Test ends successfullyTest framework reports success-PASS
Failure Scenario
Failing Condition: Page title does not match 'Example Domain' due to navigation failure or page change
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test check after opening the browser?
AThe page contains a login form
BThe browser window size
CThe page title is 'Example Domain'
DThe URL contains 'test'
Key Result
Always verify key page elements like the title to confirm the page loaded correctly before continuing tests.