0
0
Selenium Pythontesting~10 mins

HTML report generation in Selenium Python - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test opens a web page, checks the page title, and generates a test report showing the test result.

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

class TestPageTitle(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        options = Options()
        options.add_argument('--headless')
        cls.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')

    @classmethod
    def tearDownClass(cls):
        cls.driver.quit()

if __name__ == '__main__':
    unittest.main(testRunner=unittest.TextTestRunner(verbosity=2))
Execution Trace - 7 Steps
StepActionSystem StateAssertionResult
1Test starts: unittest framework initializes test suiteTest runner ready, ChromeDriver configured with headless option-PASS
2Browser opens: Chrome browser starts in headless modeChrome browser running without UI-PASS
3Navigates: Browser navigates to 'https://example.com'Page 'Example Domain' loaded-PASS
4Finds element: Selenium reads the page titlePage title is 'Example Domain'Check if page title equals 'Example Domain'PASS
5Assertion checks: unittest asserts title equalityAssertion passes as titles matchassertEqual('Example Domain', 'Example Domain')PASS
6Browser closes: ChromeDriver quitsBrowser closed, resources freed-PASS
7Test report generated by unittest TextTestRunnerTest report shows test passed with details-PASS
Failure Scenario
Failing Condition: Page title does not match expected 'Example Domain'
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify on the web page?
AThe page title matches 'Example Domain'
BThe page contains a button with id 'submit'
CThe page URL contains 'test'
DThe page background color is blue
Key Result
Always verify key page elements like the title to confirm correct page load before proceeding with further tests. Generating reports helps track test results clearly.