0
0
Selenium Pythontesting~10 mins

GitHub Actions integration in Selenium Python - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test automates a simple web login scenario using Selenium in Python. It verifies that the login button is clickable and that the user is redirected to the dashboard page after login. The test is designed to run in a GitHub Actions workflow to ensure continuous integration.

Test Code - Selenium
Selenium Python
import unittest
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

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

    def test_login(self):
        driver = self.driver
        driver.get('https://example.com/login')

        # Wait for username field and enter username
        WebDriverWait(driver, 10).until(
            EC.presence_of_element_located((By.ID, 'username'))
        )
        driver.find_element(By.ID, 'username').send_keys('testuser')

        # Wait for password field and enter password
        WebDriverWait(driver, 10).until(
            EC.presence_of_element_located((By.ID, 'password'))
        )
        driver.find_element(By.ID, 'password').send_keys('password123')

        # Wait for login button and click
        login_button = WebDriverWait(driver, 10).until(
            EC.element_to_be_clickable((By.ID, 'login-btn'))
        )
        login_button.click()

        # Verify redirection to dashboard
        WebDriverWait(driver, 10).until(
            EC.url_contains('/dashboard')
        )
        self.assertIn('/dashboard', driver.current_url)

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

if __name__ == '__main__':
    unittest.main()
Execution Trace - 7 Steps
StepActionSystem StateAssertionResult
1Test starts - unittest framework initializes and setUp method opens Chrome browserChrome browser window opens, ready to navigate-PASS
2Browser navigates to 'https://example.com/login'Login page loads with username, password fields and login button visible-PASS
3Waits for username field presence and enters 'testuser'Username input field is filled with 'testuser'Presence of username field verifiedPASS
4Waits for password field presence and enters 'password123'Password input field is filled with 'password123'Presence of password field verifiedPASS
5Waits for login button to be clickable and clicks itLogin button clicked, form submittedLogin button is clickablePASS
6Waits for URL to contain '/dashboard' after loginBrowser URL changes to dashboard pageCurrent URL contains '/dashboard'PASS
7Test ends - tearDown method closes browserBrowser window closes-PASS
Failure Scenario
Failing Condition: Login button is not found or not clickable within 10 seconds
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify after clicking the login button?
AThat the URL contains '/dashboard'
BThat the username field is cleared
CThat the login button disappears
DThat an error message appears
Key Result
Always use explicit waits like WebDriverWait with expected conditions to handle dynamic page elements reliably in automated tests.