Commit 15b4b755 authored by JunHyung An's avatar JunHyung An
Browse files

lint check

parent 8b5ea9c0
Loading
Loading
Loading
Loading
Loading
+43 −40
Original line number Diff line number Diff line
# -*- coding: utf-8 -*-
"""Load check script using Selenium for web application testing."""
import sys
import threading  # Import the threading module
import threading
import time
import unittest
import random
@@ -15,7 +15,9 @@ from selenium.webdriver.support import expected_conditions as EC

class MultipleTest(unittest.TestCase):
    """A test case for running multiple, concurrent Selenium sessions."""
    def setUp(self):

    def _get_user_inputs(self):
        """Helper method to get user inputs and set up initial configuration."""
        # Test case user input
        print("[필수 입력] Chrome 위치 (e.g., /opt/chrome-linux64/chrome, D:\\tmp\\chrome-win64\\chrome.exe): ")
        self.binary_location = input().strip()
@@ -44,7 +46,6 @@ class MultipleTest(unittest.TestCase):
                    print("입력된 계정 정보가 없습니다. 프로그램을 종료합니다.")
                    sys.exit(1)
                break

            try:
                # Each line is parsed and appended to the list as a dictionary.
                parts = user_input.split(' / ')
@@ -64,6 +65,7 @@ class MultipleTest(unittest.TestCase):
            except (ValueError, IndexError):
                print(f"잘못된 입력 형식입니다: '{user_input}'. 해당 줄은 무시됩니다.")

        # New inputs for connection management
        print("\n[선택(디폴트:일반접속)] 테스트 유형 : 일반 접속(1), 일시 접속(2), 부하 화면 접근(3)")
        try:
            self.function_to_execute = int(input().strip())
@@ -88,12 +90,19 @@ class MultipleTest(unittest.TestCase):
            self.max_connections = 50
            self.ramp_up_time = 30 * 60

    def setUp(self):
        self._get_user_inputs()
        # Initialize a list to hold driver instances for each thread
        self.drivers = []
        self.verification_errors = []
        self.accept_next_alert = True

    def _interact_with_time_filters(self, driver):
        """
        Automates the interaction with time filter buttons on a webpage using
        Selenium WebDriver. This function specifically targets the time filter
        dropdown and options found in sections like 'Performance/Operation' (성능/운영).
        """
        driver.find_element(By.XPATH, "//div[@id='page-wrapper']/div/div/div[2]/div/span[2]/div/button[2]/span").click()
        driver.find_element(By.XPATH, "//div[contains(@class, 'el-popover')]//button[span[contains(text(), '최근 3 시간')]]").click()
        driver.find_element(By.XPATH, "//div[@id='page-wrapper']/div/div/div[2]/div/span[2]/div/button[2]/span").click()
