-
Notifications
You must be signed in to change notification settings - Fork 0
/
seltest.py
60 lines (52 loc) · 1.8 KB
/
seltest.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
# Import necessary libraries
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
# Set up the webdriver
driver = webdriver.Chrome() # Replace with your preferred browser
# Function to test website functionalities
def test_website(url):
driver.get(url)
# Test navigation
try:
nav_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "nav a"))
)
nav_button.click()
print("Navigation test passed")
except TimeoutException:
print("Navigation test failed")
# Test search functionality
try:
search_box = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.NAME, "search"))
)
search_box.send_keys("test")
search_box.submit()
print("Search test passed")
except TimeoutException:
print("Search test failed")
# Test login functionality
try:
login_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "button[type='submit']"))
)
login_button.click()
print("Login test passed")
except TimeoutException:
print("Login test failed")
# Test form submission
try:
form_field = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.NAME, "username"))
)
form_field.send_keys("test")
form_field.submit()
print("Form submission test passed")
except TimeoutException:
print("Form submission test failed")
driver.quit()
# Test the website
test_website("https://www.example.com")