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

补充了自动获取本机IP地址以及自动运行ngrok开启映射,避免后续IP改变后无法打开报告问题。

上级 ee1a4399
......@@ -176,7 +176,7 @@ def compare_images_feature_matching(image1_path, image2_path):
# logging.info("开始对比图片")
#
# image1_path = r'D:\GithubData\自动化\ubains-module-test\预定系统\reports\imgs\Exhibit_Inspect\No_PaperLess\DeviceA-ShareScreen.png'
# image2_path = r'D:\GithubData\自动化\ubains-module-test\预定系统\reports\imgs\Exhibit_Inspect\No_PaperLess\DeviceB-ShareScreen.png'
# image2_path = r'D:\GithubData\自动化\ubains-module-test\预定系统\reports\imgs\Exhibit_Inspect\No_PaperLess\同屏前-无纸化设备B界面截屏.png'
#
# if not os.path.exists(image1_path):
# logging.error(f"图片 {image1_path} 不存在")
......@@ -191,6 +191,69 @@ def compare_images_feature_matching(image1_path, image2_path):
# else:
# logging.error("图片不同")
import cv2
import numpy
from PIL import Image
import logging
import os
def calculate(image1, image2):
image1 = cv2.cvtColor(numpy.asarray(image1), cv2.COLOR_RGB2BGR)
image2 = cv2.cvtColor(numpy.asarray(image2), cv2.COLOR_RGB2BGR)
hist1 = cv2.calcHist([image1], [0], None, [256], [0.0, 255.0])
hist2 = cv2.calcHist([image2], [0], None, [256], [0.0, 255.0])
# 计算直方图的重合度
degree = 0
for i in range(len(hist1)):
if hist1[i] != hist2[i]:
degree = degree + (1 - abs(hist1[i] - hist2[i]) / max(hist1[i], hist2[i]))
else:
degree = degree + 1
degree = degree / len(hist1)
return degree
def classify_hist_with_split(image1, image2, size=(256, 256)):
image1 = Image.open(image1)
image2 = Image.open(image2)
# 将图像resize后,分离为RGB三个通道,再计算每个通道的相似值
image1 = cv2.cvtColor(numpy.asarray(image1), cv2.COLOR_RGB2BGR)
image2 = cv2.cvtColor(numpy.asarray(image2), cv2.COLOR_RGB2BGR)
image1 = cv2.resize(image1, size)
image2 = cv2.resize(image2, size)
sub_image1 = cv2.split(image1)
sub_image2 = cv2.split(image2)
sub_data = 0
for im1, im2 in zip(sub_image1, sub_image2):
sub_data += calculate(im1, im2)
sub_data = sub_data / 3
return sub_data
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logging.info("开始对比图片")
image1_path = r'D:\GithubData\自动化\ubains-module-test\预定系统\reports\imgs\Exhibit_Inspect\No_PaperLess\DeviceA-ShareScreen.png'
image2_path = r'D:\GithubData\自动化\ubains-module-test\预定系统\reports\imgs\Exhibit_Inspect\No_PaperLess\DeviceB-ShareScreen.png'
if not os.path.exists(image1_path):
logging.error(f"图片 {image1_path} 不存在")
exit(1)
if not os.path.exists(image2_path):
logging.error(f"图片 {image2_path} 不存在")
exit(1)
# 对比两张截图的相似度
result1 = classify_hist_with_split(image1_path, image2_path)
# 确保 result1 是一个标量值
if isinstance(result1, numpy.ndarray):
result1 = result1.item()
print("相似度为:" + "%.2f%%" % (result1 * 100))
import cv2
import logging
......@@ -489,7 +552,7 @@ def music_control(app_drive,wd):
# 调用音频采集判断音量函数
INFO("请检查中控屏音乐播放的音频采集是否正常!!!")
volume_acquisition()
sleep(10)
sleep(5)
# 这是音乐开启播放后的界面显示
INFO("请检查中控屏软件打开音乐播放后的界面状态显示")
SELENIUM_LOG_SCREEN(wd, "50%", "Exhibit_Inspect", "Control_Manage", "music_on")
......
......@@ -1080,3 +1080,81 @@ def get_test_result(latest_report, wd):
# wd = GSTORE['wd']
# test_result = get_test_result("http://nat.ubainsyun.com:31134/report_20250217_094401.html",wd)
# print(test_result)
import socket
import re
import subprocess
# 获取本机IP地址
def get_local_ip():
try:
# 创建一个UDP套接字
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# 连接到一个公共的IP地址和端口
sock.connect(("8.8.8.8", 80))
# 获取本地IP地址
local_ip = sock.getsockname()[0]
finally:
sock.close()
return local_ip
import yaml
import logging
import socket
import subprocess
# 获取本机IP地址
def get_local_ip():
try:
# 创建一个UDP套接字
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# 连接到一个公共的IP地址和端口
sock.connect(("8.8.8.8", 80))
# 获取本地IP地址
local_ip = sock.getsockname()[0]
finally:
sock.close()
return local_ip
# 更新ngrok.cfg文件中的IP地址
def update_ngrok_config(config_path, new_ip):
try:
with open(config_path, 'r', encoding='utf-8') as file:
config = yaml.safe_load(file)
# 更新IP地址
config['tunnels']['nat1']['proto']['tcp'] = f"{new_ip}:80"
with open(config_path, 'w', encoding='utf-8') as file:
yaml.safe_dump(config, file, default_flow_style=False, allow_unicode=True)
logging.info(f"ngrok.cfg 更新成功,新的IP地址为: {new_ip}")
except Exception as e:
logging.error(f"更新ngrok.cfg文件时出错: {e}")
# 启动ngrok
def start_ngrok(ngrok_path, config_path):
try:
command = [ngrok_path, '-config', config_path, 'start', 'nat1']
subprocess.Popen(command, shell=True)
logging.info(f"ngrok 启动成功")
except Exception as e:
logging.error(f"启动ngrok时出错: {e}")
# if __name__ == '__main__':
# logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
#
# # 获取本机IP地址
# local_ip = get_local_ip()
# logging.info(f"本机IP地址: {local_ip}")
#
# # 更新ngrok.cfg文件
# ngrok_config_path = r'D:\GithubData\自动化\ubains-module-test\预定系统\ngrok\ngrok-调试主机\ngrok.cfg'
# update_ngrok_config(ngrok_config_path, local_ip)
#
# # 启动ngrok
# ngrok_path = r'D:\GithubData\自动化\ubains-module-test\预定系统\ngrok\ngrok-调试主机\ngrok.exe'
# start_ngrok(ngrok_path, ngrok_config_path)
......@@ -216,3 +216,4 @@
- 处理无纸化同屏操作流程。调整正则表达式获取测试报告的百分比参数。
56. 2025-02-18
- 讯飞语音转录补充云喇叭调用,更新ngrok映射前ip地址,将无纸化同屏打上展厅巡检标签。
- 补充了自动获取本机IP地址以及自动运行ngrok开启映射,避免后续IP改变后无法打开报告问题。
\ No newline at end of file
......@@ -15,7 +15,7 @@ class Server_monitoring_0001:
"""
执行指令:
1.cd 预定系统
2.hytest --report_title 会议预约测试报告 --report_url_prefix http://192.168.1.225 --test 展厅补充会议创建_001
2.hytest --report_title 会议预约测试报告 --report_url_prefix http://nat.ubainsyun.com:31133 --test 展厅补充会议创建_001
"""
tags = ['展厅巡检','服务器状态巡检']
......
# import time
# import logging
#
# # 假设这些函数是已经定义好的
# # sendCodeString(com, command)
# # getSystemInt(key, default)
# # setSystemInt(key, value)
# # setText(id, text)
# # setBarLevel(id, level)
# # setAllBarLevel(id, level)
# # setButtonImage(id, image)
# # sendLog(message, data)
# # getBarLevel(id)
# # metAudio.update()
# # delay(seconds, function)
#
# YPCOM = "COM7" # 控制端口
# MaxLength = 8 # 最大通道数
# ChannelMute_ONIMG = 'slDevPlayerMuteBtnS1.png' # 静音状态按钮0db--50db
# ChannelMute_OFFIMG = 'slDevPlayerMuteBtfS1.png' # 取消静音状态按钮
#
# ChannelValue = [0] * MaxLength # 设置音量初始值
# ChannelMute = [0] * MaxLength # 设置静音初始值 0=非静音 1=静音
# ChannelMax = [0, 2, 12, 12, 12, 12, 12, 12] # 设置控制音量的最大值
# ChannelMini = [0, -10, -10, -10, -20, -20, -20, -20] # 设置控制音量的最小值
# ChannelDPValue = [0] * MaxLength
# ChannelDPMax = [0, 20, 20, 20, 20, 20, 20, 20]
# ChannelDPMini = [0, -100, -100, -100, -100, -100, -100, -100]
#
# # 初始化数组
# for i in range(MaxLength):
# ChannelMute[i] = 0 # 初始静音值0非静音,1静音
# ChannelValue[i] = -20 # 初始音量值-20DB
# ChannelMax[i] = 10 # 最大音量db值0(与ChannelMini[i]决定音量控制区间)
# ChannelMini[i] = -30 # 最小音量db值-50(与ChannelMax[i]决定音量控制区间)
#
#
# # 音量加
# def SetVolumeUP(channel):
# ChannelValue[channel] = getSystemInt(f'INVOLUME{channel}', ChannelValue[channel]) # 读取中控保存的音量值
# if ChannelValue[channel] < ChannelMax[channel]:
# ChannelValue[channel] += 1
# else:
# ChannelValue[channel] = ChannelMax[channel]
# SetVolume(channel)
#
#
# # 音量减
# def SetVolumeDown(channel):
# ChannelValue[channel] = getSystemInt(f'INVOLUME{channel}', ChannelValue[channel]) # 读取中控保存的音量值
# if ChannelValue[channel] > ChannelMini[channel]:
# ChannelValue[channel] -= 1
# else:
# ChannelValue[channel] = ChannelMini[channel]
# SetVolume(channel)
#
#
# # 设置音量大小 并将音量大小值存入中控
# def SetVolume(channel):
# level_command_map = {
# 1: 'Level9 set level 1',
# 2: 'Level2 set level 1',
# 3: 'Level2 set level 2',
# 4: 'Level3 set level 1',
# 5: 'Level4 set level 1',
# 6: 'Level2 set level 9',
# 7: 'Level10 set level 1',
# 8: 'Level7 set level 7'
# }
#
# if channel in level_command_map:
# command = f"{level_command_map[channel]} {ChannelValue[channel]}x0d"
# sendCodeString(YPCOM, command)
#
# # 拉条状态和数值
# chNum = ChannelValue[channel] - ChannelMini[channel] # 当前音量值-最小音量值得到当前音量值与最低音量值的差
# chRound = round(chNum * 100 / (ChannelMax[channel] - ChannelMini[channel])) # 拉条与文字值为音量值差(最大音量-最小音量)100
# setText(f'txtVolume{channel}', f'{chRound}%') # 显示拉条上方文字
# setBarLevel(f'barVolume{channel}', chRound) # 设置拉条的值
# setAllBarLevel(f'barVolume{channel}', chRound)
# setSystemInt(f'INVOLUME{channel}', ChannelValue[channel]) # 将值保存在中控主机
# metAudio.update()
#
#
# # 静音取消静音功能
# def SetVolumeMute(channel):
# mute_command_map = {
# 1: 'Level9 set mute 1',
# 2: 'Level2 set mute 1',
# 3: 'Level2 set mute 2',
# 4: 'Level3 set mute 1',
# 5: 'Level4 set mute 1',
# 6: 'Level2 set mute 9',
# 7: 'Level10 set mute 1',
# 8: 'Level7 set mute 7'
# }
#
# if channel in mute_command_map:
# if ChannelMute[channel] == 0:
# command = f"{mute_command_map[channel]} 1x0d"
# sendCodeString(YPCOM, command)
# ChannelMute[channel] = 1
# setButtonImage(f'btnVolumeMute{channel}', ChannelMute_ONIMG) # 静音
# else:
# command = f"{mute_command_map[channel]} 0x0d"
# sendCodeString(YPCOM, command)
# ChannelMute[channel] = 0
# setButtonImage(f'btnVolumeMute{channel}', ChannelMute_OFFIMG) # 取消静音
#
# setSystemInt(f'JINYING{channel}', ChannelMute[channel])
# metAudio.update()
#
#
# # 音频同步状态
# def INITFrequencyStatus():
# for i in range(1, MaxLength + 1):
# ChannelValue[i - 1] = getSystemInt(f'INVOLUME{i}', ChannelValue[i - 1])
# chNum = ChannelValue[i - 1] - ChannelMini[i - 1]
# chRound = round(chNum * 100 / (ChannelMax[i - 1] - ChannelMini[i - 1]))
# # 同步拉条状态
# setText(f'txtVolume{i}', f'{chRound}%')
# setAllBarLevel(f'barVolume{i}', chRound)
# setBarLevel(f'barVolume{i}', chRound)
# # 同步静音状态
# ChannelMute[i - 1] = getSystemInt(f'JINYING{i}', ChannelMute[i - 1])
# if ChannelMute[i - 1] == 1:
# setButtonImage(f'btnVolumeMute{i}', ChannelMute_ONIMG)
# else:
# setButtonImage(f'btnVolumeMute{i}', ChannelMute_OFFIMG)
#
# setButtonImage('ypModel1', 'TemporalPowerOFF_png')
# setButtonImage('ypModel2', 'TemporalPowerOFF_png')
# setButtonImage('ypModel3', 'TemporalPowerOFF_png')
# model_value = getSystemInt('ypModelValue', 1)
# setButtonImage(f'ypModel{model_value}', 'TemporalPowerON_png')
#
#
# def delay(seconds, function):
# time.sleep(seconds)
# function()
#
#
# # 延迟5秒后初始化音频状态
# delay(5, INITFrequencyStatus)
#
#
# # 拉条的方法
# def SetBrace(channel):
# getBarNum = getBarLevel(f'barVolume{channel}') # getBarLevel()方法获取拉条当前值
# # 当前通道音量分贝值 = 拉条值((最大分贝值-最小分贝值)100)+ 最小分贝值;
# ChannelValue[channel] = round(getBarNum * (ChannelMax[channel] - ChannelMini[channel]) / 100) + ChannelMini[channel]
# SetVolume(channel)
#
#
# def ypModel(arg):
# if arg == 3:
# setSystemInt('INVOLUME1', 0)
# setSystemInt('INVOLUME2', 0)
# setSystemInt('INVOLUME3', 0)
# metAudio.update()
# INITFrequencyStatus()
#
# setSystemInt('ypModelValue', arg)
# setButtonImage('ypModel1', 'TemporalPowerOFF_png')
# setButtonImage('ypModel2', 'TemporalPowerOFF_png')
# setButtonImage('ypModel3', 'TemporalPowerOFF_png')
# setButtonImage(f'ypModel{arg}', 'TemporalPowerON_png')
# sendCodeString(YPCOM, f'DEVICE recallPreset 100{arg}x0d')
#
#
# def getYpDp():
# sendCodeString('NET1', 'AudioMeter2 get levelsx0d')
# delay(0.3, lambda: sendCodeString('NET1', 'AudioMeter4 get levelsx0d'))
# delay(0.6, lambda: sendCodeString('NET1', 'AudioMeter5 get levelsx0d'))
# delay(1, getYpDp)
#
#
# def getYpDp1():
# sendCodeString('NET1',
# 'xFFxFBx18xFFxFBx1FxFFxFCx20xFFxFCx23xFFxFBx27xFFxFCx24xFFxFAx1Fx00x78x00x32xFFxF0xFFxFAx27x00xFFxF0xFFxFAx18x00x41x4Ex53x49xFFxF0xFFxFDx03xFFxFBx01x0dx0a')
# delay(60, getYpDp1)
#
#
# getYpDp()
# getYpDp1()
#
#
# def setStringReceive(com, callback):
# def receive_data(data):
# sendLog(f'{com} Receive', data)
# CountArrayCount[7] = 0
# callback(data)
#
# # 假设这里有一个机制来接收数据并调用receive_data
# pass
#
#
# def handle_com7_data(data):
# sendLog('COM7 Receive', data)
# CountArrayCount[7] = 0
#
#
# def handle_net1_data(data):
# CountArrayCount[7] = 0
# a = data.find('AudioMeter')
# if a != -1:
# num = data[a + 10]
# c = data[data.find('value'):].split()
# if num == '2':
# ChannelDPValue[2] = round(float(c[7]))
# ChannelDPValue[3] = round(float(c[8]))
# ChannelDPValue[4] = round(float(c[9]))
# ChannelDPValue[5] = round(float(c[0]))
# ChannelDPValue[6] = round(float(c[1]))
# ChannelDPValue[7] = round(float(c[2]))
# ChannelDPValue[8] = round(float(c[3]))
# ChannelDPValue[9] = round(float(c[4]))
# ChannelDPValue[10] = round(float(c[5]))
# ChannelDPValue[11] = round(float(c[6]))
# ChannelDPValue[12] = round(float(c[7]))
# elif num == '4':
# ChannelDPValue[13] = round(float(c[1]))
# ChannelDPValue[14] = round(float(c[2]))
# else:
# ChannelDPValue[0] = round(float(c[0]))
# ChannelDPValue[1] = round(float(c[1]))
# metAudio.update()
#
#
# setStringReceive(YPCOM, handle_com7_data)
# setStringReceive('NET1', handle_net1_data)
......@@ -148,24 +148,6 @@ class Exhibition_hall_Control_000x:
# 调用信息发布控制函数
information_control(app_drive,wd)
# STEP(7, "关闭展厅环境灯光。")
# # 切换灯光控制界面
# # 所有测试结束后关闭灯光
# logging.info("尝试定位【灯光控制】按钮元素,并点击按钮")
# light_button = app_drive.find_element(AppiumBy.XPATH,
# "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.Button[3]")
# logging.info("定位成功")
# # 点击【灯光控制】按钮
# light_button.click()
# sleep(10)
# light_control(app_drive)
except Exception as e:
# 捕获并记录任何发生的错误
logging.error(f"发生错误: {e}", exc_info=True)
\ No newline at end of file
# finally:
# 确保驱动程序在测试结束后正确关闭
# if app_drive:
# app_drive.quit()
# logging.info("驱动程序已退出。")
\ No newline at end of file
......@@ -80,12 +80,25 @@ class same_screen_share_001:
app_drive2.get_screenshot_as_file(
r"D:\GithubData\自动化\ubains-module-test\预定系统\reports\imgs\Exhibit_Inspect\No_PaperLess\同屏后-无纸化设备B界面截屏.png")
# 调用图片对比函数判断相似度
match_text = compare_images_feature_matching(
r"/预定系统/reports/imgs/Exhibit_Inspect/No_PaperLess/DeviceA-ShareScreen.png",
r"/预定系统/reports/imgs/Exhibit_Inspect/No_PaperLess/DeviceB-ShareScreen.png")
INFO(f"图片相似度:{match_text}")
# CHECK_POINT("校验同屏功能是否成功", match_text == True)
# # 调用图片对比函数判断相似度
# image1_path = r"/预定系统/reports/imgs/Exhibit_Inspect/No_PaperLess/同屏后-无纸化设备A界面截屏.png"
# image2_path = r"/预定系统/reports/imgs/Exhibit_Inspect/No_PaperLess/同屏后-无纸化设备B界面截屏.png"
#
# if not os.path.exists(image1_path):
# logging.error(f"图片 {image1_path} 不存在")
# exit(1)
# if not os.path.exists(image2_path):
# logging.error(f"图片 {image2_path} 不存在")
# exit(1)
#
# # 对比两张截图的相似度
# result1 = classify_hist_with_split(image1_path, image2_path)
#
# # 确保 result1 是一个标量值
# if isinstance(result1, numpy.ndarray):
# result1 = result1.item()
# # 输出相似度
# INFO("相似度为:" + "%.2f%%" % (result1 * 100))
except Exception as e:
logging.error(f"发生错误: {e}", exc_info=True)
......@@ -114,9 +114,9 @@ class Exhibition_Meeting_Control_0001:
app_secret = os.getenv("APP_SECRET", "88bc1ec4eba624f47b2200a4ce8c3852")
device_sn = os.getenv("DEVICE_SN", "W703BB44444")
play_cloud_voice(app_id, app_secret, device_sn)
mic_off_button = app_drive.find_element(AppiumBy.XPATH,
"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout/android.widget.RelativeLayout[6]/android.widget.Button[3]")
mic_off_button.click()
# mic_off_button = app_drive.find_element(AppiumBy.XPATH,
# "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout/android.widget.RelativeLayout[6]/android.widget.Button[3]")
# mic_off_button.click()
sleep(5)
# 关闭左摄像头
......
server_addr: "ngrok.ubsyun.com:9083"
server_addr: ngrok.ubsyun.com:9083
trust_host_root_certs: false
tunnels:
nat1:
remote_port: 31133
proto:
tcp: "192.168.1.133:80"
\ No newline at end of file
tcp: 192.168.1.135:80
remote_port: 31133
......@@ -69,7 +69,19 @@ def start_workers(num_workers):
start_workers(3)
# 定时执行预定系统测试任务1
# schedule.every().day.at("09:00").do(run_task, run_automation_test, report_title="预定系统测试报告", report_url_prefix="http://nat.ubainsyun.com:31134", test_case="预定系统功能", ding_type="标准版巡检")
# schedule.every().day.at("15:33").do(run_task, run_automation_test, report_title="预定系统测试报告", report_url_prefix="http://nat.ubainsyun.com:31133", test_case="预定系统功能", ding_type="标准版巡检")
# 获取本机IP地址
local_ip = get_local_ip()
logging.info(f"本机IP地址: {local_ip}")
# 更新ngrok.cfg文件
ngrok_config_path = r'D:\GithubData\自动化\ubains-module-test\预定系统\ngrok\ngrok-调试主机\ngrok.cfg'
update_ngrok_config(ngrok_config_path, local_ip)
# 启动ngrok
ngrok_path = r'D:\GithubData\自动化\ubains-module-test\预定系统\ngrok\ngrok-调试主机\ngrok.exe'
start_ngrok(ngrok_path, ngrok_config_path)
# 定时执行展厅巡检任务
schedule.every().day.at("07:45").do(run_task, run_automation_test, report_title="展厅巡检测试报告", report_url_prefix="http://nat.ubainsyun.com:31133", test_case="展厅巡检", ding_type="展厅巡检")
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论