提交 c875c935 authored 作者: 陈泽健's avatar 陈泽健

调整封装get_reportfile_send_dingding函数用来获取测试报告文件并拼接IP地址,并发送钉钉群消息。优化定时任务run_automat...

调整封装get_reportfile_send_dingding函数用来获取测试报告文件并拼接IP地址,并发送钉钉群消息。优化定时任务run_automation_test函数的调用处理,并增加对于的日志输出。补充定时任务执行的注解。调整元素定位的显示等待时间,避免因服务器的网络波动导致元素获取异常。
上级 88762ce2
This source diff could not be displayed because it is too large. You can view the blob instead.
import csv import csv
import glob import glob
import re import re
from trio import current_time import urllib
import requests
import json
import hmac
import hashlib
import base64
import psutil
import time
import subprocess
import logging
from webdriver_manager.chrome import ChromeDriverManager from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service as ChromeService from selenium.webdriver.chrome.service import Service as ChromeService
import psutil
from hytest import * from hytest import *
from selenium import webdriver from selenium import webdriver
from selenium.common import TimeoutException, NoSuchElementException, ElementNotInteractableException from selenium.common import TimeoutException, NoSuchElementException, ElementNotInteractableException
...@@ -12,20 +20,9 @@ from selenium.webdriver.common.by import By ...@@ -12,20 +20,9 @@ from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support import expected_conditions as EC
import urllib
import requests
import json
import hmac
import hashlib
import base64
from urllib.parse import urlencode from urllib.parse import urlencode
from datetime import datetime from datetime import datetime
import os
import sys
import schedule
import time
import subprocess
import logging
# 获取当前脚本的绝对路径 # 获取当前脚本的绝对路径
current_dir = os.path.dirname(os.path.abspath(__file__)) current_dir = os.path.dirname(os.path.abspath(__file__))
# 获取当前脚本的父目录 # 获取当前脚本的父目录
...@@ -34,20 +31,18 @@ logging.info(parent_dir) ...@@ -34,20 +31,18 @@ logging.info(parent_dir)
# 添加路径 # 添加路径
sys.path.append(current_dir) sys.path.append(current_dir)
# 配置日志记录器 # 配置日志记录器,仅输出到控制台
log_file = os.path.join(current_dir, 'automation_test.log')
logging.basicConfig( logging.basicConfig(
level=logging.DEBUG, level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - %(message)s', format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[ handlers=[
logging.FileHandler(log_file),
logging.StreamHandler() logging.StreamHandler()
] ]
) )
# 配置日志 # 配置日志
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') # logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
def browser_init(): def browser_init():
""" """
...@@ -63,6 +58,10 @@ def browser_init(): ...@@ -63,6 +58,10 @@ def browser_init():
options = webdriver.ChromeOptions() options = webdriver.ChromeOptions()
# 添加实验性选项,排除某些命令行开关以减少输出日志 # 添加实验性选项,排除某些命令行开关以减少输出日志
options.add_experimental_option('excludeSwitches', ['enable-Logging']) options.add_experimental_option('excludeSwitches', ['enable-Logging'])
# 忽略证书错误,允许在本地主机上运行时不安全
options.add_argument('--ignore-certificate-errors')
options.add_argument('--disable-blink-features=AutomationControlled')
options.add_argument('--allow-insecure-localhost')
# 使用webdriver_manager自动下载并管理chromedriver # 使用webdriver_manager自动下载并管理chromedriver
service = ChromeService(ChromeDriverManager().install()) service = ChromeService(ChromeDriverManager().install())
...@@ -75,49 +74,20 @@ def browser_init(): ...@@ -75,49 +74,20 @@ def browser_init():
# 定义目标登录页面的URL # 定义目标登录页面的URL
login_url = 'https://192.168.5.218/#/login/logindf' login_url = 'https://192.168.5.218/#/login/logindf'
login_ngrok_url = "https://nat.ubainsyun.com:11046" # login_ngrok_url = "https://nat.ubainsyun.com:11046"
# 请求WebDriver打开登录页面 # 请求WebDriver打开登录页面
wd.get(login_url) wd.get(login_url)
# 最大化浏览器窗口 # 最大化浏览器窗口
wd.maximize_window() wd.maximize_window()
# 将WebDriver实例存储在全局存储器中,以便后续使用 # 将WebDriver实例存储在全局存储器中,以便后续使用
GSTORE['wd'] = wd GSTORE['wd'] = wd
# 标记初始化过程完成
INFO("'----------' 浏览器初始化完成 '----------'") INFO("'----------' 浏览器初始化完成 '----------'")
except Exception as e: except Exception as e:
# 捕获并记录初始化过程中的任何异常 # 捕获并记录初始化过程中的任何异常
logging.error(f"浏览器初始化失败:{e}") logging.error(f"浏览器初始化失败:{e}")
def handle_ssl_warning():
"""
处理 SSL 证书警告。
该函数通过模拟用户操作,忽略浏览器中的 SSL 证书警告,使自动化流程能够继续进行。
它首先尝试点击“详细信息”按钮,然后点击“继续”链接以忽略警告。
"""
wd = GSTORE['wd']
try:
# 记录处理 SSL 证书警告的开始信息
INFO("'----------' 正在处理SSL证书警告 '----------'")
# 等待并点击“详细信息”按钮
safe_click((By.XPATH, '//*[@id="details-button"]'), wd)
# 等待并点击“继续”链接,以忽略 SSL 警告
safe_click((By.XPATH, '//*[@id="proceed-link"]'), wd)
# 等待页面加载完成
WebDriverWait(wd, 10).until(
EC.presence_of_element_located((By.TAG_NAME, 'body'))
)
# 记录处理 SSL 证书警告完成的信息
INFO("'----------' SSL证书警告处理完成 '----------'")
except Exception as e:
# 记录处理 SSL 证书警告过程中遇到的错误,并抛出异常
logging.error(f"处理 SSL 证书警告遇到错误: {e}")
raise
def admin_login(): def admin_login():
""" """
管理员登录函数。 管理员登录函数。
...@@ -128,7 +98,6 @@ def admin_login(): ...@@ -128,7 +98,6 @@ def admin_login():
# 打印用户名输入信息 # 打印用户名输入信息
INFO("输入用户名:admin@ZDH") INFO("输入用户名:admin@ZDH")
# 等待元素刷新
# 向用户名输入框发送用户名 # 向用户名输入框发送用户名
safe_send_keys((By.XPATH, "//input[@placeholder='请输入账号或手机号或邮箱号']"), 'admin@ZDH', wd) safe_send_keys((By.XPATH, "//input[@placeholder='请输入账号或手机号或邮箱号']"), 'admin@ZDH', wd)
...@@ -179,7 +148,7 @@ def safe_send_keys(element_locator, value, wd): ...@@ -179,7 +148,7 @@ def safe_send_keys(element_locator, value, wd):
""" """
try: try:
# 等待元素在指定时间内可见 # 等待元素在指定时间内可见
element = WebDriverWait(wd, 20).until(EC.visibility_of_element_located(element_locator)) element = WebDriverWait(wd, 60).until(EC.visibility_of_element_located(element_locator))
element.clear() # 清除元素的当前值 element.clear() # 清除元素的当前值
element.send_keys(value) # 向元素发送指定的键值 element.send_keys(value) # 向元素发送指定的键值
except TimeoutException: except TimeoutException:
...@@ -205,7 +174,7 @@ def safe_click(element_locator, wd): ...@@ -205,7 +174,7 @@ def safe_click(element_locator, wd):
""" """
try: try:
# Wait up to 20 seconds for the element to be visible # Wait up to 20 seconds for the element to be visible
element = WebDriverWait(wd, 20).until(EC.visibility_of_element_located(element_locator)) element = WebDriverWait(wd, 60).until(EC.visibility_of_element_located(element_locator))
# Attempt to click the element # Attempt to click the element
element.click() element.click()
except TimeoutException: except TimeoutException:
...@@ -235,7 +204,7 @@ def input_clear(element_locator, wd): ...@@ -235,7 +204,7 @@ def input_clear(element_locator, wd):
""" """
try: try:
# 等待元素可见,并在可见后清空输入框。 # 等待元素可见,并在可见后清空输入框。
input_element = WebDriverWait(wd, 20).until(EC.visibility_of_element_located(element_locator)) input_element = WebDriverWait(wd, 60).until(EC.visibility_of_element_located(element_locator))
input_element.clear() input_element.clear()
except TimeoutException: except TimeoutException:
# 如果元素在20秒内不可见,打印超时异常消息。 # 如果元素在20秒内不可见,打印超时异常消息。
...@@ -265,7 +234,7 @@ def send_keyboard(element_locator, wd): ...@@ -265,7 +234,7 @@ def send_keyboard(element_locator, wd):
""" """
try: try:
# 等待元素可见,并在可见后向其发送RETURN键点击事件。 # 等待元素可见,并在可见后向其发送RETURN键点击事件。
element = WebDriverWait(wd, 20).until(EC.visibility_of_element_located(element_locator)) element = WebDriverWait(wd, 60).until(EC.visibility_of_element_located(element_locator))
element.send_keys(Keys.RETURN) element.send_keys(Keys.RETURN)
except TimeoutException: except TimeoutException:
# 如果元素在指定时间内不可见,打印超时错误消息。 # 如果元素在指定时间内不可见,打印超时错误消息。
...@@ -292,7 +261,7 @@ def get_notify_text(wd,element_locator,module_name,function_name,name): ...@@ -292,7 +261,7 @@ def get_notify_text(wd,element_locator,module_name,function_name,name):
""" """
try: try:
# 获取提示信息 # 获取提示信息
notify_text = WebDriverWait(wd, 20).until( notify_text = WebDriverWait(wd, 60).until(
EC.presence_of_element_located(element_locator) EC.presence_of_element_located(element_locator)
).text ).text
# 屏幕截图 # 屏幕截图
...@@ -318,7 +287,7 @@ def elment_get_text(element_locator, wd): ...@@ -318,7 +287,7 @@ def elment_get_text(element_locator, wd):
""" """
try: try:
# 使用WebDriverWait等待页面元素在20秒内可见,并获取其文本。 # 使用WebDriverWait等待页面元素在20秒内可见,并获取其文本。
element_text = WebDriverWait(wd, 20).until(EC.visibility_of_element_located(element_locator)).text element_text = WebDriverWait(wd, 60).until(EC.visibility_of_element_located(element_locator)).text
return element_text return element_text
except TimeoutException: except TimeoutException:
# 如果超过20秒元素仍未可见,则捕获TimeoutException异常并打印错误信息。 # 如果超过20秒元素仍未可见,则捕获TimeoutException异常并打印错误信息。
...@@ -429,7 +398,7 @@ def is_valid_password(password): ...@@ -429,7 +398,7 @@ def is_valid_password(password):
return True return True
except Exception as e: except Exception as e:
print(f"An error occurred: {e}") logging.error(f"An error occurred: {e}")
return False return False
def browser_quit(): def browser_quit():
...@@ -445,6 +414,7 @@ def browser_quit(): ...@@ -445,6 +414,7 @@ def browser_quit():
# 调用浏览器驱动实例的quit方法,关闭浏览器并释放资源 # 调用浏览器驱动实例的quit方法,关闭浏览器并释放资源
wd.quit() wd.quit()
def get_latest_report_file(report_dir, base_url): def get_latest_report_file(report_dir, base_url):
""" """
获取指定目录下最新的HTML报告文件,并返回带有基础URL的完整路径。 获取指定目录下最新的HTML报告文件,并返回带有基础URL的完整路径。
...@@ -453,74 +423,56 @@ def get_latest_report_file(report_dir, base_url): ...@@ -453,74 +423,56 @@ def get_latest_report_file(report_dir, base_url):
:param base_url: 基础URL :param base_url: 基础URL
:return: 最新的HTML报告文件的完整URL,如果没有找到则返回None :return: 最新的HTML报告文件的完整URL,如果没有找到则返回None
""" """
report_files = glob.glob(os.path.join(report_dir, '*.html')) # 记录调用此函数的日志
logging.info("开始调用get_latest_report_file函数获取报告文件")
# 确保报告目录存在
if not os.path.exists(report_dir):
logging.error(f"报告目录 {report_dir} 不存在。")
return None
# 获取指定目录下所有符合模式的HTML报告文件
report_files = glob.glob(os.path.join(report_dir, 'report_*.html'))
# 打印找到的文件列表
logging.debug(f"找到的报告文件: {report_files}")
# 如果没有找到报告文件,记录警告信息并返回None
if not report_files: if not report_files:
logging.warning("No report files found in the directory.") logging.warning("在指定目录中没有找到报告文件。")
return None return None
# 找到最新修改的报告文件
latest_file = max(report_files, key=os.path.getmtime) latest_file = max(report_files, key=os.path.getmtime)
last_modified_time = datetime.fromtimestamp(os.path.getmtime(latest_file)).strftime('%Y-%m-%d %H:%M:%S')
logging.info(f"Latest report file: {latest_file}, Last modified: {last_modified_time}")
# 将文件路径转换为相对于基础URL的完整URL # 获取最新报告文件的最后修改时间
relative_path = os.path.relpath(latest_file, report_dir) last_modified_time = datetime.fromtimestamp(os.path.getmtime(latest_file)).strftime('%Y-%m-%d %H:%M:%S')
full_url = f"{base_url}/{relative_path}".replace("\\", "/") # 确保路径分隔符一致
return full_url
def run_automation_test(report_title, report_url_prefix, test_case):
logging.info("Starting automation test...")
command = [
'hytest',
'--report_title', report_title,
'--report_url_prefix', report_url_prefix,
'--test', test_case
]
logging.info(f"Running command: {' '.join(command)}")
try:
result = subprocess.run(command, capture_output=True, text=True, check=True)
logging.debug(f"Command stdout: {result.stdout}")
logging.debug(f"Command stderr: {result.stderr}")
# 获取最新的报告文件 # 记录最新报告文件的信息
report_dir = os.path.join(parent_dir, 'reports') logging.info(f"最新报告文件: {latest_file}, 最后修改时间: {last_modified_time}")
base_url = report_url_prefix
latest_report = get_latest_report_file(report_dir, base_url)
if latest_report: # 将文件路径转换为相对于基础URL的相对路径
logging.info(f"Latest report file URL: {latest_report}") relative_path = os.path.relpath(latest_file, report_dir)
# 调用钉钉发送消息接口进行推送测试报告链接
try:
logging.info("开始调用dingding消息通知函数")
dingding_send_message(latest_report, report_title, f"{report_title}定时任务执行完成", "13724387318")
logging.info("dingding_send_message function called successfully")
except Exception as e:
logging.error(f"dingding_send_message调用失败: {e}")
else:
logging.warning("No report files found to send.")
except subprocess.CalledProcessError as e: # 生成完整的URL
logging.error(f"Command failed with return code {e.returncode}: {e.output}") full_url = f"{base_url}/{relative_path}".replace("\\", "/")
except OSError as e:
logging.error(f"OS error occurred: {e}")
finally:
logging.info("Automation test completed.")
# 返回完整的URL
return full_url
def dingding_send_message(test_report_Url, title, text, mobile): def dingding_send_message(test_report_url, title, text, mobile):
""" """
发送钉钉机器人消息 发送钉钉机器人消息
:param text_report_Url: 测试报告链接 :param test_report_url: 测试报告链接
:param title: 消息标题 :param title: 消息标题
:param text: 消息内容 :param text: 消息内容
:param mobile: 需要@的手机号列表 :param mobile: 需要@的手机号列表
""" """
# 钉钉机器人的 Webhook URL 和密钥 (正式环境) # 记录调用此函数的日志
# webhook_url = 'https://oapi.dingtalk.com/robot/send?access_token=b0eea0bbf097ce3badb4c832d2cd0267a50486f395ec8beca6e2042102bb295b' logging.info("开始构建并发送钉钉机器人消息")
# secret = 'SEC928b11659c5fd6476cfa2042edbf56da876abf759289f7e4d3c671fb9a81bf43'
# 钉钉机器人的 Webhook URL 和密钥 (测试环境) # 钉钉机器人的 Webhook URL 和密钥
webhook_url = 'https://oapi.dingtalk.com/robot/send?access_token=7fbf40798cad98b1b5db55ff844ba376b1816e80c5777e6f47ae1d9165dacbb4' webhook_url = 'https://oapi.dingtalk.com/robot/send?access_token=7fbf40798cad98b1b5db55ff844ba376b1816e80c5777e6f47ae1d9165dacbb4'
secret = 'SEC610498ed6261ae2df1d071d0880aaa70abf5e67efe47f75a809c1f2314e0dbd6' secret = 'SEC610498ed6261ae2df1d071d0880aaa70abf5e67efe47f75a809c1f2314e0dbd6'
...@@ -540,8 +492,10 @@ def dingding_send_message(test_report_Url, title, text, mobile): ...@@ -540,8 +492,10 @@ def dingding_send_message(test_report_Url, title, text, mobile):
'timestamp': timestamp, 'timestamp': timestamp,
'sign': sign 'sign': sign
} }
encoded_params = urlencode(params) encoded_params = urllib.parse.urlencode(params)
final_webhook_url = f'https://oapi.dingtalk.com/robot/send?{encoded_params}' final_webhook_url = f'https://oapi.dingtalk.com/robot/send?{encoded_params}'
# 记录最终的 Webhook URL
logging.info(f"钉钉机器人Webhook URL: {final_webhook_url}") logging.info(f"钉钉机器人Webhook URL: {final_webhook_url}")
# 构建消息体 # 构建消息体
...@@ -550,11 +504,11 @@ def dingding_send_message(test_report_Url, title, text, mobile): ...@@ -550,11 +504,11 @@ def dingding_send_message(test_report_Url, title, text, mobile):
'msgtype': 'link', 'msgtype': 'link',
'link': { 'link': {
'title': title, 'title': title,
'messageUrl': test_report_Url, 'messageUrl': test_report_url,
'text': text 'text': text
}, },
"at": { "at": {
"atMobiles": [mobile], # 将手机号列表化 "atMobiles": [mobile],
"isAtAll": False "isAtAll": False
} }
} }
...@@ -562,6 +516,8 @@ def dingding_send_message(test_report_Url, title, text, mobile): ...@@ -562,6 +516,8 @@ def dingding_send_message(test_report_Url, title, text, mobile):
try: try:
# 发送 POST 请求 # 发送 POST 请求
response = requests.post(final_webhook_url, data=json.dumps(message), headers=headers) response = requests.post(final_webhook_url, data=json.dumps(message), headers=headers)
# 检查响应状态码
if response.status_code == 200: if response.status_code == 200:
logging.info('消息发送成功!') logging.info('消息发送成功!')
logging.info(f'响应内容: {response.text}') logging.info(f'响应内容: {response.text}')
...@@ -570,3 +526,89 @@ def dingding_send_message(test_report_Url, title, text, mobile): ...@@ -570,3 +526,89 @@ def dingding_send_message(test_report_Url, title, text, mobile):
logging.error(f'响应内容: {response.text}') logging.error(f'响应内容: {response.text}')
except requests.exceptions.RequestException as e: except requests.exceptions.RequestException as e:
logging.error(f'请求异常: {e}') logging.error(f'请求异常: {e}')
def run_automation_test(report_title, report_url_prefix, test_case):
"""
运行自动化测试并生成报告。
参数:
- report_title: 报告的标题
- report_url_prefix: 报告URL的前缀
- test_case: 测试用例脚本执行的标签名
- callback: 回调函数
"""
# 记录测试开始的日志
logging.info("开始自动化测试...")
# 构建运行测试命令
command = [
'hytest',
'--report_title', report_title,
'--report_url_prefix', report_url_prefix,
'--tag', test_case
]
# 记录将要执行的命令日志
logging.info(f"执行命令: {' '.join(command)}")
try:
# 执行测试命令并获取结果
result = subprocess.run(command, capture_output=True, text=True, check=True)
# 记录命令的标准输出和错误输出
logging.debug(f"命令标准输出: {result.stdout}")
logging.debug(f"命令错误输出: {result.stderr}")
except subprocess.CalledProcessError as e:
# 处理子进程调用失败的异常
logging.error(f"命令执行失败,返回码 {e.returncode}: {e.output}")
except OSError as e:
# 处理操作系统相关的异常
logging.error(f"发生操作系统错误: {e}")
finally:
# 无论测试是否成功,都记录测试结束的日志
logging.info("自动化测试完成。")
# 调用回调函数处理后续操作
get_reportfile_send_dingding("用户管理模块_测试报告", "http://192.168.1.166")
def get_reportfile_send_dingding(report_title, report_url_prefix):
try:
# 获取报告文件所在的目录
report_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..','reports')
# 获取基础URL
base_url = report_url_prefix
# 获取最新的报告文件
latest_report = get_latest_report_file(report_dir, base_url)
# 如果找到了最新的报告文件,则发送报告链接到钉钉
if latest_report:
logging.info(f"最新报告文件URL: {latest_report}")
try:
# 记录调用钉钉消息通知函数的日志
logging.info("开始调用钉钉消息通知函数")
# 调用钉钉发送消息接口进行推送测试报告链接
dingding_send_message(latest_report, report_title, f"{report_title}_定时任务执行完成", "13724387318")
# 记录钉钉消息通知函数调用成功的日志
logging.info("钉钉消息通知函数调用成功")
except Exception as e:
# 记录钉钉消息通知函数调用失败的日志
logging.error(f"钉钉消息通知函数调用失败: {e}")
else:
# 记录没有找到报告文件的日志
logging.warning("没有找到报告文件以发送。")
except subprocess.CalledProcessError as e:
# 处理子进程调用失败的异常
logging.error(f"命令执行失败,返回码 {e.returncode}: {e.output}")
except OSError as e:
# 处理操作系统相关的异常
logging.error(f"发生操作系统错误: {e}")
finally:
# 无论是否成功,都记录测试结束的日志
logging.info("自动化测试完成。")
\ No newline at end of file
...@@ -72,3 +72,9 @@ ...@@ -72,3 +72,9 @@
- 调试定时任务的问题,还需再进一步调试。 - 调试定时任务的问题,还需再进一步调试。
- 补充运维集控的MQTT底层方法与消息体构建。 - 补充运维集控的MQTT底层方法与消息体构建。
- 调试定时任务执行后钉钉消息没有发送的问题。将定时任务与测试报告文件获取封装成函数进行调用,方便后续维护管理。目前调试发现定时任务执行别的脚本时会出现异常问题,需要进一步排查。 - 调试定时任务执行后钉钉消息没有发送的问题。将定时任务与测试报告文件获取封装成函数进行调用,方便后续维护管理。目前调试发现定时任务执行别的脚本时会出现异常问题,需要进一步排查。
21. 2024-11-27
- 调试定时任务执行完成后没有发送钉钉群消息的问题,并优化SSL处理方式。
22. 2024-11-28
- 封装get_reportfile_send_dingding函数用来获取测试报告文件并拼接IP地址,并发送钉钉群消息。优化定时任务run_automation_test函数的调用处理,并增加对于的日志输出。
- 补充定时任务执行的注解。
- 调整元素定位的显示等待时间,避免因服务器的网络波动导致元素获取异常。
\ No newline at end of file
...@@ -18,8 +18,8 @@ except ModuleNotFoundError as e: ...@@ -18,8 +18,8 @@ except ModuleNotFoundError as e:
def suite_setup(): def suite_setup():
STEP(1, "初始化浏览器") STEP(1, "初始化浏览器")
browser_init() browser_init()
STEP(2, "处理SSL认证") # STEP(2, "处理SSL认证")
handle_ssl_warning() # handle_ssl_warning()
def suite_teardown(): def suite_teardown():
browser_quit() browser_quit()
\ No newline at end of file
from time import sleep from time import sleep
from hytest import * from 预定系统.cases.账号管理.用户管理.__st__ import *
# 获取当前脚本的绝对路径 # 获取当前脚本的绝对路径
current_dir = os.path.dirname(os.path.abspath(__file__)) current_dir = os.path.dirname(os.path.abspath(__file__))
# 构建预定系统的绝对路径 # 构建预定系统的绝对路径
...@@ -8,25 +9,42 @@ current_dir = os.path.dirname(os.path.abspath(__file__)) ...@@ -8,25 +9,42 @@ current_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.append(预定系统_path) sys.path.append(预定系统_path)
# 导入模块 # 导入模块
from 预定系统.Base.base import * from 预定系统.Base.base import *
account = 'admin@Test' # 获取当前脚本所在的目录
username = 'admin@Test' current_dir = os.path.dirname(os.path.abspath(__file__))
password = 'Ubains@54321'
new_password = 'Ubains@4321' # 构建CSV文件的绝对路径
phone = '17319004611' csv_file_path = os.path.join(current_dir, '../../../测试数据/账号管理/用户管理模块/用户管理主流程.csv')
email = '2919407801@qq.com'
# 配置日志记录器,仅输出到控制台
class Main_User_Manage_0001: logging.basicConfig(
tags = ['用户管理功能'] level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[
logging.StreamHandler()
]
)
class Main_User_Manage_000x:
# tags = ['用户管理功能']
""" """
执行指令: 执行指令:
1.cd 预定系统 1.cd 预定系统
2.hytest --report_title 用户主流程测试报告 --test Main_User_Manage_0001 2.hytest --report_title 用户主流程测试报告 --report_url_prefix http://192.168.1.166 --test 用户管理主流程_001
""" """
def teststeps(self): def teststeps(self):
"""
执行测试步骤以用户管理的主流程功能。
本函数根据参数添加用户,并使用新增的用户进行登录的提示信息是否与预期相符。
"""
login_url = 'https://192.168.5.218/#/login/logindf'
# 初始化通知文本为空字符串 # 初始化通知文本为空字符串
notify_text = "" notify_text = ""
# 从全局存储中获取webdriver实例 # 从全局存储中获取webdriver实例
wd = GSTORE['wd'] wd = GSTORE['wd']
# 从self.para中解构出用户名、密码、验证码和检查文本
name = self.name
account, username, password, new_password, phone, email = self.para
STEP(1, "点击【新增】按钮") STEP(1, "点击【新增】按钮")
safe_click((By.XPATH, "//span[contains(text(),'添 加')]"), wd) safe_click((By.XPATH, "//span[contains(text(),'添 加')]"), wd)
...@@ -105,12 +123,28 @@ class Main_User_Manage_0001: ...@@ -105,12 +123,28 @@ class Main_User_Manage_0001:
safe_send_keys((By.XPATH, "//input[@placeholder='请输入账号或手机号或邮箱号']"),account,wd) safe_send_keys((By.XPATH, "//input[@placeholder='请输入账号或手机号或邮箱号']"),account,wd)
safe_send_keys((By.XPATH, "//input[@placeholder='请输入密码']"),new_password,wd) safe_send_keys((By.XPATH, "//input[@placeholder='请输入密码']"),new_password,wd)
safe_send_keys((By.XPATH, "//input[@placeholder='请输入图形验证码']"),'csba',wd) safe_send_keys((By.XPATH, "//input[@placeholder='请输入图形验证码']"),'csba',wd)
INFO("点击登录按钮")
sleep(1)
safe_click((By.XPATH, "//input[@value='登 录']"),wd) safe_click((By.XPATH, "//input[@value='登 录']"),wd)
sleep(2) sleep(2)
INFO("获取登录信息")
notify_text = elment_get_text((By.XPATH, "//span[contains(text(),'欢迎 自动化测试公司')]"),wd) notify_text = elment_get_text((By.XPATH, "//span[contains(text(),'欢迎 自动化测试公司')]"),wd)
# 检查点:验证提示信息是否与预期相符 # 检查点:验证提示信息是否与预期相符
INFO(f"登录系统提示:{notify_text}") INFO(f"登录系统提示:{notify_text}")
CHECK_POINT('登录成功校验', notify_text == "欢迎 自动化测试公司") CHECK_POINT('登录成功校验', notify_text == "欢迎 自动化测试公司")
SELENIUM_LOG_SCREEN(wd,"50%","User_Manage","User_Main","用户管理主流程-用户登录") SELENIUM_LOG_SCREEN(wd,"50%","User_Manage","User_Main","用户管理主流程-用户登录")
# 清除浏览器,再重新打开浏览器
wd.get(login_url)
# 最大化浏览器窗口
wd.maximize_window()
admin_login()
enter_the_backend()
INFO("打开账号管理下拉菜单")
safe_click((By.XPATH, "//span[@class='aside_menu menu_account']"), wd)
INFO("进入用户管理模块")
safe_click((By.XPATH, "//li[contains(text(),'用户管理')]"), wd)
\ No newline at end of file
...@@ -13,6 +13,7 @@ except ModuleNotFoundError as e: ...@@ -13,6 +13,7 @@ except ModuleNotFoundError as e:
print(f"ModuleNotFoundError: {e}") print(f"ModuleNotFoundError: {e}")
print("尝试使用绝对路径导入") print("尝试使用绝对路径导入")
from 预定系统.Base.base import * from 预定系统.Base.base import *
from 预定系统.cases.账号管理.用户管理.__st__ import *
# 获取当前脚本所在的目录 # 获取当前脚本所在的目录
current_dir = os.path.dirname(os.path.abspath(__file__)) current_dir = os.path.dirname(os.path.abspath(__file__))
...@@ -20,6 +21,16 @@ current_dir = os.path.dirname(os.path.abspath(__file__)) ...@@ -20,6 +21,16 @@ current_dir = os.path.dirname(os.path.abspath(__file__))
# 构建CSV文件的绝对路径 # 构建CSV文件的绝对路径
csv_file_path = os.path.join(current_dir, '../../../测试数据/账号管理/用户管理模块/用户修改密码.csv') csv_file_path = os.path.join(current_dir, '../../../测试数据/账号管理/用户管理模块/用户修改密码.csv')
# 配置日志记录器,仅输出到控制台
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[
logging.StreamHandler()
]
)
class User_Chanage_Pwd_000x: class User_Chanage_Pwd_000x:
tags = ['用户管理功能'] tags = ['用户管理功能']
""" """
...@@ -34,6 +45,7 @@ class User_Chanage_Pwd_000x: ...@@ -34,6 +45,7 @@ class User_Chanage_Pwd_000x:
执行测试步骤以用户新增功能。 执行测试步骤以用户新增功能。
本函数根据参数输入账号、用户名、密码、确认密码、部门、性别、手机号和邮箱,并检查新增后的提示信息是否与预期相符。 本函数根据参数输入账号、用户名、密码、确认密码、部门、性别、手机号和邮箱,并检查新增后的提示信息是否与预期相符。
""" """
login_url = 'https://192.168.5.218/#/login/logindf'
# 初始化通知文本为空字符串 # 初始化通知文本为空字符串
notify_text = "" notify_text = ""
# 从全局存储中获取webdriver实例 # 从全局存储中获取webdriver实例
...@@ -73,7 +85,7 @@ class User_Chanage_Pwd_000x: ...@@ -73,7 +85,7 @@ class User_Chanage_Pwd_000x:
STEP(4, '点击确定按钮') STEP(4, '点击确定按钮')
INFO('点击确定按钮') INFO('点击确定按钮')
safe_click((By.XPATH, safe_click((By.XPATH,
"//body/div[@class='el-dialog__wrapper']/div[@aria-label='修改密码']/div[@class='el-dialog__footer']/span[@class='dialog-footer']/button[@type='button']/span[1]"), "//body/div[@class='el-dialog__wrapper']/div[@aria-label='修改密码']/div[@class='el-dialog__footer']/span[@class='dialog-footer']/button[1]"),
wd) wd)
sleep(2) sleep(2)
STEP(5, '检查提示信息') STEP(5, '检查提示信息')
...@@ -102,3 +114,17 @@ class User_Chanage_Pwd_000x: ...@@ -102,3 +114,17 @@ class User_Chanage_Pwd_000x:
f'{name}检查提示信息') f'{name}检查提示信息')
INFO(f'校验修改密码提示信息:{notify_text}') INFO(f'校验修改密码提示信息:{notify_text}')
CHECK_POINT('校验修改密码提示信息', notify_text == check_text) CHECK_POINT('校验修改密码提示信息', notify_text == check_text)
if name == '用户修改密码_022':
# 清除浏览器,再重新打开浏览器
wd.get(login_url)
# 最大化浏览器窗口
wd.maximize_window()
admin_login()
enter_the_backend()
INFO("打开账号管理下拉菜单")
safe_click((By.XPATH, "//span[@class='aside_menu menu_account']"), wd)
INFO("进入用户管理模块")
safe_click((By.XPATH, "//li[contains(text(),'用户管理')]"), wd)
\ No newline at end of file
...@@ -13,6 +13,7 @@ except ModuleNotFoundError as e: ...@@ -13,6 +13,7 @@ except ModuleNotFoundError as e:
print(f"ModuleNotFoundError: {e}") print(f"ModuleNotFoundError: {e}")
print("尝试使用绝对路径导入") print("尝试使用绝对路径导入")
from 预定系统.Base.base import * from 预定系统.Base.base import *
from 预定系统.cases.账号管理.用户管理.__st__ import *
# 获取当前脚本所在的目录 # 获取当前脚本所在的目录
current_dir = os.path.dirname(os.path.abspath(__file__)) current_dir = os.path.dirname(os.path.abspath(__file__))
...@@ -20,6 +21,15 @@ current_dir = os.path.dirname(os.path.abspath(__file__)) ...@@ -20,6 +21,15 @@ current_dir = os.path.dirname(os.path.abspath(__file__))
# 构建CSV文件的绝对路径 # 构建CSV文件的绝对路径
csv_file_path = os.path.join(current_dir, '../../../测试数据/账号管理/用户管理模块/用户新增.csv') csv_file_path = os.path.join(current_dir, '../../../测试数据/账号管理/用户管理模块/用户新增.csv')
# 配置日志记录器,仅输出到控制台
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[
logging.StreamHandler()
]
)
class Add_User_000x: class Add_User_000x:
tags = ['用户管理功能'] tags = ['用户管理功能']
""" """
...@@ -34,6 +44,7 @@ class Add_User_000x: ...@@ -34,6 +44,7 @@ class Add_User_000x:
执行测试步骤以用户新增功能。 执行测试步骤以用户新增功能。
本函数根据参数输入账号、用户名、密码、确认密码、部门、性别、手机号和邮箱,并检查新增后的提示信息是否与预期相符。 本函数根据参数输入账号、用户名、密码、确认密码、部门、性别、手机号和邮箱,并检查新增后的提示信息是否与预期相符。
""" """
login_url = 'https://192.168.5.218/#/login/logindf'
# 初始化通知文本为空字符串 # 初始化通知文本为空字符串
notify_text = "" notify_text = ""
# 从全局存储中获取webdriver实例 # 从全局存储中获取webdriver实例
...@@ -95,3 +106,17 @@ class Add_User_000x: ...@@ -95,3 +106,17 @@ class Add_User_000x:
if check_text == '添加成功': if check_text == '添加成功':
safe_click((By.XPATH, "//span[contains(text(),'添 加')]"), wd) safe_click((By.XPATH, "//span[contains(text(),'添 加')]"), wd)
sleep(1) sleep(1)
if name == '用户新增_048':
# 清除浏览器,再重新打开浏览器
wd.get(login_url)
# 最大化浏览器窗口
wd.maximize_window()
admin_login()
enter_the_backend()
INFO("打开账号管理下拉菜单")
safe_click((By.XPATH, "//span[@class='aside_menu menu_account']"), wd)
INFO("进入用户管理模块")
safe_click((By.XPATH, "//li[contains(text(),'用户管理')]"), wd)
\ No newline at end of file
import csv import csv
from time import sleep from time import sleep
from hytest import * from hytest import *
# 获取当前脚本的绝对路径 # 获取当前脚本的绝对路径
current_dir = os.path.dirname(os.path.abspath(__file__)) current_dir = os.path.dirname(os.path.abspath(__file__))
# 构建预定系统的绝对路径 # 构建预定系统的绝对路径
...@@ -10,6 +9,7 @@ current_dir = os.path.dirname(os.path.abspath(__file__)) ...@@ -10,6 +9,7 @@ current_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.append(预定系统_path) sys.path.append(预定系统_path)
# 导入模块 # 导入模块
from 预定系统.Base.base import * from 预定系统.Base.base import *
from 预定系统.cases.账号管理.用户管理.__st__ import *
# 获取当前脚本所在的目录 # 获取当前脚本所在的目录
current_dir = os.path.dirname(os.path.abspath(__file__)) current_dir = os.path.dirname(os.path.abspath(__file__))
...@@ -17,6 +17,15 @@ current_dir = os.path.dirname(os.path.abspath(__file__)) ...@@ -17,6 +17,15 @@ current_dir = os.path.dirname(os.path.abspath(__file__))
# 构建CSV文件的绝对路径 # 构建CSV文件的绝对路径
csv_file_path = os.path.join(current_dir, '../../../测试数据/账号管理/用户管理模块/用户查询.csv') csv_file_path = os.path.join(current_dir, '../../../测试数据/账号管理/用户管理模块/用户查询.csv')
# 配置日志记录器,仅输出到控制台
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[
logging.StreamHandler()
]
)
class Query_User_000x: class Query_User_000x:
tags = ['用户管理功能'] tags = ['用户管理功能']
""" """
...@@ -33,6 +42,7 @@ class Query_User_000x: ...@@ -33,6 +42,7 @@ class Query_User_000x:
query_text:查询文本 query_text:查询文本
query_type:查询类型 query_type:查询类型
""" """
login_url = 'https://192.168.5.218/#/login/logindf'
# 从全局存储中获取webdriver实例 # 从全局存储中获取webdriver实例
wd = GSTORE['wd'] wd = GSTORE['wd']
# 从self.para中解构出查询文本以及查询类型 # 从self.para中解构出查询文本以及查询类型
...@@ -94,3 +104,17 @@ class Query_User_000x: ...@@ -94,3 +104,17 @@ class Query_User_000x:
# 截屏显示 # 截屏显示
SELENIUM_LOG_SCREEN(wd, "50%", "User_Manage", "User_Query", f"{name}_检查搜索结果") SELENIUM_LOG_SCREEN(wd, "50%", "User_Manage", "User_Query", f"{name}_检查搜索结果")
CHECK_POINT("检查搜索结果", query_text in check_text) CHECK_POINT("检查搜索结果", query_text in check_text)
if name == '用户查询_044':
# 清除浏览器,再重新打开浏览器
wd.get(login_url)
# 最大化浏览器窗口
wd.maximize_window()
admin_login()
enter_the_backend()
INFO("打开账号管理下拉菜单")
safe_click((By.XPATH, "//span[@class='aside_menu menu_account']"), wd)
INFO("进入用户管理模块")
safe_click((By.XPATH, "//li[contains(text(),'用户管理')]"), wd)
\ No newline at end of file
...@@ -9,6 +9,7 @@ current_dir = os.path.dirname(os.path.abspath(__file__)) ...@@ -9,6 +9,7 @@ current_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.append(预定系统_path) sys.path.append(预定系统_path)
# 导入模块 # 导入模块
from 预定系统.Base.base import * from 预定系统.Base.base import *
from 预定系统.cases.账号管理.用户管理.__st__ import *
# 获取当前脚本所在的目录 # 获取当前脚本所在的目录
current_dir = os.path.dirname(os.path.abspath(__file__)) current_dir = os.path.dirname(os.path.abspath(__file__))
...@@ -16,6 +17,15 @@ current_dir = os.path.dirname(os.path.abspath(__file__)) ...@@ -16,6 +17,15 @@ current_dir = os.path.dirname(os.path.abspath(__file__))
# 构建CSV文件的绝对路径 # 构建CSV文件的绝对路径
csv_file_path = os.path.join(current_dir, '../../../测试数据/账号管理/用户管理模块/用户删除.csv') csv_file_path = os.path.join(current_dir, '../../../测试数据/账号管理/用户管理模块/用户删除.csv')
# 配置日志记录器,仅输出到控制台
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[
logging.StreamHandler()
]
)
class Delete_User_000x: class Delete_User_000x:
tags = ['用户管理功能'] tags = ['用户管理功能']
""" """
...@@ -30,6 +40,7 @@ class Delete_User_000x: ...@@ -30,6 +40,7 @@ class Delete_User_000x:
执行测试步骤以用户删除功能。 执行测试步骤以用户删除功能。
本函数根据参数输入账号,并检查删除后的数据是否减少。 本函数根据参数输入账号,并检查删除后的数据是否减少。
""" """
login_url = 'https://192.168.5.218/#/login/logindf'
notify_text = "" notify_text = ""
# 从全局存储中获取webdriver实例 # 从全局存储中获取webdriver实例
wd = GSTORE['wd'] wd = GSTORE['wd']
...@@ -79,3 +90,17 @@ class Delete_User_000x: ...@@ -79,3 +90,17 @@ class Delete_User_000x:
sleep(2) sleep(2)
#屏幕截图 #屏幕截图
SELENIUM_LOG_SCREEN(wd,"50%","User_Manage","User_Delete",f"{name}_查看删除结果") SELENIUM_LOG_SCREEN(wd,"50%","User_Manage","User_Delete",f"{name}_查看删除结果")
if name == "用户删除_012":
# 清除浏览器,再重新打开浏览器
wd.get(login_url)
# 最大化浏览器窗口
wd.maximize_window()
admin_login()
enter_the_backend()
INFO("打开账号管理下拉菜单")
safe_click((By.XPATH, "//span[@class='aside_menu menu_account']"), wd)
INFO("进入用户管理模块")
safe_click((By.XPATH, "//li[contains(text(),'用户管理')]"), wd)
\ No newline at end of file
...@@ -13,6 +13,7 @@ except ModuleNotFoundError as e: ...@@ -13,6 +13,7 @@ except ModuleNotFoundError as e:
print(f"ModuleNotFoundError: {e}") print(f"ModuleNotFoundError: {e}")
print("尝试使用绝对路径导入") print("尝试使用绝对路径导入")
from 预定系统.Base.base import * from 预定系统.Base.base import *
from 预定系统.cases.账号管理.用户管理.__st__ import *
# 获取当前脚本所在的目录 # 获取当前脚本所在的目录
current_dir = os.path.dirname(os.path.abspath(__file__)) current_dir = os.path.dirname(os.path.abspath(__file__))
...@@ -20,6 +21,15 @@ current_dir = os.path.dirname(os.path.abspath(__file__)) ...@@ -20,6 +21,15 @@ current_dir = os.path.dirname(os.path.abspath(__file__))
# 构建CSV文件的绝对路径 # 构建CSV文件的绝对路径
csv_file_path = os.path.join(current_dir, '../../../测试数据/账号管理/用户管理模块/用户状态设置.csv') csv_file_path = os.path.join(current_dir, '../../../测试数据/账号管理/用户管理模块/用户状态设置.csv')
# 配置日志记录器,仅输出到控制台
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[
logging.StreamHandler()
]
)
class User_Status_000x: class User_Status_000x:
tags = ['用户管理功能'] tags = ['用户管理功能']
""" """
...@@ -31,9 +41,10 @@ class User_Status_000x: ...@@ -31,9 +41,10 @@ class User_Status_000x:
def teststeps(self): def teststeps(self):
""" """
执行测试步骤以用户新增功能。 执行测试步骤以用户状态设置功能。
本函数根据参数输入账号、用户名、密码、确认密码、部门、性别、手机号和邮箱,并检查新增后的提示信息是否与预期相符。 本函数根据参数选择用户进行【启用】与【停用】操作,并检查停用、启用后登录系统的提示信息是否与预期相符。
""" """
login_url = 'https://192.168.5.218/#/login/logindf'
# 初始化通知文本为空字符串 # 初始化通知文本为空字符串
notify_text = "" notify_text = ""
# 从全局存储中获取webdriver实例 # 从全局存储中获取webdriver实例
...@@ -114,7 +125,23 @@ class User_Status_000x: ...@@ -114,7 +125,23 @@ class User_Status_000x:
safe_send_keys((By.XPATH, "//input[@placeholder='请输入密码']"), 'Ubains@4321', wd) safe_send_keys((By.XPATH, "//input[@placeholder='请输入密码']"), 'Ubains@4321', wd)
safe_send_keys((By.XPATH, "//input[@placeholder='请输入图形验证码']"), 'csba', wd) safe_send_keys((By.XPATH, "//input[@placeholder='请输入图形验证码']"), 'csba', wd)
safe_click((By.XPATH, "//input[@value='登 录']"), wd) safe_click((By.XPATH, "//input[@value='登 录']"), wd)
sleep(2) sleep(4)
notify_text = elment_get_text((By.XPATH, "//span[contains(text(),'欢迎 自动化测试公司')]"), wd) notify_text = elment_get_text((By.XPATH, f"//span[normalize-space()='{username}']"), wd)
INFO(f'校验登录提示信息:{notify_text}') INFO(f'校验登录提示信息:{notify_text}')
CHECK_POINT('校验登录提示信息', notify_text == '欢迎 自动化测试公司') CHECK_POINT('校验登录提示信息', username in notify_text)
\ No newline at end of file sleep(2)
if name == '用户状态设置_004':
# 清除浏览器,再重新打开浏览器
wd.get(login_url)
# 最大化浏览器窗口
wd.maximize_window()
admin_login()
enter_the_backend()
wd.refresh()
INFO("打开账号管理下拉菜单")
safe_click((By.XPATH, "//span[@class='aside_menu menu_account']"), wd)
INFO("进入用户管理模块")
safe_click((By.XPATH, "//li[contains(text(),'用户管理')]"), wd)
\ No newline at end of file
...@@ -13,6 +13,7 @@ except ModuleNotFoundError as e: ...@@ -13,6 +13,7 @@ except ModuleNotFoundError as e:
print(f"ModuleNotFoundError: {e}") print(f"ModuleNotFoundError: {e}")
print("尝试使用绝对路径导入") print("尝试使用绝对路径导入")
from 预定系统.Base.base import * from 预定系统.Base.base import *
from 预定系统.cases.账号管理.用户管理.__st__ import *
# 获取当前脚本所在的目录 # 获取当前脚本所在的目录
current_dir = os.path.dirname(os.path.abspath(__file__)) current_dir = os.path.dirname(os.path.abspath(__file__))
...@@ -20,6 +21,15 @@ current_dir = os.path.dirname(os.path.abspath(__file__)) ...@@ -20,6 +21,15 @@ current_dir = os.path.dirname(os.path.abspath(__file__))
# 构建CSV文件的绝对路径 # 构建CSV文件的绝对路径
csv_file_path = os.path.join(current_dir, '../../../测试数据/账号管理/用户管理模块/用户编辑.csv') csv_file_path = os.path.join(current_dir, '../../../测试数据/账号管理/用户管理模块/用户编辑.csv')
# 配置日志记录器,仅输出到控制台
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[
logging.StreamHandler()
]
)
class User_Edit_000x: class User_Edit_000x:
tags = ['用户管理功能'] tags = ['用户管理功能']
""" """
...@@ -34,6 +44,7 @@ class User_Edit_000x: ...@@ -34,6 +44,7 @@ class User_Edit_000x:
执行测试步骤以用户新增功能。 执行测试步骤以用户新增功能。
本函数根据参数输入账号、用户名、密码、确认密码、部门、性别、手机号和邮箱,并检查新增后的提示信息是否与预期相符。 本函数根据参数输入账号、用户名、密码、确认密码、部门、性别、手机号和邮箱,并检查新增后的提示信息是否与预期相符。
""" """
login_url = 'https://192.168.5.218/#/login/logindf'
# 初始化通知文本为空字符串 # 初始化通知文本为空字符串
notify_text = "" notify_text = ""
# 从全局存储中获取webdriver实例 # 从全局存储中获取webdriver实例
...@@ -55,7 +66,7 @@ class User_Edit_000x: ...@@ -55,7 +66,7 @@ class User_Edit_000x:
notify_text = elment_get_text((By.XPATH, "//span[contains(text(),'编辑用户')]"), wd) notify_text = elment_get_text((By.XPATH, "//span[contains(text(),'编辑用户')]"), wd)
INFO(f'校验编辑界面UI:{notify_text}') INFO(f'校验编辑界面UI:{notify_text}')
CHECK_POINT('校验编辑界面', "编辑用户" in notify_text) CHECK_POINT('校验编辑界面', "编辑用户" in notify_text)
sleep(1) sleep(2)
# 执行输入用户信息的步骤 # 执行输入用户信息的步骤
STEP(2, f'输入用户名:{new_username}') STEP(2, f'输入用户名:{new_username}')
...@@ -64,11 +75,12 @@ class User_Edit_000x: ...@@ -64,11 +75,12 @@ class User_Edit_000x:
safe_send_keys((By.XPATH, "//input[@placeholder='用户名']"), new_username, wd) safe_send_keys((By.XPATH, "//input[@placeholder='用户名']"), new_username, wd)
# 清除下拉框数据 # 清除下拉框数据
if name != '用户编辑_001': # if name != '用户编辑_001':
safe_click((By.XPATH, "//i[@class='el-tag__close el-icon-close']"), wd) safe_click((By.XPATH, "//i[@class='el-tag__close el-icon-close']"), wd)
sleep(2)
# 点击部门下拉框 # 点击部门下拉框
safe_click((By.XPATH, "//div[@class='el-input el-input--suffix']//input[@placeholder='请选择']"), wd) safe_click((By.XPATH, "//div[@class='el-input el-input--suffix']//input[@placeholder='请选择']"), wd)
sleep(2)
# 选择部门 # 选择部门
safe_click((By.XPATH, "/html[1]/body[1]/div[4]/div[1]/div[1]/div[1]/ul[1]/li[1]/label[1]/span[1]/span[1]"), wd) safe_click((By.XPATH, "/html[1]/body[1]/div[4]/div[1]/div[1]/div[1]/ul[1]/li[1]/label[1]/span[1]/span[1]"), wd)
...@@ -86,7 +98,22 @@ class User_Edit_000x: ...@@ -86,7 +98,22 @@ class User_Edit_000x:
safe_click((By.XPATH, "//div[@aria-label='编辑用户']//span[contains(text(),'确定')]"), wd) safe_click((By.XPATH, "//div[@aria-label='编辑用户']//span[contains(text(),'确定')]"), wd)
# 检查操作后的提示信息 # 检查操作后的提示信息
sleep(2)
STEP(4, '检查提示信息') STEP(4, '检查提示信息')
notify_text = get_notify_text(wd, (By.XPATH,"//p[@class='el-message__content']"), 'User_Manage', 'User_Chanage_Pwd', notify_text = get_notify_text(wd, (By.XPATH,"//p[@class='el-message__content']"), 'User_Manage', 'User_Chanage_Pwd',
f'{name}检查提示信息') f'{name}检查提示信息')
CHECK_POINT('校验编辑用户提示信息', notify_text == check_text) CHECK_POINT('校验编辑用户提示信息', notify_text == check_text)
# if name == '用户编辑_018':
# # 清除浏览器,再重新打开浏览器
# wd.get(login_url)
# # 最大化浏览器窗口
# wd.maximize_window()
# admin_login()
# enter_the_backend()
#
# INFO("打开账号管理下拉菜单")
# safe_click((By.XPATH, "//span[@class='aside_menu menu_account']"), wd)
#
# INFO("进入用户管理模块")
# safe_click((By.XPATH, "//li[contains(text(),'用户管理')]"), wd)
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
import schedule
from Base.base import * from Base.base import *
# 配置日志记录器,仅输出到控制台
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[
logging.StreamHandler()
]
)
"""
执行指令:
打开终端1:
1.cd 预定系统
2.python ./定时执行功能测试.py
打开终端2:
1.python -m http.server 80 --directory reports (可以让同网段下的电脑通过使用测试主机的IP地址+测试报告文件进行访问查看)
"""
# 每天凌晨 0 点执行任务 # 每天凌晨 0 点执行任务
schedule.every().day.at("21:18").do(run_automation_test, report_title="账号密码登录模块_测试报告", report_url_prefix="http://192.168.1.166", test_case="登录_0**") schedule.every().day.at("09:30").do(run_automation_test, report_title="用户管理模块_测试报告", report_url_prefix="http://192.168.1.166", test_case="用户管理功能")
# schedule.every().day.at("21:14").do(run_automation_test, report_title="用户管理模块_主流程_测试报告", report_url_prefix="http://192.168.1.166", test_case="Main_User_Manage_0001")
try: try:
# 无限循环,持续检查并执行计划任务
while True: while True:
schedule.run_pending() schedule.run_pending() # 检查并执行所有待处理的任务
time.sleep(5) time.sleep(1) # 每秒检查一次
except KeyboardInterrupt: except KeyboardInterrupt:
# 捕获用户中断信号 (Ctrl+C)
logging.info("Scheduler interrupted by user.") logging.info("Scheduler interrupted by user.")
except Exception as e: except Exception as e:
# 捕获其他未预期的异常
logging.error(f"Unexpected error: {e}") logging.error(f"Unexpected error: {e}")
#
# if __name__ == "__main__":
# get_reportfile_send_dingding("用户管理模块_测试报告", "http://192.168.1.166")
\ No newline at end of file
...@@ -9,4 +9,5 @@ name,account,expected ...@@ -9,4 +9,5 @@ name,account,expected
用户删除_008,admin@37,删除成功 用户删除_008,admin@37,删除成功
用户删除_009,admin@38,删除成功 用户删除_009,admin@38,删除成功
用户删除_010,admin@44,删除成功 用户删除_010,admin@44,删除成功
用户删除_011,admin@51,删除成功 用户删除_011,admin@48,删除成功
\ No newline at end of file 用户删除_012,admin@51,删除成功
\ No newline at end of file
name,account,username,password,new_password,phone,email
用户管理主流程_001,admin@Test,admin@Test,Ubains@54321,Ubains@4321,17319004611,2919407801@qq.com
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论