Test Overview
This test selects multiple options from a multi-select dropdown and verifies that the correct options are selected.
This test selects multiple options from a multi-select dropdown and verifies that the correct options are selected.
from selenium import webdriver from selenium.webdriver.support.ui import Select import unittest class TestMultiSelect(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com/multiselect') def test_multi_select(self): select_element = self.driver.find_element('id', 'fruits') multi_select = Select(select_element) # Select multiple options by visible text multi_select.select_by_visible_text('Apple') multi_select.select_by_visible_text('Banana') multi_select.select_by_visible_text('Cherry') selected_options = [option.text for option in multi_select.all_selected_options] self.assertIn('Apple', selected_options) self.assertIn('Banana', selected_options) self.assertIn('Cherry', selected_options) 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 is open, ready to navigate | - | PASS |
| 2 | Browser navigates to 'https://example.com/multiselect' | Page with multi-select dropdown loaded | - | PASS |
| 3 | Find element with id 'fruits' representing the multi-select dropdown | Multi-select dropdown element located | - | PASS |
| 4 | Select 'Apple' option by visible text | 'Apple' option is selected in the dropdown | - | PASS |
| 5 | Select 'Banana' option by visible text | 'Banana' option is selected along with 'Apple' | - | PASS |
| 6 | Select 'Cherry' option by visible text | 'Cherry', 'Banana', and 'Apple' options are all selected | - | PASS |
| 7 | Retrieve all selected options' text | List of selected options: ['Apple', 'Banana', 'Cherry'] | Check that 'Apple' is in selected options | PASS |
| 8 | Assert 'Banana' is in selected options | Selected options list unchanged | Check that 'Banana' is in selected options | PASS |
| 9 | Assert 'Cherry' is in selected options | Selected options list unchanged | Check that 'Cherry' is in selected options | PASS |
| 10 | Test ends and browser closes | Browser window closed | - | PASS |