Update test framework: fix run_tests.py to support all test files, add auto-import-check for test files

This commit is contained in:
qiaoxinjiu
2026-05-09 15:11:30 +08:00
parent eb053a347f
commit eaba8328da
21739 changed files with 2236758 additions and 719 deletions

View File

@@ -0,0 +1,4 @@
# -*- coding:utf-8 -*-
# @Time : 2023/7/7 13:37
# @Author: luozhipeng
# @File : __init__.py.py

View File

@@ -0,0 +1,228 @@
# -*- coding:utf-8 -*-
from airtest.core.api import *
import allure
import sys
LOCAL_PATH = os.path.dirname(os.path.abspath(__file__))
BASE_PROJECT_PATH = os.path.abspath(os.path.join(LOCAL_PATH, '../../../../../../../{}'.format("UBRD")))
BASIC_PATH = os.path.abspath(os.path.join(LOCAL_PATH, '../../../../../../../'))
sys.path.append(BASE_PROJECT_PATH)
sys.path.append(BASIC_PATH)
from ui_library.page.student.huohua.PC.view.view import View
from ui_library.page.student.huohua.PC.home.huohua_pc_home import HuohuaPCHome
from ui_library.page.student.huohua.PC.login.huohua_pc_login import HuohuaPCLogin
from library.CommonFun.host_update import HostUpdate,CoreApollo
from base_framework.public_tools.edu_user_helper import EDUUserHelper
from ui_library.page.student.huohua.PC.classroom.huohua_pc_classroom import HuohuaPCClassroom
import subprocess
import logging
import shutil
logger = logging.getLogger("airtest")
logger.setLevel(logging.ERROR)
host_update = HostUpdate()
obj_edu_user_helper = EDUUserHelper()
obj_core_apollo = CoreApollo()
@allure.feature('Huohua Student')
class TestHuohuaStudentLogin:
def setup(self):
self.host_list = []
file_path = r"C:\Users\Administrator\AppData\Roaming\peppa-app-pc-student-sim\db.json"
source_file = r"C:\Users\Administrator\AppData\Roaming\st-huohua\db.json"
if os.path.isfile(file_path):
os.remove(file_path)
shutil.copy(source_file, file_path)
subprocess.Popen(['C:\\Users\\Administrator\\AppData\\Local\\Programs\\peppa-app-pc-student-sim\\火花思维 - SIM版.exe'])
sleep(15)
auto_setup(__file__, logdir=True, devices=["Windows:///?title_re=.*火花思维学生端*"])
defalut_status = HuohuaPCHome().get_defalut_status()
if not defalut_status :
HuohuaPCHome().login_out()
def teardown(self):
# 清理域名屏蔽和指向
for i in self.host_list:
host_update.host_remove_intercept(i["ip"],i["host_name"])
os.system("ipconfig /flushdns")
subprocess.call(['taskkill', '/F', '/IM', '火花思维 - SIM版.exe'])
@allure.title("[国内学生端PC前端登录域名降级--001]")
def test_student_login_by_pwd_low_fe(self):
auto_setup(__file__, logdir=True, devices=["Windows:///?title_re=.*火花思维学生端*"])
with allure.step("清理客户端缓存"):
file_path = r"C:\Users\Administrator\AppData\Roaming\peppa-app-pc-student-sim\kmm_cache_db.json"
if os.path.isfile(file_path):
os.remove(file_path)
# with allure.step("点击用户默认头像"):
# HuohuaPCHome().click_defult_avatar()
with allure.step("清除前端缓存"):
View().input_console_command("window.localStorage.removeItem{(}'POP_STORAGE_TYPE'{)}")
with allure.step("点击通过密码登录"):
HuohuaPCLogin().click_by_pwd()
with allure.step("输入手机号"):
HuohuaPCLogin().input_phone("12345678001")
with allure.step("点击同意协议"):
HuohuaPCLogin().click_agree_label()
with allure.step("输入密码"):
HuohuaPCLogin().input_pwd("123456")
with allure.step("点击登录按钮"):
HuohuaPCLogin().click_login_button()
sleep(25)
#with allure.step("校验网络异常"):
# HuohuaPCLogin().assert_login_network_error()
with allure.step("点击登录按钮"):
default_status = HuohuaPCLogin().get_login_button()
if default_status:
HuohuaPCLogin().click_login_button()
sleep(25)
else:
print("已经登录进去了")
#with allure.step("校验网络异常"):
# HuohuaPCLogin().assert_login_network_error()
with allure.step("点击登录按钮"):
default_status = HuohuaPCLogin().get_login_button()
if default_status:
HuohuaPCLogin().click_login_button()
else:
print("已经登录进去了")
@allure.title("[国内学生端PC前端腾讯验证码降级--002]")
def test_student_login_by_pwd_low_ten(self):
with allure.step("添加验证码域名屏蔽并清理客户端缓存"):
self.host_list = [{"ip": "0.0.0.0", "host_name": "turing.captcha.qcloud.com"}]
host_update.host_update_by_host_dict(self.host_list)
host_update.wait_dns_flush(ip="0.0.0.0" ,domain= "turing.captcha.qcloud.com")
file_path = r"C:\Users\Administrator\AppData\Roaming\peppa-app-pc-student-sim\kmm_cache_db.json"
if os.path.isfile(file_path):
os.remove(file_path)
subprocess.call(['taskkill', '/F', '/IM', '火花思维 - SIM版.exe'])
subprocess.Popen(
['C:\\Users\\Administrator\\AppData\\Local\\Programs\\peppa-app-pc-student-sim\\火花思维 - SIM版.exe'])
sleep(15)
auto_setup(__file__, logdir=True, devices=["Windows:///?title_re=.*火花思维学生端*"])
defalut_status = HuohuaPCHome().get_defalut_status()
if not defalut_status:
HuohuaPCHome().login_out()
with allure.step("输入手机号"):
HuohuaPCLogin().input_phone("13460219197")
with allure.step("点击同意协议"):
HuohuaPCLogin().click_agree_label()
with allure.step("点击获取验证码"):
HuohuaPCLogin().click_get_code()
with allure.step("确认存在图形验证码的验证按钮"):
HuohuaPCLogin().assert_login_low_button()
@allure.title("[国内学生端PC前端腾讯验证码正常弹出--003]")
def test_student_login_by_pwd_ten(self):
with allure.step("清除客户端缓存"):
file_path = r"C:\Users\Administrator\AppData\Roaming\peppa-app-pc-student-sim\kmm_cache_db.json"
if os.path.isfile(file_path):
os.remove(file_path)
subprocess.call(['taskkill', '/F', '/IM', '火花思维 - SIM版.exe'])
subprocess.Popen(
['C:\\Users\\Administrator\\AppData\\Local\\Programs\\peppa-app-pc-student-sim\\火花思维 - SIM版.exe'])
sleep(15)
auto_setup(__file__, logdir=True, devices=["Windows:///?title_re=.*火花思维学生端*"])
with allure.step("点击用户默认头像"):
HuohuaPCHome().click_defult_avatar()
with allure.step("输入手机号"):
HuohuaPCLogin().input_phone("13460219197")
with allure.step("点击同意协议"):
HuohuaPCLogin().click_agree_label()
with allure.step("点击获取验证码"):
HuohuaPCLogin().click_get_code()
with allure.step("确认存在腾讯验证码的滑动按钮"):
HuohuaPCLogin().assert_login_tencent_image()
@allure.title("[国内学生端PC磐石登录成功--004]")
def test_student_login_by_pwd_normal(self):
with allure.step("清除客户端缓存"):
file_path = r"C:\Users\Administrator\AppData\Roaming\peppa-app-pc-student-sim\kmm_cache_db.json"
if os.path.isfile(file_path):
os.remove(file_path)
subprocess.call(['taskkill', '/F', '/IM', '火花思维 - SIM版.exe'])
subprocess.Popen(
['C:\\Users\\Administrator\\AppData\\Local\\Programs\\peppa-app-pc-student-sim\\火花思维 - SIM版.exe'])
sleep(15)
auto_setup(__file__, logdir=True, devices=["Windows:///?title_re=.*火花思维学生端*"])
with allure.step("清除前端缓存"):
View().input_console_command("window.localStorage.removeItem{(}'POP_STORAGE_TYPE'{)}")
with allure.step("点击用户默认头像"):
HuohuaPCHome().click_defult_avatar()
with allure.step("点击通过密码登录"):
HuohuaPCLogin().click_by_pwd()
with allure.step("输入手机号"):
HuohuaPCLogin().input_phone("13460219197")
with allure.step("点击同意协议"):
HuohuaPCLogin().click_agree_label()
with allure.step("输入密码"):
HuohuaPCLogin().input_pwd("123456")
with allure.step("点击登录按钮"):
HuohuaPCLogin().click_login_button()
sleep(20)
with allure.step("确认登录成功"):
HuohuaPCHome().assert_discover_button()
@allure.title("[国内学生端PCcheck备份域名强制登录进入课堂上课--005]")
def test_student_login_by_check(self):
with allure.step("添加域名重定向"):
self.host_list = [{"ip": "127.0.0.1", "host_name": "core-api.sim.huohua.cn"}]
host_update.host_update_by_host_dict(self.host_list)
host_update.wait_dns_flush(ip="127.0.0.1" ,domain= "core-api.sim.huohua.cn")
file_path = r"C:\Users\Administrator\AppData\Roaming\peppa-app-pc-student-sim\kmm_cache_db.json"
if os.path.isfile(file_path):
os.remove(file_path)
subprocess.call(['taskkill', '/F', '/IM', '火花思维 - SIM版.exe'])
subprocess.Popen(
['C:\\Users\\Administrator\\AppData\\Local\\Programs\\peppa-app-pc-student-sim\\火花思维 - SIM版.exe'])
sleep(15)
auto_setup(__file__, logdir=True, devices=["Windows:///?title_re=.*火花思维学生端*"])
defalut_status = HuohuaPCHome().get_defalut_status()
if not defalut_status:
HuohuaPCHome().login_out()
with allure.step("清除前端缓存"):
View().input_console_command("window.localStorage.removeItem{(}'POP_STORAGE_TYPE'{)}")
sleep(2)
with allure.step("输入手机号"):
HuohuaPCLogin().input_phone("15890630602")
with allure.step("点击同意协议"):
HuohuaPCLogin().click_agree_label()
with allure.step("点击获取验证码按钮"):
HuohuaPCLogin().click_get_code()
with allure.step("确认存在验证码提示"):
HuohuaPCLogin().assert_login_force_code_image()
sleep(2)
with allure.step("点击通过密码登录"):
HuohuaPCLogin().click_by_pwd()
with allure.step("输入手机号"):
HuohuaPCLogin().input_phone("15890630602")
with allure.step("输入密码"):
HuohuaPCLogin().input_pwd("123456")
# with allure.step("点击登录按钮"):
# HuohuaPCLogin().click_login_button()
# with allure.step("确认存在密码异常提示"):
# HuohuaPCLogin().assert_login_force_pwd_image()
# sleep(2)
sleep(2)
with allure.step("点击通过验证登录"):
HuohuaPCLogin().click_by_code()
with allure.step("输入验证码"):
HuohuaPCLogin().input_code("8888")
with allure.step("点击登录按钮"):
HuohuaPCLogin().click_login_button()
sleep(5)
with allure.step("点击进入课堂按钮"):
HuohuaPCHome().click_enter_classroom()
sleep(120)
with allure.step("成功进入课堂"):
HuohuaPCClassroom.check_classroom_icon()
if __name__ == '__main__':
TestHuohuaStudentLogin().test_student_login_by_pwd_low_ten()

