Test Overview
This test reads login credentials from an Excel file and uses them to perform a login on a web page. It verifies that the login is successful by checking the presence of a logout button.
This test reads login credentials from an Excel file and uses them to perform a login on a web page. It verifies that the login is successful by checking the presence of a logout button.
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 import openpyxl class TestLoginWithExcel(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com/login') def test_login_from_excel(self): # Load Excel file workbook = openpyxl.load_workbook('testdata.xlsx') sheet = workbook.active # Read username and password from first row username = sheet['A2'].value password = sheet['B2'].value driver = self.driver # Find username input and enter value username_input = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.ID, 'username')) ) username_input.clear() username_input.send_keys(username) # Find password input and enter value password_input = driver.find_element(By.ID, 'password') password_input.clear() password_input.send_keys(password) # Click login button login_button = driver.find_element(By.ID, 'loginBtn') login_button.click() # Wait for logout button to appear to confirm login success logout_button = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.ID, 'logoutBtn')) ) # Assert logout button is displayed self.assertTrue(logout_button.is_displayed()) def tearDown(self): self.driver.quit() if __name__ == '__main__': unittest.main()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and Chrome browser opens | Browser window opened at https://example.com/login page | - | PASS |
| 2 | Load Excel file 'testdata.xlsx' and read username and password from cells A2 and B2 | Excel file loaded with test data: username and password read | - | PASS |
| 3 | Find username input field by ID 'username' and enter username | Username input field located and filled with username from Excel | - | PASS |
| 4 | Find password input field by ID 'password' and enter password | Password input field located and filled with password from Excel | - | PASS |
| 5 | Find login button by ID 'loginBtn' and click it | Login button clicked, page processing login | - | PASS |
| 6 | Wait for logout button with ID 'logoutBtn' to appear to confirm login success | Logout button visible on page after successful login | Assert logout button is displayed | PASS |
| 7 | Test ends and browser closes | Browser window closed | - | PASS |