@@ -265,69 +274,63 @@ class MultipleTest(unittest.TestCase):
        driver.find_element(By.XPATH, "(.//*[normalize-space(text()) and normalize-space(.)='동작 상태'])[33]/following::li[1]").click()
        driver.find_element(By.XPATH, "//div[2]/div/div/button/i").click()

    def _execute_single_action_and_measure(self, driver, user_id, action_func, driver_instance_number, action_name, *args, **kwargs):
    def _execute_single_action_and_measure(self, driver, action_func, action_name, *args, **kwargs):
        """Executes a single action and measures its duration."""
        start_time = time.time()
        try:
            action_func(driver, *args, **kwargs)
        except Exception as e:
            print(f"Session {driver_instance_number}, Action {action_name} failed: {e}")
            print(f"Session {driver.instance_number}, Action {action_name} failed: {e}")
        finally:
            end_time = time.time()
            # Use the 'user_id' parameter passed to the function
            print(f"Session {driver_instance_number}, User: {user_id}: {action_name} executed in {end_time - start_time:.2f} seconds")
            print(f"Session {driver.instance_number}, User: {driver.user_id}: {action_name} executed in {end_time - start_time:.2f} seconds")

    def _run_driver1_actions(self, driver, account_type):
        """Runs the actions for driver type 1."""
        wait = WebDriverWait(driver, 10)
        instance_number = driver.instance_number
        user_id = driver.user_id
        # These actions will be repeated in a loop
        self._execute_single_action_and_measure(driver, user_id, self._dashboard_actions, instance_number, "_dashboard_actions")
        self._execute_single_action_and_measure(driver, user_id, self._topology_map_actions, instance_number, "_topology_map_actions")
        self._execute_single_action_and_measure(driver, user_id, self._performance_operation_actions, instance_number, "_performance_operation_actions")
        self._execute_single_action_and_measure(driver, user_id, self._log_analysis_actions, instance_number, "_log_analysis_actions")
        self._execute_single_action_and_measure(driver, user_id, self._event_status_actions, instance_number, "_event_status_actions")
        self._execute_single_action_and_measure(driver, user_id, self._work_management_actions, instance_number, "_work_management_actions", wait)
        self._execute_single_action_and_measure(driver, self._dashboard_actions, "_dashboard_actions")
        self._execute_single_action_and_measure(driver, self._topology_map_actions, "_topology_map_actions")
        self._execute_single_action_and_measure(driver, self._performance_operation_actions, "_performance_operation_actions")
        self._execute_single_action_and_measure(driver, self._log_analysis_actions, "_log_analysis_actions")
        self._execute_single_action_and_measure(driver, self._event_status_actions, "_event_status_actions")
        self._execute_single_action_and_measure(driver, self._work_management_actions, "_work_management_actions", wait)
        if account_type == 1:
            self._execute_single_action_and_measure(driver, user_id, self._admin_settings_actions, instance_number, "_admin_settings_actions")
            self._execute_single_action_and_measure(driver, self._admin_settings_actions, "_admin_settings_actions")
        elif account_type == 2:
            print(f"Session {instance_number}, User: {user_id}: Manager account - no specific admin actions.")
            print(f"Session {driver.instance_number}, User: {driver.user_id}: Manager account - no specific admin actions.")
        elif account_type == 3:
            print(f"Session {instance_number}, User: {user_id}: User account - no specific admin actions.")
            print(f"Session {driver.instance_number}, User: {driver.user_id}: User account - no specific admin actions.")

    def _run_driver2_actions(self, driver, account_type):
        """Runs the actions for driver type 2."""
        instance_number = driver.instance_number
        user_id = driver.user_id
        # These actions will be repeated in a loop
        self._execute_single_action_and_measure(driver, user_id, self._dashboard_actions, instance_number, "_dashboard_actions")
        self._execute_single_action_and_measure(driver, user_id, self._topology_map_actions, instance_number, "_topology_map_actions")
        self._execute_single_action_and_measure(driver, user_id, self._event_status_actions, instance_number, "_event_status_actions")
        self._execute_single_action_and_measure(driver, self._dashboard_actions, "_dashboard_actions")
        self._execute_single_action_and_measure(driver, self._topology_map_actions, "_topology_map_actions")
        self._execute_single_action_and_measure(driver, self._event_status_actions, "_event_status_actions")
        if account_type == 1:
            print(f"Session {instance_number}, User: {user_id}: Admin actions not defined for this driver function.")
            print(f"Session {driver.instance_number}, User: {driver.user_id}: Admin actions not defined for this driver function.")
        elif account_type == 2:
            print(f"Session {instance_number}, User: {user_id}: Manager account - no specific admin actions.")
            print(f"Session {driver.instance_number}, User: {driver.user_id}: Manager account - no specific admin actions.")
        elif account_type == 3:
            print(f"Session {instance_number}, User: {user_id}: User account - no specific admin actions.")
            print(f"Session {driver.instance_number}, User: {driver.user_id}: User account - no specific admin actions.")

    def _run_driver3_actions(self, driver, account_type):
        """Runs the actions for driver type 3."""
        instance_number = driver.instance_number
        user_id = driver.user_id
        # These actions will be repeated in a loop
        self._execute_single_action_and_measure(driver, user_id, self._dashboard_actions, instance_number, "_dashboard_actions (1st)")
        self._execute_single_action_and_measure(driver, user_id, self._dashboard_actions, instance_number, "_dashboard_actions (2nd)")
        self._execute_single_action_and_measure(driver, user_id, self._performance_operation_actions, instance_number, "_performance_operation_actions (1st)")
        self._execute_single_action_and_measure(driver, user_id, self._performance_operation_actions, instance_number, "_performance_operation_actions (2nd)")
        self._execute_single_action_and_measure(driver, user_id, self._log_analysis_actions, instance_number, "_log_analysis_actions (1st)")
        self._execute_single_action_and_measure(driver, user_id, self._log_analysis_actions, instance_number, "_log_analysis_actions (2nd)")
        self._execute_single_action_and_measure(driver, self._dashboard_actions, "_dashboard_actions (1st)")
        self._execute_single_action_and_measure(driver, self._dashboard_actions, "_dashboard_actions (2nd)")
        self._execute_single_action_and_measure(driver, self._performance_operation_actions, "_performance_operation_actions (1st)")
        self._execute_single_action_and_measure(driver, self._performance_operation_actions, "_performance_operation_actions (2nd)")
        self._execute_single_action_and_measure(driver, self._log_analysis_actions, "_log_analysis_actions (1st)")
        self._execute_single_action_and_measure(driver, self._log_analysis_actions, "_log_analysis_actions (2nd)")
        if account_type == 1:
            self._execute_single_action_and_measure(driver, user_id, self._admin_alarm_settings_actions, instance_number, "_admin_alarm_settings_actions")
            self._execute_single_action_and_measure(driver, self._admin_alarm_settings_actions, "_admin_alarm_settings_actions")
        elif account_type == 2:
            print(f"Session {instance_number}, User: {user_id}: Manager account - no specific admin actions.")
            print(f"Session {driver.instance_number}, User: {driver.user_id}: Manager account - no specific admin actions.")
        elif account_type == 3:
            print(f"Session {instance_number}, User: {user_id}: User account - no specific admin actions.")
            print(f"Session {driver.instance_number}, User: {driver.user_id}: User account - no specific admin actions.")

    def _run_single_driver_actions(self, address, user_id, pw, account_type, driver_instance_number):
        """Sets up and runs a single driver instance's actions."""
@@ -358,7 +361,7 @@ class MultipleTest(unittest.TestCase):
        start_time = time.time()
        # Log in once at the start of the session
        wait = WebDriverWait(driver, 10)
        self._execute_single_action_and_measure(driver, user_id, self._login_action, driver_instance_number, "_login_action", address, user_id, pw, wait)
        self._execute_single_action_and_measure(driver, self._login_action, "_login_action", address, user_id, pw, wait)

        print(f"Starting looped actions for session {driver_instance_number} with user: {user_id}")

@@ -452,8 +455,8 @@ class MultipleTest(unittest.TestCase):
        for driver in self.drivers:
            try:
                driver.quit()
            except Exception:
                print("Error quitting driver.")
            except Exception as e:
                print(f"Error quitting driver: {e}")
        self.assertEqual([], self.verification_errors)