-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlatency.py
95 lines (80 loc) · 4.09 KB
/
latency.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
import os
import time
import datetime
from selenium.webdriver.common.keys import Keys
from dataclasses import dataclass
from interaction_manager import InteractionManager, InteractionManagerConfig
import logging
ARMO_PLATFORM_URL = "https://cloud.armosec.io"
logging.basicConfig(level=logging.INFO)
_logger = logging.getLogger(__name__)
@dataclass
class LatencyDetails:
latency: float
latency_without_login: float
def to_file(self, file_path: str) -> None:
timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
with open(file_path, "a") as f:
f.write(f"{timestamp},{self.latency},{self.latency_without_login}\n")
def __str__(self) -> str:
return f"Latency: {self.latency}, Latency without login: {self.latency_without_login}"
def __repr__(self) -> str:
return self.__str__()
class LatencyTest:
def __init__(self) -> None:
_config = InteractionManagerConfig.from_env()
self._interaction_manager = InteractionManager(_config)
def _take_screen_shot(self, description: str) -> None:
_logger.info(f"Taking screenshot: {description}")
timestamp = time.strftime("%Y%m%d-%H%M%S")
screenshot_name = f"{timestamp}_{description}.png"
result = self._interaction_manager.driver.save_screenshot(
screenshot_name)
if result is False:
_logger.error("Failed to take screenshot") # pragma: no cover
raise RuntimeError("Failed to take screenshot")
_logger.info(f"Screenshot saved to: {screenshot_name}")
def _login(self) -> None:
_logger.info("Logging in to Armo")
self._interaction_manager.navigate(ARMO_PLATFORM_URL)
mail_input = self._interaction_manager.wait_until_interactable(
'//*[@id="frontegg-login-box-container-default"]/div[1]/input'
)
mail_input.send_keys(os.environ['email_latency'])
mail_input.send_keys(Keys.ENTER)
password_input = self._interaction_manager.wait_until_interactable(
'/html/body/frontegg-app/div[2]/div[2]/input'
)
password_input.send_keys(os.environ['login_pass_latency'])
password_input.send_keys(Keys.ENTER)
_logger.info("Logged in to Armo")
def _navigate_to_compliance(self) -> None:
_logger.info("Navigating to compliance")
# Click on the compliance tab.
self._interaction_manager.click('//*[@id="configuration-scanning-left-menu-item"]')
# Click on the cluster (the first one).
self._interaction_manager.click('/html/body/armo-root/div/div/div/armo-config-scanning-page/div[2]/armo-cluster-scans-table/table/tbody/tr[1]/td[2]')
# Click on the failed resource button.
self._interaction_manager.click('//*[@id="framework-control-table-failed-0"]/div/armo-router-link/a/armo-button/button', click_delay=1)
# Click on the fix button in the rules list.
self._interaction_manager.click("//button[contains(@class, 'armo-button') and contains(@class, 'primary') and contains(@class, 'sm') and span[text()='Fix']]", click_delay=1)
# Switch to the last window.
# self._interaction_manager.switch_to_window(-1)
time.sleep(2)
SBS_panel =self._interaction_manager.wait_until_exists("//td[contains(@class, 'pl-5 w-100 position-relative')]/pre[text()='apiVersion: apps/v1']", timeout=5)
_logger.info(f"side bt side is displayed: {SBS_panel.is_displayed()}")
_logger.info("Navigated to compliance completed")
def run(self) -> None:
start_time = time.time()
self._login()
login_time = time.time()
self._navigate_to_compliance()
end_time = time.time()
latency_without_login = "{:.2f}".format(end_time - login_time)
latency = "{:.2f}".format(end_time - start_time)
latency_details = LatencyDetails(latency, latency_without_login)
latency_details.to_file("./logs/latency_logs.csv")
_logger.info(f"Latency details: {latency_details}")
self._interaction_manager.quit()
if __name__ == "__main__":
LatencyTest().run()