Last active
August 19, 2024 02:47
-
-
Save elikem/b48040984f54bdae13266c48b298a21d to your computer and use it in GitHub Desktop.
Example of automated tests on https://californiahvip.org
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # test to assert page title: is what is expected | |
| # test to assert search button: test the presence of the search link | |
| # test to assert presence of a searchable article: test the presence of a searchable article 'Evening Community Meeting' | |
| import time | |
| import unittest | |
| import warnings | |
| from selenium import webdriver | |
| from selenium.webdriver.common.by import By | |
| from selenium.webdriver.common.keys import Keys | |
| warnings.filterwarnings("ignore") | |
| class california_hvip(unittest.TestCase): | |
| def test_page_title(self): | |
| driver = webdriver.Chrome() | |
| driver.get("https://californiahvip.org") | |
| self.assertEqual("Home - Hybrid and Zero-Emission Truck and Bus Voucher Incentive Project | California HVIP", driver.title) | |
| def test_search_button(self): | |
| driver = webdriver.Chrome() | |
| driver.get("https://californiahvip.org") | |
| search_link = driver.find_element(By.CLASS_NAME, 'search-link') | |
| time.sleep(2) | |
| search_link.click() | |
| self.assertTrue(search_link.is_displayed()) | |
| def test_searchable_article(self): | |
| driver = webdriver.Chrome() | |
| driver.get("https://californiahvip.org") | |
| search_button = driver.find_element(By.CLASS_NAME, 'search-link') | |
| time.sleep(2) | |
| search_button.click() | |
| search_box = driver.find_element(By.ID, 'sSearch') | |
| search_box.send_keys('Evening Community Meeting') | |
| time.sleep(2) | |
| search_box.send_keys(Keys.RETURN) | |
| search_result = driver.find_element(By.CSS_SELECTOR, '#content > div.front-last-articles > div.inner > div > div > div:nth-child(1) > a') | |
| time.sleep(2) | |
| search_result.click() | |
| time.sleep(2) | |
| page_title = driver.title | |
| self.assertIn('Evening Community Meeting', page_title) | |
| def tearDown(self): | |
| driver = webdriver.Chrome() | |
| driver.quit() | |
| if __name__ == '__main__': | |
| unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment