Test Overview
This test runs a simple Selenium script in a Continuous Integration (CI) pipeline. It opens a browser, navigates to a website, finds a search box, enters a query, submits it, and verifies the results page loaded correctly.
This test runs a simple Selenium script in a Continuous Integration (CI) pipeline. It opens a browser, navigates to a website, finds a search box, enters a query, submits it, and verifies the results page loaded correctly.
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys from selenium.webdriver.chrome.options import Options from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC import unittest class TestSearchInCIPipeline(unittest.TestCase): def setUp(self): chrome_options = Options() chrome_options.add_argument('--headless') # Run in headless mode for CI chrome_options.add_argument('--no-sandbox') chrome_options.add_argument('--disable-dev-shm-usage') self.driver = webdriver.Chrome(options=chrome_options) self.driver.implicitly_wait(10) def test_search(self): self.driver.get('https://www.example.com') search_box = self.driver.find_element(By.NAME, 'q') search_box.send_keys('selenium testing') search_box.send_keys(Keys.RETURN) WebDriverWait(self.driver, 10).until( EC.presence_of_element_located((By.ID, 'results')) ) results = self.driver.find_element(By.ID, 'results') self.assertTrue(results.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 is launched in headless mode with CI options | Browser runs without UI, ready to navigate | - | PASS |
| 2 | Browser navigates to https://www.example.com | Example.com homepage is loaded | - | PASS |
| 3 | Finds search input box by name 'q' | Search box element is located on the page | Element with name 'q' is present | PASS |
| 4 | Types 'selenium testing' into search box and presses Enter | Search query submitted, page starts loading results | - | PASS |
| 5 | Waits up to 10 seconds for element with ID 'results' to appear | Results section is loaded and visible | Presence of element with ID 'results' | PASS |
| 6 | Checks if the results element is displayed | Results section is visible on the page | results.is_displayed() returns True | PASS |
| 7 | Browser quits and test ends | Browser closed, resources freed | - | PASS |