Repository navigation
Expand file tree
/
Copy pathtesting.py
More file actions
55 lines (40 loc) · 1.5 KB
/
Copy pathtesting.py
File metadata and controls
55 lines (40 loc) · 1.5 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
from selenium import webdriver
from selenium.webdriver.common.by import By
from concurrent.futures import ThreadPoolExecutor
import os
import time
import random
import matplotlib.pyplot as plt
import datetime
FILES_DIR = 'Testing files'
APP_URL = 'http://localhost:5000'
CHROME_DRIVER_PATH = 'C:/webdrivers/chromedriver.exe'
def upload_random_file(_):
file_name = random.choice(os.listdir(FILES_DIR))
driver = webdriver.Chrome(executable_path=CHROME_DRIVER_PATH)
driver.get(APP_URL)
absolute_file_path = os.path.abspath(os.path.join(FILES_DIR, file_name))
start_time = time.time()
file_input = driver.find_element(By.NAME, 'file')
file_input.send_keys(absolute_file_path)
submit_button = driver.find_element(By.XPATH, '//input[@type="submit"]')
submit_button.click()
time.sleep(2) # Wait for upload to complete
end_time = time.time()
driver.quit()
return end_time - start_time # Return the time taken for upload
num_uploads = 40
times_taken = []
with ThreadPoolExecutor(max_workers=10) as executor:
results = executor.map(upload_random_file, range(num_uploads))
times_taken = list(results)
current_timestamp = datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
filename = f'upload_performance_{current_timestamp}.png'
plt.figure(figsize=(10, 6))
plt.hist(times_taken, bins=20, color='skyblue', edgecolor='black')
plt.title('File Upload Performance')
plt.xlabel('Time Taken (s)')
plt.ylabel('Number of Uploads')
plt.grid(True)
plt.savefig(filename)
plt.show()