Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录
切换导航
U
ubains-module-test
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
郑晓兵
ubains-module-test
Commits
30e878c3
提交
30e878c3
authored
4月 14, 2025
作者:
陈泽健
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
登录模块增加excel写入函数调用。调试将图片嵌入单元格的功能,验证不可行。
上级
0743db2b
显示空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
134 行增加
和
56 行删除
+134
-56
base.cpython-310.pyc
预定系统/Base/__pycache__/base.cpython-310.pyc
+0
-0
base.py
预定系统/Base/base.py
+51
-47
README.md
预定系统/README.md
+3
-0
新-账号密码登录测试.cpython-310.pyc
预定系统/cases/登录模块/__pycache__/新-账号密码登录测试.cpython-310.pyc
+0
-0
新-账号密码登录测试.py
预定系统/cases/登录模块/新-账号密码登录测试.py
+80
-9
会议预定测试用例.xlsx
预定系统/测试数据/会议预定测试用例.xlsx
+0
-0
长安大学测试用例.xlsx
预定系统/测试数据/长安大学测试用例.xlsx
+0
-0
没有找到文件。
预定系统/Base/__pycache__/base.cpython-310.pyc
浏览文件 @
30e878c3
No preview for this file type
预定系统/Base/base.py
浏览文件 @
30e878c3
...
...
@@ -1747,12 +1747,14 @@ def approval_status_control(message_name, approval_type, wd):
# xlsx文件写入函数
import
os
import
openpyxl
import
logging
from
openpyxl
import
load_workbook
from
openpyxl.drawing.image
import
Image
from
openpyxl.utils
import
get_column_letter
import
logging
def
write_xlsx_data
(
xlsx_file_path
,
sheet_name
,
function_number
,
test_result
,
log_screenshot
):
"""
在XLSX文件的指定行中填充测试结果和日志截图。
在XLSX文件的指定行中填充测试结果和日志截图
(图片嵌入单元格)
。
参数:
xlsx_file_path (str): XLSX文件的路径。
...
...
@@ -1762,76 +1764,78 @@ def write_xlsx_data(xlsx_file_path, sheet_name, function_number, test_result, lo
log_screenshot (str): 日志截图路径。
"""
try
:
# 打开XLSX文件
workbook
=
openpyxl
.
load_workbook
(
xlsx_file_path
)
workbook
=
load_workbook
(
xlsx_file_path
)
except
FileNotFoundError
:
raise
FileNotFoundError
(
f
"文件未找到: {xlsx_file_path}"
)
except
Exception
as
e
:
raise
Exception
(
f
"无法打开文件: {e}"
)
# 选择工作表
if
sheet_name
:
try
:
sheet
=
workbook
[
sheet_name
]
sheet
=
workbook
[
sheet_name
]
if
sheet_name
else
workbook
.
active
except
KeyError
:
raise
KeyError
(
f
"工作表未找到: {sheet_name}"
)
else
:
sheet
=
workbook
.
active
# 读取表头
,从第三行开始
# 读取表头
headers
=
[
cell
.
value
for
cell
in
sheet
[
3
]]
required_columns
=
[
"功能编号"
,
"测试结果"
,
"日志截图"
]
indices
=
{}
# 打印表头列名
logging
.
info
(
f
"表头列名: {headers}"
)
# 找到表头中名为 '功能编号'、'测试结果' 和 '日志截图' 的列索引
for
col
in
required_columns
:
try
:
function_number_index
=
headers
.
index
(
"功能编号"
)
except
ValueError
as
e
:
raise
ValueError
(
f
"表头中没有找到 '功能编号' 列: {e
}"
)
indices
[
col
]
=
headers
.
index
(
col
)
except
ValueError
:
raise
ValueError
(
f
"表头中缺少必要列: {col
}"
)
try
:
test_result_index
=
headers
.
index
(
"测试结果"
)
except
ValueError
as
e
:
raise
ValueError
(
f
"表头中没有找到 '测试结果' 列: {e}"
)
try
:
log_screenshot_index
=
headers
.
index
(
"日志截图"
)
except
ValueError
as
e
:
raise
ValueError
(
f
"表头中没有找到 '日志截图' 列: {e}"
)
# 查找目标行
target_row
=
None
for
row
in
sheet
.
iter_rows
(
min_row
=
4
):
if
row
[
indices
[
"功能编号"
]]
.
value
==
function_number
:
target_row
=
row
break
else
:
raise
ValueError
(
f
"未找到功能编号为 {function_number} 的行"
)
# 遍历数据行,找到与给定功能编号匹配的行
for
row
in
sheet
.
iter_rows
(
min_row
=
4
,
values_only
=
False
):
if
row
[
function_number_index
]
.
value
==
function_number
:
# 填充测试结果
row
[
test_result_index
]
.
value
=
test_result
test_result_cell
=
target_row
[
indices
[
"测试结果"
]]
test_result_cell
.
value
=
test_result
# 插入日志截图
# 处理图片
if
log_screenshot
:
img
=
Image
(
log_screenshot
)
img_cell
=
target_row
[
indices
[
"日志截图"
]]
# 计算单元格尺寸(单位转换)
col_letter
=
get_column_letter
(
img_cell
.
column
)
col_width
=
sheet
.
column_dimensions
[
col_letter
]
.
width
or
8.43
# 默认列宽
row_height
=
sheet
.
row_dimensions
[
img_cell
.
row
]
.
height
or
15.0
# 默认行高
# 将Excel单位转换为像素(经验公式)
cell_width_px
=
col_width
*
7
# 1字符 ≈ 7像素
cell_height_px
=
row_height
*
1.333
# 1磅 ≈ 1.333像素
# 按比例缩放图片
img_ratio
=
img
.
width
/
img
.
height
if
cell_width_px
/
cell_height_px
>
img_ratio
:
new_height
=
cell_height_px
new_width
=
cell_height_px
*
img_ratio
else
:
new_width
=
cell_width_px
new_height
=
cell_width_px
/
img_ratio
# 获取单元格的宽度和高度
cell
=
row
[
log_screenshot_index
]
cell_width
=
sheet
.
column_dimensions
[
get_column_letter
(
cell
.
column
)]
.
width
cell_height
=
sheet
.
row_dimensions
[
cell
.
row
]
.
height
# 调整图片大小以适应单元格
img
.
width
=
cell_width
*
7
# 7 是一个经验值,根据需要调整
img
.
height
=
cell_height
*
1.5
# 1.5 是一个经验值,根据需要调整
img
.
width
=
new_width
img
.
height
=
new_height
# 设置图片位置
sheet
.
add_image
(
img
,
cell
.
coordinate
)
# 将图片锚定到单元格
sheet
.
add_image
(
img
,
f
"{col_letter}{img_cell.row}"
)
break
else
:
raise
ValueError
(
f
"未找到功能编号为 {function_number} 的行"
)
# 保存修改后的文件
# 保存文件
try
:
workbook
.
save
(
xlsx_file_path
)
logging
.
info
(
f
"文件
{xlsx_file_path} 已保存,数据已写入功能编号为 {function_number} 的行。
"
)
logging
.
info
(
f
"文件
已保存,功能编号 {function_number} 的图片已嵌入
"
)
except
Exception
as
e
:
logging
.
error
(
f
"保存文件时出错: {e}"
)
logging
.
error
(
f
"保存失败: {e}"
)
raise
# import xlwings as xw
...
...
预定系统/README.md
浏览文件 @
30e878c3
...
...
@@ -283,3 +283,5 @@
-
优化read_xlsx_data用例文件读取函数,增加功能类别判断,实现标准版和各项目的区分执行。补充工商银行项目的车牌功能验证。config.json文件增加工商银行生产环境。
78.
2025-04-11
-
补充get_remote_log_with_paramiko函数来获取服务器的日志文件。补充config.json的统一平台测试环境。
79.
2025-04-14
-
登录模块增加excel写入函数调用。调试将图片嵌入单元格的功能,验证不可行。
\ No newline at end of file
预定系统/cases/登录模块/__pycache__/新-账号密码登录测试.cpython-310.pyc
浏览文件 @
30e878c3
No preview for this file type
预定系统/cases/登录模块/新-账号密码登录测试.py
浏览文件 @
30e878c3
...
...
@@ -59,25 +59,95 @@ class Login:
safe_click
((
locator_type
,
locator_value
),
wd
)
sleep
(
2
)
if
"成功"
in
expented_result
:
# 获取登录成功提示信息
notify_text
=
elment_get_text
((
By
.
CSS_SELECTOR
,
"div[class='meeting_t'] span:nth-child(1)"
),
wd
)
# 截屏并记录日志
SELENIUM_LOG_SCREEN
(
wd
,
'50
%
'
,
'Login'
,
'Login_Pwd'
,
"检查登录成功提示信息"
)
# 记录提示信息
INFO
(
f
"Alert text: {notify_text}"
)
CHECK_POINT
(
'检查是否出现提示弹窗'
,
"欢迎"
in
notify_text
)
# 检查提示信息是否包含“欢迎”
if
CHECK_POINT
(
'检查是否出现提示弹窗'
,
"欢迎"
in
notify_text
):
# 如果提示信息不正确,记录为失败
write_xlsx_data
(
xlsx_file_path
,
"登录页面"
,
name
,
f
"失败,提示{notify_text}"
,
r"D:\GithubData\自动化\ubains-module-test\预定系统\reports\imgs\Login\Login_Pwd\检查登录成功提示信息.png"
)
else
:
# 如果提示信息正确,记录为成功
write_xlsx_data
(
xlsx_file_path
,
"登录页面"
,
name
,
f
"成功,正确提示:{notify_text}"
,
r"D:\GithubData\自动化\ubains-module-test\预定系统\reports\imgs\Login\Login_Pwd\检查登录成功提示信息.png"
)
# 点击退出登录按钮
safe_click
((
By
.
XPATH
,
"//img[@title='退出登录']"
),
wd
)
sleep
(
2
)
elif
"错误"
in
expented_result
:
notify_text
=
get_notify_text
(
wd
,
(
By
.
XPATH
,
"//p[@class='el-message__content']"
),
'Login'
,
'Login_Pwd'
,
f
"检查{expented_result}登录的提示信息"
)
# 获取登录错误提示信息
notify_text
=
get_notify_text
(
wd
,
(
By
.
XPATH
,
"//p[@class='el-message__content']"
),
'Login'
,
'Login_Pwd'
,
f
"检查{expented_result}登录的提示信息"
)
# 记录获取到的结果
INFO
(
f
"获取到的结果:{notify_text}"
)
CHECK_POINT
(
'检查是否出现提示弹窗'
,
expented_result
in
notify_text
)
# 检查提示信息是否包含预期的错误信息
if
CHECK_POINT
(
'检查是否出现提示弹窗'
,
expented_result
in
notify_text
):
# 如果提示信息不正确,记录为失败
write_xlsx_data
(
xlsx_file_path
,
"登录页面"
,
name
,
f
"失败,提示:{notify_text}"
,
r"D:\GithubData\自动化\ubains-module-test\预定系统\reports\imgs\Login\Login_Pwd\检查登录成功提示信息.png"
)
else
:
# 如果提示信息正确,记录为成功
write_xlsx_data
(
xlsx_file_path
,
"登录页面"
,
name
,
f
"成功,正确提示:{notify_text}"
,
r"D:\GithubData\自动化\ubains-module-test\预定系统\reports\imgs\Login\Login_Pwd\检查登录成功提示信息.png"
)
sleep
(
2
)
elif
"请输入"
in
expented_result
:
notify_text
=
get_notify_text
(
wd
,
(
By
.
XPATH
,
"//p[@class='el-message__content']"
),
'Login'
,
'Login_Pwd'
,
f
"检查{expented_result}登录的提示信息"
)
# 获取登录提示信息
notify_text
=
get_notify_text
(
wd
,
(
By
.
XPATH
,
"//p[@class='el-message__content']"
),
'Login'
,
'Login_Pwd'
,
f
"检查{expented_result}登录的提示信息"
)
# 记录获取到的结果
INFO
(
f
"获取到的结果:{notify_text}"
)
CHECK_POINT
(
'检查是否出现提示弹窗'
,
expented_result
in
notify_text
)
# 检查提示信息是否包含预期的提示信息
if
CHECK_POINT
(
'检查是否出现提示弹窗'
,
expented_result
in
notify_text
):
# 如果提示信息不正确,记录为失败
write_xlsx_data
(
xlsx_file_path
,
"登录页面"
,
name
,
f
"失败,提示:{notify_text}"
,
r"D:\GithubData\自动化\ubains-module-test\预定系统\reports\imgs\Login\Login_Pwd\检查登录成功提示信息.png"
)
else
:
# 如果提示信息正确,记录为成功
write_xlsx_data
(
xlsx_file_path
,
"登录页面"
,
name
,
f
"成功,正确提示:{notify_text}"
,
r"D:\GithubData\自动化\ubains-module-test\预定系统\reports\imgs\Login\Login_Pwd\检查登录成功提示信息.png"
)
sleep
(
2
)
\ No newline at end of file
预定系统/测试数据/会议预定测试用例.xlsx
浏览文件 @
30e878c3
No preview for this file type
预定系统/测试数据/长安大学测试用例.xlsx
浏览文件 @
30e878c3
No preview for this file type
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论