-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_petclinic.py
105 lines (86 loc) · 3.43 KB
/
test_petclinic.py
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
99
100
101
102
103
104
105
import logging
import time
import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
# Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
@pytest.fixture(scope="module")
def browser():
logging.info("Starting the browser")
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(options=chrome_options)
yield driver
driver.quit()
time.sleep(5)
def test_navigate_home_page(browser):
logging.info("Navigating to the home page")
browser.get("http://localhost:8080/petclinic/")
time.sleep(5)
def test_find_owners(browser):
logging.info("Finding and clicking on the 'Find Owners' link")
find_owners_link = browser.find_element(By.XPATH, '//a[contains(@href, "/petclinic/owners/find")]')
find_owners_link.click()
time.sleep(5)
def test_search_franklin(browser):
logging.info("Searching for 'Franklin'")
search_bar = browser.find_element(By.NAME, "lastName")
search_bar.clear()
search_bar.send_keys("Franklin")
time.sleep(1)
search_bar.submit()
time.sleep(5)
def test_navigate_veterinarians(browser):
logging.info("Finding and clicking on the 'Veterinarians' link")
vets_link = browser.find_element(By.XPATH, '//a[contains(@href, "/petclinic/vets")]')
vets_link.click()
time.sleep(5)
def test_navigate_oups(browser):
logging.info("Finding and clicking on the 'oups' link")
oups_link = browser.find_element(By.XPATH, '//a[contains(@href, "/petclinic/oups")]')
oups_link.click()
time.sleep(5)
if __name__ == '__main__':
logging.info("Script started")
pytest.main([__file__])
logging.info("Script finished successfully")
# import logging
# import time
# from selenium import webdriver
# from selenium.webdriver.common.by import By
# from selenium.webdriver.chrome.options import Options
# # Configure logging
# logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
# logging.info("Starting the script")
# chrome_options = Options()
# chrome_options.add_argument('--headless')
# chrome_options.add_argument('--no-sandbox') # Add this line
# chrome_options.add_argument('--disable-dev-shm-usage') # Add this line
# driver = webdriver.Chrome(options=chrome_options)
# logging.info("Navigating to the home page")
# driver.get("http://localhost:8080/petclinic/")
# time.sleep(5)
# logging.info("Finding and clicking on the 'Find Owners' link")
# find_owners_link = driver.find_element(By.XPATH, '//a[contains(@href, "/petclinic/owners/find")]')
# find_owners_link.click()
# time.sleep(5)
# logging.info("Searching for 'Franklin'")
# search_bar = driver.find_element(By.NAME, "lastName")
# search_bar.clear()
# search_bar.send_keys("Franklin")
# time.sleep(1)
# search_bar.submit()
# time.sleep(5)
# logging.info("Finding and clicking on the 'Veterinarians' link")
# find_owners_link = driver.find_element(By.XPATH, '//a[contains(@href, "/petclinic/vets")]')
# find_owners_link.click()
# time.sleep(5)
# logging.info("Finding and clicking on the 'oups' link")
# find_owners_link = driver.find_element(By.XPATH, '//a[contains(@href, "/petclinic/oups")]')
# find_owners_link.click()
# time.sleep(5)
# logging.info("Script finished successfully")