View File

@@ -0,0 +1,231 @@
# -*- coding:utf-8 -*-
from airtest.core.api import *
import allure
import sys
LOCAL_PATH = os.path.dirname(os.path.abspath(__file__))
BASE_PROJECT_PATH = os.path.abspath(os.path.join(LOCAL_PATH, '../../../../../../../{}'.format("UBRD")))
BASIC_PATH = os.path.abspath(os.path.join(LOCAL_PATH, '../../../../../../../'))
sys.path.append(BASE_PROJECT_PATH)
sys.path.append(BASIC_PATH)
from ui_library.page.student.huohua.PC.view.view import View
from ui_library.page.student.huohua.PC.home.huohua_pc_home import HuohuaPCHome
from ui_library.page.student.huohua.PC.login.huohua_pc_login import HuohuaPCLogin
from library.CommonFun.host_update import HostUpdate,CoreApollo
from base_framework.public_tools.edu_user_helper import EDUUserHelper
from ui_library.page.student.huohua.PC.classroom.huohua_pc_classroom import HuohuaPCClassroom
import subprocess
import logging
import shutil
logger = logging.getLogger("airtest")
logger.setLevel(logging.ERROR)
host_update = HostUpdate()
obj_edu_user_helper = EDUUserHelper()
obj_core_apollo = CoreApollo()
import time
def assert_with_retry(assertion_func, retries=5, delay=1):
found = False
for i in range(retries):
try:
assertion_func()
found = True
return # If the assertion_func() call doesn't raise an exception, exit the function
except AssertionError:
if i < retries - 1: # If this isn't the last retry
time.sleep(delay) # Wait for a while before retrying
if not found:
raise Exception("Network error message not found after n attempts")
@allure.feature('Huohua Student Online')
class TestHuohuaStudentLogin:
def setup(self):
self.host_list = []
file_path = r"C:\Users\Administrator\AppData\Roaming\huohua-learner-client\db.json"
source_file = r"C:\Users\Administrator\AppData\Roaming\on_huohua\db.json"
if os.path.isfile(file_path):
os.remove(file_path)
shutil.copy(source_file, file_path)
subprocess.Popen(['C:\\Users\\Administrator\\AppData\\Local\\Programs\\huohua-learner-client\\火花思维.exe'])
sleep(15)
auto_setup(__file__, logdir=True, devices=["Windows:///?title_re=.*火花思维学生端*"])
defalut_status = HuohuaPCHome().get_defalut_status()
if not defalut_status :
HuohuaPCHome().login_out()
def teardown(self):
# 清理域名屏蔽和指向
for i in self.host_list:
host_update.host_remove_intercept(i["ip"],i["host_name"])
os.system("ipconfig /flushdns")
subprocess.call(['taskkill', '/F', '/IM', '火花思维.exe'])
@allure.title("[国内学生端PC前端登录域名降级--001]")
def test_student_login_by_pwd_low_fe(self):
auto_setup(__file__, logdir=True, devices=["Windows:///?title_re=.*火花思维学生端*"])
with allure.step("清理客户端缓存"):
file_path = r"C:\Users\Administrator\AppData\Roaming\huohua-learner-client\kmm_cache_db.json"
if os.path.isfile(file_path):
os.remove(file_path)
#with allure.step("点击用户默认头像"):
# HuohuaPCHome().click_defult_avatar()
with allure.step("清除前端缓存 域名重新轮询"):
View().input_console_command("window.localStorage.removeItem{(}'POP_STORAGE_TYPE'{)}")
with allure.step("点击通过密码登录"):
HuohuaPCLogin().click_by_pwd()
with allure.step("输入手机号"):
HuohuaPCLogin().input_phone("12345678001")
with allure.step("点击同意协议"):
HuohuaPCLogin().click_agree_label()
with allure.step("输入密码"):
HuohuaPCLogin().input_pwd("123456")
sleep(2)
with allure.step("第一次点击登录按钮"):
HuohuaPCLogin().click_login_button()
sleep(5)
with allure.step("第二次点击登录按钮"):
HuohuaPCLogin().get_login_button()
sleep(10)
with allure.step("第三次点击登录按钮"):
HuohuaPCLogin().get_login_button()
sleep(10)
with allure.step("第四次点击登录按钮"):
default_status = HuohuaPCLogin().get_login_button()
if default_status:
HuohuaPCLogin().click_login_button()
sleep(10)
else:
print("已经登录进去了")
@allure.title("[国内学生端PC前端腾讯验证码降级--002]")
def test_student_login_by_pwd_low_ten(self):
with allure.step("添加验证码域名屏蔽并清理客户端缓存"):
self.host_list = [{"ip": "0.0.0.0", "host_name": "turing.captcha.qcloud.com"}]
host_update.host_update_by_host_dict(self.host_list)
host_update.wait_dns_flush(ip="0.0.0.0" ,domain= "turing.captcha.qcloud.com")
file_path = r"C:\Users\Administrator\AppData\Roaming\huohua-learner-client\kmm_cache_db.json"
if os.path.isfile(file_path):
os.remove(file_path)
subprocess.call(['taskkill', '/F', '/IM', '火花思维.exe'])
subprocess.Popen(
['C:\\Users\\Administrator\\AppData\\Local\\Programs\\huohua-learner-client\\火花思维.exe'])
sleep(10)
auto_setup(__file__, logdir=True, devices=["Windows:///?title_re=.*火花思维学生端*"])
defalut_status = HuohuaPCHome().get_defalut_status()
if not defalut_status:
HuohuaPCHome().login_out()
# with allure.step("点击用户默认头像"):
# HuohuaPCHome().click_defult_avatar()
with allure.step("输入手机号"):
HuohuaPCLogin().input_phone("18333586570")
with allure.step("点击同意协议"):
HuohuaPCLogin().click_agree_label()
with allure.step("点击获取验证码"):
HuohuaPCLogin().click_get_code()
with allure.step("确认存在图形验证码的验证按钮"):
HuohuaPCLogin().assert_login_low_button()
@allure.title("[国内学生端PC前端腾讯验证码正常弹出--003]")
def test_student_login_by_pwd_ten(self):
with allure.step("清除客户端缓存"):
file_path = r"C:\Users\Administrator\AppData\Roaming\huohua-learner-client\kmm_cache_db.json"
if os.path.isfile(file_path):
os.remove(file_path)
subprocess.call(['taskkill', '/F', '/IM', '火花思维.exe'])
subprocess.Popen(
['C:\\Users\\Administrator\\AppData\\Local\\Programs\\huohua-learner-client\\火花思维.exe'])
sleep(10)
auto_setup(__file__, logdir=True, devices=["Windows:///?title_re=.*火花思维学生端*"])
defalut_status = HuohuaPCHome().get_defalut_status()
if not defalut_status:
HuohuaPCHome().login_out()
#with allure.step("点击用户默认头像"):
# HuohuaPCHome().click_defult_avatar()
with allure.step("点击同意协议"):
HuohuaPCLogin().click_agree_label()
with allure.step("输入手机号"):
HuohuaPCLogin().input_phone("18333586570")
with allure.step("点击获取验证码"):
HuohuaPCLogin().click_get_code()
with allure.step("确认存在腾讯验证码的滑动按钮"):
HuohuaPCLogin().assert_login_tencent_image()
@allure.title("[国内学生端PC磐石登录成功--004]")
def test_student_login_by_pwd_normal(self):
with allure.step("清除客户端缓存"):
file_path = r"C:\Users\Administrator\AppData\Roaming\huohua-learner-client\kmm_cache_db.json"
if os.path.isfile(file_path):
os.remove(file_path)
subprocess.call(['taskkill', '/F', '/IM', '火花思维.exe'])
subprocess.Popen(
['C:\\Users\\Administrator\\AppData\\Local\\Programs\\huohua-learner-client\\火花思维.exe'])
sleep(10)
auto_setup(__file__, logdir=True, devices=["Windows:///?title_re=.*火花思维学生端*"])
defalut_status = HuohuaPCHome().get_defalut_status()
if not defalut_status:
HuohuaPCHome().login_out()
with allure.step("清除前端缓存"):
View().input_console_command("window.localStorage.removeItem{(}'POP_STORAGE_TYPE'{)}")
with allure.step("点击用户默认头像"):
HuohuaPCHome().click_defult_avatar()
with allure.step("点击通过密码登录"):
HuohuaPCLogin().click_by_pwd()
with allure.step("输入手机号"):
HuohuaPCLogin().input_phone("18333586570")
with allure.step("点击同意协议"):
HuohuaPCLogin().click_agree_label()
with allure.step("输入密码"):
HuohuaPCLogin().input_pwd("123456")
with allure.step("点击登录按钮"):
HuohuaPCLogin().click_login_button()
sleep(10)
with allure.step("确认登录成功"):
HuohuaPCHome().assert_discover_button()
@allure.title("[国内学生端PCcheck备份域名强制登录进入课堂上课--005]")
def test_student_login_by_check(self):
with allure.step("添加域名重定向到降级域名"):
self.host_list = [{"ip": "127.0.0.1", "host_name": "core-api.huohua.cn"}]
host_update.host_update_by_host_dict(self.host_list)
host_update.wait_dns_flush(ip="127.0.0.1" ,domain= "core-api.huohua.cn")
file_path = r"C:\Users\Administrator\AppData\Roaming\huohua-learner-client\kmm_cache_db.json"
if os.path.isfile(file_path):
os.remove(file_path)
subprocess.call(['taskkill', '/F', '/IM', '火花思维.exe'])
subprocess.Popen(
['C:\\Users\\Administrator\\AppData\\Local\\Programs\\huohua-learner-client\\火花思维.exe'])
sleep(10)
auto_setup(__file__, logdir=True, devices=["Windows:///?title_re=.*火花思维学生端*"])
defalut_status = HuohuaPCHome().get_defalut_status()
if not defalut_status:
HuohuaPCHome().login_out()
with allure.step("清除前端缓存"):
View().input_console_command("window.localStorage.removeItem{(}'POP_STORAGE_TYPE'{)}")
with allure.step("点击用户默认头像"):
HuohuaPCHome().click_defult_avatar()
#with allure.step("点击通过验证登录"):
# HuohuaPCLogin().click_by_code()
with allure.step("点击同意协议"):
HuohuaPCLogin().click_agree_label()
with allure.step("输入手机号"):
HuohuaPCLogin().input_phone("15890630602")
with allure.step("输入验证码"):
HuohuaPCLogin().input_code("8888")
with allure.step("点击登录按钮"):
HuohuaPCLogin().click_login_button()
sleep(5)
with allure.step("点击进入课堂按钮"):
HuohuaPCHome().click_enter_classroom()
sleep(100)
with allure.step("成功进入课堂"):
HuohuaPCClassroom.check_classroom_icon()
if __name__ == '__main__':
TestHuohuaStudentLogin().test_student_login_by_pwd_low_ten()