Test Overview
This test opens a webpage and finds all buttons with the class 'btn'. It verifies that the number of buttons found matches the expected count.
This test opens a webpage and finds all buttons with the class 'btn'. It verifies that the number of buttons found matches the expected count.
from selenium import webdriver from selenium.webdriver.common.by import By import unittest class TestFindMultipleElements(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com/buttons') def test_find_all_buttons(self): buttons = self.driver.find_elements(By.CLASS_NAME, 'btn') self.assertEqual(len(buttons), 3, 'Expected 3 buttons with class "btn"') def tearDown(self): self.driver.quit() if __name__ == '__main__': unittest.main()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Test framework initializes and prepares to run the test | - | PASS |
| 2 | Browser opens Chrome | Chrome browser window opens, ready to navigate | - | PASS |
| 3 | Navigates to 'https://example.com/buttons' | Page with multiple buttons loaded in browser | - | PASS |
| 4 | Finds all elements with class name 'btn' using find_elements | List of button elements with class 'btn' retrieved | Check that number of buttons found equals 3 | PASS |
| 5 | Assertion checks that length of buttons list is 3 | Test verifies the count matches expected | len(buttons) == 3 | PASS |
| 6 | Browser closes and test ends | Browser window closed, test finished | - | PASS |