0
0
Selenium Pythontesting~10 mins

Jenkins integration in Selenium Python - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test automates a simple login scenario using Selenium WebDriver in Python. It verifies that the login button is clickable and that the user is redirected to the dashboard page after login. This test is designed to be integrated and run in Jenkins for continuous testing.

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 LoginTest(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome()
        self.driver.get('https://example.com/login')

    def test_login(self):
        driver = self.driver
        # Wait until the username field is present
        WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, 'username')))
        username_input = driver.find_element(By.ID, 'username')
        password_input = driver.find_element(By.ID, 'password')
        login_button = driver.find_element(By.ID, 'login-btn')

        username_input.send_keys('testuser')
        password_input.send_keys('password123')
        login_button.click()

        # Wait until redirected 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 the test caseTest runner is ready to execute the test-PASS
2Browser opens Chrome and navigates to 'https://example.com/login'Login page is loaded in the browserWebDriverWait waits for username field presencePASS
3Find username, password input fields and login button by IDAll elements are located on the login pageElements are found without exceptionsPASS
4Enter 'testuser' in username and 'password123' in password fieldsInput fields contain the entered text-PASS
5Click the login buttonBrowser submits login form-PASS
6Wait until URL contains '/dashboard' indicating successful loginBrowser navigates to dashboard pageAssert current URL contains '/dashboard'PASS
7Test ends - browser closesBrowser window is closed-PASS
Failure Scenario
Failing Condition: Login button element with ID 'login-btn' is not found on the page
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify after clicking the login button?
AThat the URL contains '/dashboard' indicating successful login
BThat the login button becomes disabled
CThat an error message appears on the login page
DThat the username field is cleared
Key Result
Always use explicit waits like WebDriverWait to ensure elements are present before interacting, especially in automated tests run in CI tools like Jenkins.