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

系统地址获取方式改为读取config.json进行获取对应的环境信息。

上级 bc3495b9
......@@ -3,8 +3,6 @@ import glob
import re
import urllib
from selenium.webdriver.chrome.service import Service
import numpy as np
import requests
import json
import hmac
import hashlib
......@@ -13,19 +11,12 @@ import psutil
import time
import subprocess
import logging
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service as ChromeService
from hytest import *
from selenium import webdriver
from selenium.common import TimeoutException, NoSuchElementException, ElementNotInteractableException
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from urllib.parse import urlencode
from datetime import datetime
from time import sleep
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
# 获取当前脚本的绝对路径
current_dir = os.path.dirname(os.path.abspath(__file__))
......@@ -44,10 +35,6 @@ logging.basicConfig(
]
)
# 配置日志
# logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
def browser_init(login_type):
"""
初始化浏览器设置和实例。
......@@ -90,17 +77,25 @@ def browser_init(login_type):
# 设置隐式等待时间为10秒,以允许元素加载
wd.implicitly_wait(60)
# 请求WebDriver打开登录页面
login_url = ""
# 判断初始化的系统类型
if login_type == "标准版":
login_url = 'https://192.168.5.235/#/login/lgindf'
elif login_type == "展厅预定巡检":
login_url = "http://192.168.5.200/#/login/logindf"
elif login_type == "展厅运维巡检":
login_url = "http://192.168.5.200:8081/#/login"
elif login_type == "展厅统一平台巡检":
login_url = "http://192.168.5.200:38083/#/login"
# 获取当前脚本的绝对路径
current_dir = os.path.dirname(os.path.abspath(__file__))
# 构建配置文件的绝对路径
config_path = os.path.join(current_dir, '..', 'Base', 'config.json')
logging.info(f"配置文件路径: {config_path}")
# 检查文件是否存在
if not os.path.exists(config_path):
raise FileNotFoundError(f"配置文件 {config_path} 不存在")
# 读取配置文件
with open(config_path, 'r', encoding='utf-8') as config_file:
config = json.load(config_file)
login_url = config.get(login_type)
INFO(f"正在打开{login_type}的登录页面:{login_url}")
# 检查是否成功获取到 URL
if not login_url:
raise ValueError(f"未找到对应的 URL 配置项: {login_type}")
# 打开对应类型的登录页面
wd.get(login_url)
......@@ -116,6 +111,7 @@ def browser_init(login_type):
logging.error(f"浏览器初始化失败:{e}")
def admin_login(username, password):
"""
管理员登录函数。
......
{
"_comment_meeting": "这是标准版预定系统的URL",
"标准版": "https://192.168.5.235/#/login/lgindf",
"_comment_exhibit_meeting": "这是展厅预定系统的URL",
"展厅预定巡检": "http://192.168.5.200/#/login/logindf",
"_comment_exhibit_operation": "这是展厅运维系统的URL",
"展厅运维巡检": "http://192.168.5.200:8081/#/login",
"_comment_exhibit_unified_platform": "这是展厅统一平台系统的URL",
"展厅统一平台巡检": "http://192.168.5.200:38083/#/login"
}
\ No newline at end of file
......@@ -176,4 +176,5 @@
- 调整截图文件的缩放比,实现测试报告点击图片弹窗放大功能。
42. 2025-01-16
- 优化browser_init初始化函数的传参方式以及系统环境判断处理。优化ngrok以及定时任务注解。
- 调整优化。处理截屏函数的兼容性,优化URL的判断。
\ No newline at end of file
- 调整优化。处理截屏函数的兼容性,优化URL的判断。
- 系统地址获取方式改为读取config.json进行获取对应的环境信息。
\ No newline at end of file
......@@ -17,7 +17,7 @@ except ModuleNotFoundError as e:
def suite_setup():
STEP(1, "初始化浏览器")
# 传入系统类型,标准版 == 192.168.5.235
browser_init("标准版")
browser_init("标准版预定系统")
wd = GSTORE['wd']
admin_login("admin@ZDH", "Ubains@4321")
......
......@@ -8,9 +8,10 @@ import logging
"""
调试主机-执行指令:
1.打开一个终端输入:
- cd 预定系统
- cd .\预定系统\
- python -m http.server 80 --directory reports
2.打开新终端输入:
- cd .\预定系统\
- cd .\ngrok\ngrok-调试主机\
- .\start.bat
3.再打开一个终端输入:
......@@ -19,9 +20,10 @@ import logging
自动化运行虚拟机-执行指令:
1.打开一个终端输入:
- cd 预定系统
- cd .\预定系统\
- python -m http.server 81 --directory reports
2.打开新终端输入:
- cd .\预定系统\
- cd .\ngrok\ngrok-自动化运行虚拟机
- .\start.bat
3.再打开一个终端输入:
......@@ -69,7 +71,7 @@ def start_workers(num_workers):
start_workers(3)
# 定时执行预定系统测试任务
schedule.every().day.at("10:41").do(run_task, run_automation_test, report_title="预定系统测试报告", report_url_prefix="http://nat.ubainsyun.com:31134", test_case="后台管理功能", ding_type="标准版巡检")
schedule.every().day.at("08: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("07:50").do(run_task, run_automation_test, report_title="展厅巡检测试报告", report_url_prefix="http://nat.ubainsyun.com:31133", test_case="展厅巡检", ding_type="展厅巡检")
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论