-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSimpleConcurrentExecution.py
More file actions
75 lines (60 loc) · 2.69 KB
/
Copy pathSimpleConcurrentExecution.py
File metadata and controls
75 lines (60 loc) · 2.69 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
__version__ = "2024.03.02.01"
__author__ = "Muthukumar Subramanian"
'''
SimpleConcurrentExecution
History:
2024.03.02.01 - Initial Draft
'''
import time
import concurrent.futures
from selenium import webdriver
def run_selenium_test(server_config, test_case):
# Simulating test execution
# driver = webdriver.Chrome()
print(f"Running Selenium test, server_config: {server_config}, test_case: {test_case}")
for i in range(5):
time.sleep(1)
print(f"Sleep: {i}, server_config: {server_config}, test_case: {test_case}")
# driver.quit()
def run_suite(suite_name, test_cases, server_config, test_parallel=True):
# Ensure tests are executed in parallel if test_parallel is True
if test_parallel:
with concurrent.futures.ThreadPoolExecutor() as executor:
executor.map(lambda test_case: run_selenium_test(server_config, test_case), test_cases)
else:
for test_case in test_cases:
run_selenium_test(server_config, test_case)
def run_parallel_test_suites(server_config, test_suites, test_parallel):
# suite_tasks = []
for suite_name, test_cases in test_suites.items():
# Ensure tests within each suite are executed sequentially if test_parallel is False
if test_parallel:
with concurrent.futures.ThreadPoolExecutor() as executor:
executor.submit(run_suite, suite_name, test_cases, server_config, test_parallel)
else:
run_suite(suite_name, test_cases, server_config, test_parallel)
def main(server_configs, test_suites, suite_parallel=True, test_parallel=True):
start_time = time.time() # Record start time
# suite_tasks = []
for server_config in server_configs:
if suite_parallel:
# Run suites in parallel
with concurrent.futures.ThreadPoolExecutor() as executor:
executor.submit(run_parallel_test_suites, server_config, test_suites, test_parallel)
else:
# Run suites sequentially
for suite_name, test_cases in test_suites.items():
run_suite(suite_name, test_cases, server_config, test_parallel)
end_time = time.time() # Record end time
# Calculate total execution time
total_time = end_time - start_time
print(f"Total execution time: {total_time} seconds")
if __name__ == "__main__":
test_suites = {
"testsuite-1": ["tc-1", "tc-2", "tc-3"],
"testsuite-2": ["tc-5", "tc-6"]
}
server_configs = ["Excel_sheet_1", "Excel_sheet_2", "Excel_sheet_3"]
suite_parallel_execution = False
test_parallel_execution = False
main(server_configs, test_suites, suite_parallel=suite_parallel_execution, test_parallel=test_parallel_execution)