-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_python_link1.py
More file actions
69 lines (50 loc) · 2.01 KB
/
test_python_link1.py
File metadata and controls
69 lines (50 loc) · 2.01 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
import unittest
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
class ChromeLinksTest(unittest.TestCase):
"""
This test class defines automated test cases for interacting with links on the Python website using Selenium and Chrome webdriver.
"""
def setUp(self):
"""
Initializes a new Chrome webdriver instance before each test case.
"""
options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-logging'])
print("Initializing Chrome webdriver...")
self.driver = webdriver.Chrome()
def test_pypi_link(self):
"""
This test case verifies that clicking the "PyPI" link on the Python website redirects the user to the expected PyPI URL.
"""
print("Testing navigation to PyPI using the 'PyPI' link...")
# 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)
# Find the "PyPI" link element using its link text
pypi_link = driver.find_element(By.LINK_TEXT, "PyPI")
# Click on the "PyPI" link
pypi_link.click()
# Wait for 3 seconds for the page to load
time.sleep(3)
print("Navigation to PyPI using 'PyPI' link test passed!")
expected_url = "https://pypi.org/"
actual_url = driver.current_url
self.assertEqual(actual_url, expected_url)
print("Search with Enter key test passed!")
def tearDown(self):
"""
This method closes the Chrome webdriver instance after each test case.
"""
print("Closing Chrome webdriver...")
self.driver.close()
if __name__ == "__main__":
"""
This block checks if the script is run directly (not imported as a module) and executes the test cases.
"""
print("Running test suite...")
unittest.main()