Commit f9493f30 authored by Watchtek's avatar Watchtek
Browse files

Merge branch 'dev' into 'main'

Library version upgrade with Add connection check

See merge request watchtek-group/load-test!14
parents 9331f3d1 f9ee9e00
Loading
Loading
Loading
Loading
Loading
+54 −0
Original line number Diff line number Diff line
@@ -7,6 +7,8 @@ import unittest
import random
import os
from datetime import datetime
import requests
import urllib3

from selenium import webdriver
from selenium.webdriver.common.by import By
@@ -26,6 +28,11 @@ class MultipleTest(unittest.TestCase):

        print("\n2. [필수 입력] 테스트 대상 웹 (e.g., https://example.com:8443/): ")
        self.dc_address = input()
        if self.check_http_status(self.dc_address):
            pass
        else:
            print("EMS 접속이 원할하지 않습니다. 프로그램을 종료합니다")
            sys.exit(1)

        # A list is created to store multiple account configurations.
        self.account_configs = []
@@ -96,6 +103,53 @@ class MultipleTest(unittest.TestCase):
        os.makedirs(self.screenshots_folder, exist_ok=True)
        self.screenshot_base_dir = self.screenshots_folder

    def check_http_status(self, url: str, max_retry: int = 3, ignore_cert: bool = True) -> bool:
        """
        Checks the HTTP status of the given URL.
        Follows redirects, retries up to `max_retry` times if the final status is not 200,
        and optionally ignores SSL certificate validation.

        Args:
            url (str): The target URL to check.
            max_retry (int): Maximum number of retries if status is not 200. Defaults to 3.
            ignore_cert (bool): If True, SSL certificate errors are ignored. Defaults to True.

        Returns:
            bool: True if the final HTTP status is 200, otherwise False.
        """

        # Disable SSL certificate warnings (optional)
        urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

        for attempt in range(1, max_retry + 1):
            try:
                # HEAD request first
                response = requests.head(
                    url, allow_redirects=True, timeout=5, verify=not ignore_cert
                )

                # Some servers may not support HEAD properly
                if response.status_code >= 400 or response.status_code == 405:
                    response = requests.get(
                        url, allow_redirects=True, timeout=5, verify=not ignore_cert
                    )

                # print(f"Attempt {attempt}: {response.status_code} ({response.url})")

                # ✅ Success only if final status == 200
                if response.status_code == 200:
                    return True

            except requests.exceptions.RequestException as e:
                print(f"Attempt {attempt}: Error - {e}")

            # Wait a bit before retrying
            if attempt < max_retry:
                time.sleep(1)

        # ❌ All retries failed or never got 200
        return False

    def setUp(self):
        self._get_user_inputs()
        # Initialize a list to hold driver instances for each thread
+2 −1
Original line number Diff line number Diff line
selenium==4.36.0
urllib3==2.5.0
requests==2.32.5
 No newline at end of file