0
0
Selenium Pythontesting~10 mins

Test reporting in CI in Selenium Python - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test opens a web page, clicks a button, and verifies the result. It demonstrates how test results are reported in a Continuous Integration (CI) environment.

Test Code - Selenium with unittest
Selenium Python
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import unittest

class TestButtonClick(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome()
        self.driver.implicitly_wait(5)

    def test_button_click(self):
        self.driver.get('https://example.com/buttonpage')
        button = WebDriverWait(self.driver, 10).until(
            EC.element_to_be_clickable((By.ID, 'click-me'))
        )
        button.click()
        message = WebDriverWait(self.driver, 10).until(
            EC.visibility_of_element_located((By.ID, 'message'))
        )
        self.assertEqual(message.text, 'Button clicked!')

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

if __name__ == '__main__':
    unittest.main()
Execution Trace - 9 Steps
StepActionSystem StateAssertionResult
1Test startsTest runner initializes and prepares to run tests-PASS
2Browser opens ChromeChrome browser window opens, ready for navigation-PASS
3Navigates to 'https://example.com/buttonpage'Page loads with a button having ID 'click-me'-PASS
4Waits until button with ID 'click-me' is clickableButton is visible and enabledButton is clickablePASS
5Clicks the buttonButton click triggers message display-PASS
6Waits until message with ID 'message' is visibleMessage element appears with text 'Button clicked!'Message is visiblePASS
7Checks that message text equals 'Button clicked!'Message text is exactly 'Button clicked!'Assert message.text == 'Button clicked!'PASS
8Test ends and browser closesBrowser window closes, test runner collects results-PASS
9Test report generated in CI environmentCI system shows test passed with detailsTest status is PASS in reportPASS
Failure Scenario
Failing Condition: Message text does not match expected 'Button clicked!'
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify after clicking the button?
AThat the page URL changes
BThat the message text is 'Button clicked!'
CThat the button disappears
DThat the browser closes automatically
Key Result
Always include clear assertions and wait conditions to ensure reliable test results in CI environments.