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

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

上级 bc3495b9
...@@ -3,8 +3,6 @@ import glob ...@@ -3,8 +3,6 @@ import glob
import re import re
import urllib import urllib
from selenium.webdriver.chrome.service import Service from selenium.webdriver.chrome.service import Service
import numpy as np
import requests
import json import json
import hmac import hmac
import hashlib import hashlib
...@@ -13,19 +11,12 @@ import psutil ...@@ -13,19 +11,12 @@ import psutil
import time import time
import subprocess import subprocess
import logging import logging
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service as ChromeService
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
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 import expected_conditions as EC
from urllib.parse import urlencode from urllib.parse import urlencode
from datetime import datetime 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__)) current_dir = os.path.dirname(os.path.abspath(__file__))
...@@ -44,10 +35,6 @@ logging.basicConfig( ...@@ -44,10 +35,6 @@ logging.basicConfig(
] ]
) )
# 配置日志
# logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
def browser_init(login_type): def browser_init(login_type):
""" """
初始化浏览器设置和实例。 初始化浏览器设置和实例。
...@@ -90,17 +77,25 @@ def browser_init(login_type): ...@@ -90,17 +77,25 @@ def browser_init(login_type):
# 设置隐式等待时间为10秒,以允许元素加载 # 设置隐式等待时间为10秒,以允许元素加载
wd.implicitly_wait(60) wd.implicitly_wait(60)
# 请求WebDriver打开登录页面 # 获取当前脚本的绝对路径
login_url = "" current_dir = os.path.dirname(os.path.abspath(__file__))
# 判断初始化的系统类型 # 构建配置文件的绝对路径
if login_type == "标准版": config_path = os.path.join(current_dir, '..', 'Base', 'config.json')
login_url = 'https://192.168.5.235/#/login/lgindf' logging.info(f"配置文件路径: {config_path}")
elif login_type == "展厅预定巡检":
login_url = "http://192.168.5.200/#/login/logindf" # 检查文件是否存在
elif login_type == "展厅运维巡检": if not os.path.exists(config_path):
login_url = "http://192.168.5.200:8081/#/login" raise FileNotFoundError(f"配置文件 {config_path} 不存在")
elif login_type == "展厅统一平台巡检":
login_url = "http://192.168.5.200:38083/#/login" # 读取配置文件
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) wd.get(login_url)
...@@ -116,6 +111,7 @@ def browser_init(login_type): ...@@ -116,6 +111,7 @@ def browser_init(login_type):
logging.error(f"浏览器初始化失败:{e}") logging.error(f"浏览器初始化失败:{e}")
def admin_login(username, password): 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
...@@ -177,3 +177,4 @@ ...@@ -177,3 +177,4 @@
42. 2025-01-16 42. 2025-01-16
- 优化browser_init初始化函数的传参方式以及系统环境判断处理。优化ngrok以及定时任务注解。 - 优化browser_init初始化函数的传参方式以及系统环境判断处理。优化ngrok以及定时任务注解。
- 调整优化。处理截屏函数的兼容性,优化URL的判断。 - 调整优化。处理截屏函数的兼容性,优化URL的判断。
- 系统地址获取方式改为读取config.json进行获取对应的环境信息。
\ No newline at end of file
...@@ -17,7 +17,7 @@ except ModuleNotFoundError as e: ...@@ -17,7 +17,7 @@ except ModuleNotFoundError as e:
def suite_setup(): def suite_setup():
STEP(1, "初始化浏览器") STEP(1, "初始化浏览器")
# 传入系统类型,标准版 == 192.168.5.235 # 传入系统类型,标准版 == 192.168.5.235
browser_init("标准版") browser_init("标准版预定系统")
wd = GSTORE['wd'] wd = GSTORE['wd']
admin_login("admin@ZDH", "Ubains@4321") admin_login("admin@ZDH", "Ubains@4321")
......
...@@ -8,9 +8,10 @@ import logging ...@@ -8,9 +8,10 @@ import logging
""" """
调试主机-执行指令: 调试主机-执行指令:
1.打开一个终端输入: 1.打开一个终端输入:
- cd 预定系统 - cd .\预定系统\
- python -m http.server 80 --directory reports - python -m http.server 80 --directory reports
2.打开新终端输入: 2.打开新终端输入:
- cd .\预定系统\
- cd .\ngrok\ngrok-调试主机\ - cd .\ngrok\ngrok-调试主机\
- .\start.bat - .\start.bat
3.再打开一个终端输入: 3.再打开一个终端输入:
...@@ -19,9 +20,10 @@ import logging ...@@ -19,9 +20,10 @@ import logging
自动化运行虚拟机-执行指令: 自动化运行虚拟机-执行指令:
1.打开一个终端输入: 1.打开一个终端输入:
- cd 预定系统 - cd .\预定系统\
- python -m http.server 81 --directory reports - python -m http.server 81 --directory reports
2.打开新终端输入: 2.打开新终端输入:
- cd .\预定系统\
- cd .\ngrok\ngrok-自动化运行虚拟机 - cd .\ngrok\ngrok-自动化运行虚拟机
- .\start.bat - .\start.bat
3.再打开一个终端输入: 3.再打开一个终端输入:
...@@ -69,7 +71,7 @@ def start_workers(num_workers): ...@@ -69,7 +71,7 @@ def start_workers(num_workers):
start_workers(3) 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="展厅巡检") # 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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论