-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_urls.py
More file actions
93 lines (78 loc) · 3.03 KB
/
test_urls.py
File metadata and controls
93 lines (78 loc) · 3.03 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
import undetected_chromedriver as uc
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
import time
def wait_for_final_result(driver, timeout=30):
def check_result(driver):
result_div = driver.find_element(By.ID, 'result')
text = result_div.text.lower()
if 'fetch successful' in text:
return 'success'
if 'fetch failed' in text or 'error:' in text:
return 'error'
return None
try:
wait = WebDriverWait(driver, timeout)
return wait.until(lambda d: check_result(d))
except TimeoutException:
return 'too long'
def modify_url(url):
if url.endswith('/'):
return url + 'api/v2/transactions'
else:
return url + '/api/v2/transactions'
def test_urls():
# Read URLs from file
with open('explorer_urls.txt', 'r') as f:
urls = [line.strip() for line in f.readlines()]
if not urls:
print("No URLs found in explorer_urls.txt")
return []
print(f"Testing {len(urls)} URL(s)...")
# Initialize Chrome driver with undetected-chromedriver
options = uc.ChromeOptions()
options.add_argument('--headless')
print("Starting Chrome...")
driver = uc.Chrome(options=options)
results = []
try:
# Go to the test page
print("Navigating to https://isstuev.github.io/")
driver.get('https://isstuev.github.io/')
# Find the input field and button
url_input = driver.find_element(By.ID, 'urlInput')
test_button = driver.find_element(By.XPATH, "//button[text()='Test Fetch']")
# Test each URL
for url in urls:
mod_url = modify_url(url)
print(f"Testing URL: {mod_url}")
try:
# Clear and fill input
url_input.clear()
url_input.send_keys(mod_url)
print("Clicked test button...")
# Click test button
test_button.click()
# Wait for a final result (success, error, or too long)
result = wait_for_final_result(driver, timeout=30)
print(f"Result: {result}")
results.append(f"{mod_url} | {result}")
except Exception as e:
print(f"Exception: {e}")
results.append(f"{mod_url} | error")
# Small delay between requests
time.sleep(1)
finally:
print("Quitting Chrome...")
driver.quit()
# Save results to file
with open('url_test_results.txt', 'w') as f:
for result in results:
f.write(f"{result}\n")
print("Results saved to url_test_results.txt")
return results
if __name__ == "__main__":
results = test_urls()
print(f"Tested {len(results)} URL(s). Results saved to url_test_results.txt")