提交 6928f116 authored 作者: 彭甘宇's avatar 彭甘宇

新增测试用例和基础函数

- 新增类型标签、设备管理、协议管理、数据类型、联动动作等模块的测试用例文件- 在 base.py 中添加了进入各个管理页面的函数
- 增加了读取 CSV 文件数据的函数
- 优化了日志记录和错误处理
上级 dcc998fe
import sys
import os
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', '..', '..')))
from 运维集控.项目测试.运维标准版.lib.base import *
def suite_setup():
wd = GSTORE['wd']
# user_login("admin@pgy", "ub@123456", "csba")
# enter_system()
# enter_manage()
enter_typetag()
# def suite_teardown():
# INFO('进行清除操作')
# wd = GSTORE['wd']
# wd.quit()
#
import sys
import os
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', '..', '..')))
from 运维集控.项目测试.运维标准版.lib.base import *
def suite_setup():
wd = GSTORE['wd']
# user_login("admin@pgy", "ub@123456", "csba")
# enter_system()
# enter_manage()
enter_devices_manage()
# def suite_teardown():
# INFO('进行清除操作')
# wd = GSTORE['wd']
# wd.quit()
#
import sys
import os
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', '..', '..')))
from 运维集控.项目测试.运维标准版.lib.base import *
def suite_setup():
wd = GSTORE['wd']
# user_login("admin@pgy", "ub@123456", "csba")
# enter_system()
# enter_manage()
enter_protocol_manage()
# def suite_teardown():
# INFO('进行清除操作')
# wd = GSTORE['wd']
# wd.quit()
#
import sys
import os
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', '..', '..')))
from 运维集控.项目测试.运维标准版.lib.base import *
def suite_setup():
wd = GSTORE['wd']
# user_login("admin@pgy", "ub@123456", "csba")
# enter_system()
# enter_manage()
enter_datatype()
# def suite_teardown():
# INFO('进行清除操作')
# wd = GSTORE['wd']
# wd.quit()
#
import sys
import os
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', '..', '..')))
from 运维集控.项目测试.运维标准版.lib.base import *
def suite_setup():
wd = GSTORE['wd']
# user_login("admin@pgy", "ub@123456", "csba")
# enter_system()
# enter_manage()
enter_linkaction()
# def suite_teardown():
# INFO('进行清除操作')
# wd = GSTORE['wd']
# wd.quit()
#
......@@ -27,6 +27,7 @@ from selenium.webdriver.common.keys import Keys
from time import sleep
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
# 打开浏览器,忽略ssh警告
def open_browser():
INFO('打开默认浏览器')
# 更改显示屏分辨率为1920x1080
......@@ -43,6 +44,7 @@ def open_browser():
wd.maximize_window()
wd.implicitly_wait(10)
# 定义调整屏幕分辨率,仅内部环境跑定时任务需要使用。
def change_resolution(width, height):
# 获取当前显示器的设备上下文(Device Context, DC)
device = win32api.EnumDisplayDevices(None, 0)
......@@ -69,6 +71,7 @@ def change_resolution(width, height):
print("The requested resolution is already set.")
return True
# 用户进行登录
def user_login(username, password, captcha):
wd = GSTORE['wd']
INFO(f'输入登录账号: {username}')
......@@ -118,6 +121,7 @@ def run_login_tests(df):
except ValueError as e:
print(f"Invalid input at row {index}: {e}")
# 构建当前所在目录
def main():
# 获取当前脚本的目录
current_dir = os.path.dirname(os.path.abspath(__file__))
......@@ -131,6 +135,7 @@ def main():
except Exception as e:
print(f"An error occurred: {e}")
# 进入后台管理系统页面
def enter_system():
wd = GSTORE['wd']
if wd is None:
......@@ -146,6 +151,7 @@ def enter_system():
except (TimeoutException, ElementNotInteractableException) as error:
logging.error(f"Error clicking system settings button: {error}")
# 进入管理页面
def enter_manage():
wd = GSTORE['wd']
if wd is None:
......@@ -161,6 +167,7 @@ def enter_manage():
except (TimeoutException, ElementNotInteractableException) as error:
logging.error(f"Error clicking manage button: {error}")
# 进入用户管理页面
def enter_user_manage():
wd = GSTORE['wd']
if wd is None:
......@@ -176,6 +183,7 @@ def enter_user_manage():
except (TimeoutException, ElementNotInteractableException) as error:
logging.error(f"Error clicking manage button: {error}")
# 进入区域分组管理页面
def enter_areagroup_manage():
wd = GSTORE['wd']
if wd is None:
......@@ -191,6 +199,7 @@ def enter_areagroup_manage():
except (TimeoutException, ElementNotInteractableException) as error:
logging.error(f"Error clicking manage button: {error}")
# 进入区域类型页面
def enter_areatype_manage():
wd = GSTORE['wd']
if wd is None:
......@@ -206,6 +215,7 @@ def enter_areatype_manage():
except (TimeoutException, ElementNotInteractableException) as error:
logging.error(f"Error clicking manage button: {error}")
# 进入区域功能页面
def enter_areafuntion_manage():
wd = GSTORE['wd']
if wd is None:
......@@ -221,6 +231,7 @@ def enter_areafuntion_manage():
except (TimeoutException, ElementNotInteractableException) as error:
logging.error(f"Error clicking manage button: {error}")
# 进入区域管理页面
def enter_area_manage():
wd = GSTORE['wd']
if wd is None:
......@@ -236,6 +247,103 @@ def enter_area_manage():
except (TimeoutException, ElementNotInteractableException) as error:
logging.error(f"Error clicking manage button: {error}")
# 进入类型标签页面
def enter_typetag():
wd = GSTORE['wd']
if wd is None:
raise ValueError("WebDriver is not initialized")
logging.info('点击类型标签按钮')
try:
enter_type_tag = WebDriverWait(wd, 10).until(
EC.element_to_be_clickable((By.XPATH, "//li[contains(text(),'类型标签')]"))
)
enter_type_tag.click()
logging.info('打开类型标签页面')
except (TimeoutException, ElementNotInteractableException) as error:
logging.error(f"Error clicking manage button: {error}")
# 进入设备管理页面
def enter_devices_manage():
wd = GSTORE['wd']
if wd is None:
raise ValueError("WebDriver is not initialized")
logging.info('点击设备管理按钮')
try:
enter_devices_mag = WebDriverWait(wd, 10).until(
EC.element_to_be_clickable((By.XPATH, "//li[contains(text(),'设备管理')]"))
)
enter_devices_mag.click()
logging.info('打开设备管理页面')
except (TimeoutException, ElementNotInteractableException) as error:
logging.error(f"Error clicking manage button: {error}")
# 进入协议管理页面
def enter_protocol_manage():
wd = GSTORE['wd']
if wd is None:
raise ValueError("WebDriver is not initialized")
logging.info('点击协议管理按钮')
try:
enter_protocol_mag = WebDriverWait(wd, 10).until(
EC.element_to_be_clickable((By.XPATH, "//li[contains(text(),'协议管理')]"))
)
enter_protocol_mag.click()
logging.info('打开协议管理页面')
except (TimeoutException, ElementNotInteractableException) as error:
logging.error(f"Error clicking manage button: {error}")
# 进入数据类型页面
def enter_datatype():
wd = GSTORE['wd']
if wd is None:
raise ValueError("WebDriver is not initialized")
logging.info('点击数据类型按钮')
try:
enter_data_type = WebDriverWait(wd, 10).until(
EC.element_to_be_clickable((By.XPATH, "//li[contains(text(),'数据类型')]"))
)
enter_data_type.click()
logging.info('打开数据类型页面')
except (TimeoutException, ElementNotInteractableException) as error:
logging.error(f"Error clicking manage button: {error}")
# 进入联动动作页面
def enter_linkaction():
wd = GSTORE['wd']
if wd is None:
raise ValueError("WebDriver is not initialized")
logging.info('点击联动动作按钮')
try:
enter_link_action = WebDriverWait(wd, 10).until(
EC.element_to_be_clickable((By.XPATH, "//li[contains(text(),'联动动作')]"))
)
enter_link_action.click()
logging.info('打开联动动作页面')
except (TimeoutException, ElementNotInteractableException) as error:
logging.error(f"Error clicking manage button: {error}")
# 进入模式管理页面
def enter_model_manage():
wd = GSTORE['wd']
if wd is None:
raise ValueError("WebDriver is not initialized")
logging.info('点击模式管理按钮')
try:
enter_model_mag = WebDriverWait(wd, 10).until(
EC.element_to_be_clickable((By.XPATH, "//li[contains(text(),'模式管理')]"))
)
enter_model_mag.click()
logging.info('打开模式管理页面')
except (TimeoutException, ElementNotInteractableException) as error:
logging.error(f"Error clicking manage button: {error}")
# 定义钉钉接口函数
def dingding_send_message(test_report_url, title, mobile, ding_type):
"""
发送钉钉机器人消息
......@@ -311,7 +419,7 @@ def dingding_send_message(test_report_url, title, mobile, ding_type):
except requests.exceptions.RequestException as e:
logging.error(f'请求异常: {e}')
# 调用框架自带生成的测试报告
def get_latest_report_file(report_dir, base_url):
"""
获取指定目录下最新的HTML报告文件,并返回带有基础URL的完整路径。
......@@ -357,6 +465,7 @@ def get_latest_report_file(report_dir, base_url):
# 返回完整的URL
return full_url
# 定义发送钉钉报告函数
def get_reportfile_send_dingding(report_title, report_url_prefix, ding_type):
try:
# 获取报告文件所在的目录
......@@ -398,6 +507,7 @@ def get_reportfile_send_dingding(report_title, report_url_prefix, ding_type):
# 无论是否成功,都记录测试结束的日志
logging.info("自动化测试完成。")
# 获取csv文件数据
def read_csv_data(csv_file_path):
"""
读取CSV文件中的数据,并将其转换为一个包含字典的列表,每个字典代表一行测试用例数据。
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论