-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_python_menu1.py
More file actions
98 lines (72 loc) · 3.37 KB
/
test_python_menu1.py
File metadata and controls
98 lines (72 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import unittest
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.expected_conditions import *
from selenium.webdriver.support.ui import WebDriverWait
import logging
class ChromeMenuTest(unittest.TestCase):
"""
This test class defines automated test cases for interacting with links on the Python website using Selenium and Chrome webdriver.
It utilizes logging to record informative messages and explicit waits for reliable page interactions.
"""
def setUp(self):
"""
Initializes a new Chrome webdriver instance and configures logging.
"""
logging.basicConfig(level=logging.INFO, filename="py_log.log", filemode="w")
logging.info("Initializing Chrome webdriver...")
options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-logging'])
self.driver = webdriver.Chrome(options=options)
def test_menu_link_psf_newsletter(self):
"""
Verifies navigation to the "PSF Newsletter Signup" page by clicking the "PSF Newsletter" link.
"""
logging.info("Testing navigation to 'PSF Newsletter Signup' page...")
# Get the Chrome webdriver instance
driver = self.driver
# Open the Python website
driver.get("https://www.python.org")
# Verify the page title contains "Python"
self.assertIn("Python", driver.title)
psf_newsletter_link_xpath = "//li[@class='tier-1 element-6']/ul[@class='subnav menu']/li[2]"
news_link = WebDriverWait(driver, 10).until( # Explicit wait for element presence
presence_of_element_located((By.XPATH, psf_newsletter_link_xpath))
)
news_link.click()
expected_url = "https://www.python.org/psf/newsletter/"
actual_url = driver.current_url
self.assertEqual(actual_url, expected_url)
logging.info("Navigation to 'PSF Newsletter Signup' page successful!")
def test_menu_link_psf_news(self):
"""
Verifies navigation to the "News from the Python Software Foundation" page by clicking the "PSF News" link.
"""
logging.info("Testing navigation to 'News from the Python Software Foundation' page...")
# Get the Chrome webdriver instance
driver = self.driver
# Open the Python website
driver.get("https://www.python.org")
# Verify the page title contains "Python"
self.assertIn("Python", driver.title)
psf_news_link_xpath = "//li[@class='tier-1 element-6']/ul[@class='subnav menu']/li[3]"
news_link = WebDriverWait(driver, 10).until( # Explicit wait for element presence
presence_of_element_located((By.XPATH, psf_news_link_xpath))
)
news_link.click()
expected_url = "https://pyfound.blogspot.com/"
actual_url = driver.current_url
self.assertEqual(actual_url, expected_url)
logging.info("Navigation to 'News from the Python Software Foundation' page successful!")
def tearDown(self):
"""
This method closes the Chrome webdriver instance after each test case.
"""
logging.info("Closing Chrome webdriver...")
self.driver.close()
if __name__ == "__main__":
"""
Executes the test suite if the script is run directly.
"""
print("Running test suite...")
unittest.main()