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/10/11 14:32
# @Author: luozhipeng
# @File : __init__.py.py

View File

@@ -0,0 +1,202 @@
from airtest.core.api import *
import logging
import allure
import os
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 base_framework.public_tools.apollo import Apollo
from library.CommonFun.host_update import HostUpdate,CoreApollo
from ui_library.page.student.spark.PC.login.spark_pc_login import SparkPCLogin
from ui_library.page.student.spark.PC.home.spark_pc_home import SparkPCHome
from ui_library.page.student.spark.PC.classroom.spark_pc_classroom import SparkPCClassroom
import subprocess
import shutil
logger = logging.getLogger("airtest")
logger.setLevel(logging.ERROR)
host_update = HostUpdate()
obj_core_apollo = CoreApollo()
@allure.feature('Spark Student')
class TestSparkStudentLogin:
def setup(self):
self.host_list = []
# 打开APP
# nginx = subprocess.Popen(['C:\\Users\\Administrator\\Downloads\\nginx-1.24.0\\nginx.exe', '-p', '.'], cwd=r"C:\Users\Administrator\Downloads\nginx-1.24.0")
file_path = r"C:\Users\Administrator\AppData\Roaming\overseas-pc-student-sim\db.json"
source_file = r"C:\Users\Administrator\AppData\Roaming\st-oversea\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\\overseas-pc-student-sim\\SparkMath学生端 - SIM.exe'])
sleep(20)
auto_setup(__file__, logdir=True, devices=["Windows:///?title_re=.*Spark Education*"])
SparkPCHome().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', 'SparkMath学生端 - SIM.exe'])
# subprocess.call(['taskkill', '/F', '/IM', 'nginx.exe'])
@allure.title("[海外学生端PC前端域名降级--001]")
def test_student_login_by_pwd_low_fe(self):
auto_setup(__file__, logdir=True, devices=["Windows:///?title_re=.*Spark Education*"])
with allure.step("清理客户端缓存"):
file_path = r"C:\Users\Administrator\AppData\Roaming\overseas-pc-student-sim\kmm_cache_db.json"
if os.path.isfile(file_path):
os.remove(file_path)
with allure.step("清除前端缓存"):
View().input_console_command("await{ }window._NATIVE.localStorage.removeItem{(}'POP_STORAGE_TYPE'{)}")
with allure.step("点击密码登录"):
sleep(5)
SparkPCLogin().click_via_pwd()
with allure.step("输入手机号12345678001"):
SparkPCLogin().input_user_phone("12345678001")
with allure.step("输入密码123456"):
SparkPCLogin().input_user_pwd("123456")
with allure.step("点击同意协议"):
SparkPCLogin().click_agree_label()
with allure.step("点击登录按钮"):
SparkPCLogin().click_login_button()
sleep(15)
with allure.step("确认登录成功"):
default_status = SparkPCLogin().get_login_button()
if default_status:
SparkPCLogin().click_login_button()
sleep(10)
sleep(10)
SparkPCHome().check_spark_icon()
@allure.title("[海外学生端PC腾讯验证码降级--002]")
def test_student_login_low_ten(self):
with allure.step("添加域名屏蔽"):
self.host_list = [{"ip": "1.1.1.1", "host_name": "turing.captcha.qcloud.com"}]
host_update.host_update_by_host_dict(self.host_list)
host_update.wait_dns_flush(ip="1.1.1.1" ,domain= "turing.captcha.qcloud.com")
file_path = r"C:\Users\Administrator\AppData\Roaming\overseas-pc-student-sim\kmm_cache_db.json"
if os.path.isfile(file_path):
os.remove(file_path)
subprocess.call(['taskkill', '/F', '/IM', 'SparkMath学生端 - SIM.exe'])
subprocess.Popen(
['C:\\Users\\Administrator\\AppData\\Local\\Programs\\overseas-pc-student-sim\\SparkMath学生端 - SIM.exe'])
sleep(20)
auto_setup(__file__, logdir=True, devices=["Windows:///?title_re=.*Spark Education*"])
SparkPCHome().login_out()
with allure.step("清除前端缓存"):
View().input_console_command("await{ }window._NATIVE.localStorage.removeItem{(}'POP_STORAGE_TYPE'{)}")
with allure.step("输入手机号13460219197"):
SparkPCLogin().input_user_phone("13460219197")
with allure.step("点击同意协议"):
SparkPCLogin().click_agree_label()
with allure.step("点击获取验证码"):
SparkPCLogin().click_get_code()
sleep(10)
with allure.step("确认不存在腾讯验证码"):
SparkPCLogin().assert_no_tencent_button()
@allure.title("[海外学生端PC腾讯验证码正常流程--003]")
def test_student_login_normal_ten(self):
with allure.step("清除客户端缓存"):
file_path = r"C:\Users\Administrator\AppData\Roaming\overseas-pc-student-sim\kmm_cache_db.json"
if os.path.isfile(file_path):
os.remove(file_path)
subprocess.call(['taskkill', '/F', '/IM', 'SparkMath学生端 - SIM.exe'])
subprocess.Popen(
['C:\\Users\\Administrator\\AppData\\Local\\Programs\\overseas-pc-student-sim\\SparkMath学生端 - SIM.exe'])
sleep(20)
auto_setup(__file__, logdir=True, devices=["Windows:///?title_re=.*Spark Education*"])
SparkPCHome().login_out()
with allure.step("清除前端缓存"):
View().input_console_command("await{ }window._NATIVE.localStorage.removeItem{(}'POP_STORAGE_TYPE'{)}")
with allure.step("输入手机号13460219197"):
SparkPCLogin().input_user_phone("13460219197")
with allure.step("点击同意协议"):
SparkPCLogin().click_agree_label()
with allure.step("点击获取验证码"):
SparkPCLogin().click_get_code()
sleep(10)
with allure.step("确认存在腾讯验证码"):
SparkPCLogin().assert_exist_tencent_button()
@allure.title("[海外学生端PC磐石登录成功--004]")
def test_student_login_by_pwd_normal(self):
with allure.step("清除客户端缓存"):
file_path = r"C:\Users\Administrator\AppData\Roaming\overseas-pc-student-sim\kmm_cache_db.json"
if os.path.isfile(file_path):
os.remove(file_path)
subprocess.call(['taskkill', '/F', '/IM', 'SparkMath学生端 - SIM.exe'])
subprocess.Popen(
['C:\\Users\\Administrator\\AppData\\Local\\Programs\\overseas-pc-student-sim\\SparkMath学生端 - SIM.exe'])
sleep(10)
auto_setup(__file__, logdir=True, devices=["Windows:///?title_re=.*Spark Education*"])
with allure.step("清除前端缓存"):
View().input_console_command("await{ }window._NATIVE.localStorage.removeItem{(}'POP_STORAGE_TYPE'{)}")
with allure.step("点击密码登录"):
sleep(5)
SparkPCLogin().click_via_pwd()
with allure.step("输入手机号13460219197"):
SparkPCLogin().input_user_phone("13460219197")
with allure.step("输入密码123456"):
SparkPCLogin().input_user_pwd("123456")
sleep(1)
with allure.step("点击同意协议"):
SparkPCLogin().click_agree_label()
with allure.step("点击登录按钮"):
SparkPCLogin().click_login_button()
sleep(5)
with allure.step("确认登录成功"):
default_status = SparkPCLogin().get_login_button()
if default_status:
SparkPCLogin().click_login_button()
sleep(10)
SparkPCHome().check_spark_icon()
@allure.title("[海外学生端PC强制验证码登录进入课堂上课--005]")
def test_student_join_classroom_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\overseas-pc-student-sim\kmm_cache_db.json"
if os.path.isfile(file_path):
os.remove(file_path)
subprocess.call(['taskkill', '/F', '/IM', 'SparkMath学生端 - SIM.exe'])
subprocess.Popen(
['C:\\Users\\Administrator\\AppData\\Local\\Programs\\overseas-pc-student-sim\\SparkMath学生端 - SIM.exe'])
sleep(20)
auto_setup(__file__, logdir=True, devices=["Windows:///?title_re=.*Spark Education*"])
SparkPCHome().login_out()
with allure.step("清除前端缓存"):
View().input_console_command("await{ }window._NATIVE.localStorage.removeItem{(}'POP_STORAGE_TYPE'{)}")
sleep(2)
with allure.step("输入手机号15890630602"):
SparkPCLogin().input_user_phone("15890630602")
with allure.step("点击同意协议"):
SparkPCLogin().click_agree_label()
with allure.step("点击输入验证码"):
SparkPCLogin().input_user_code("8888")
with allure.step("点击登录按钮"):
SparkPCLogin().click_login_by_code()
sleep(5)
with allure.step("确认登录成功"):
SparkPCHome().check_spark_icon()
sleep(8)
with allure.step("点击进入课堂按钮"):
SparkPCHome().click_enter_class_button()
sleep(15)
with allure.step("检查课堂内宝箱图标"):
SparkPCClassroom.check_classroom_star_box()
if __name__ == '__main__':
TestSparkStudentLogin().test_student_login_by_pwd_low_fe()

View File

@@ -0,0 +1,189 @@
from airtest.core.api import *
import logging
import allure
import os
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 base_framework.public_tools.apollo import Apollo
from library.CommonFun.host_update import HostUpdate,CoreApollo
from ui_library.page.student.spark.PC.login.spark_pc_login import SparkPCLogin
from ui_library.page.student.spark.PC.home.spark_pc_home import SparkPCHome
from ui_library.page.student.spark.PC.classroom.spark_pc_classroom import SparkPCClassroom
import subprocess
import shutil
logger = logging.getLogger("airtest")
logger.setLevel(logging.ERROR)
host_update = HostUpdate()
obj_core_apollo = CoreApollo()
@allure.feature('Spark Student')
class TestSparkStudentLogin:
def setup(self):
self.host_list = []
# 打开APP
# nginx = subprocess.Popen(['C:\\Users\\Administrator\\Downloads\\nginx-1.24.0\\nginx.exe', '-p', '.'], cwd=r"C:\Users\Administrator\Downloads\nginx-1.24.0")
file_path = r"C:\Users\Administrator\AppData\Roaming\sparkedu-learner-client\db.json"
source_file = r"C:\Users\Administrator\AppData\Roaming\on_spark\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\\sparkedu-learner-client\\SparkMath学生端.exe'])
sleep(20)
auto_setup(__file__, logdir=True, devices=["Windows:///?title_re=.*Spark Education*"])
SparkPCHome().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', 'SparkMath学生端.exe'])
# subprocess.call(['taskkill', '/F', '/IM', 'nginx.exe'])
@allure.title("[海外学生端PC前端域名降级--001]")
def test_student_login_by_pwd_low_fe(self):
auto_setup(__file__, logdir=True, devices=["Windows:///?title_re=.*Spark Education*"])
with allure.step("添加域名屏蔽"):
file_path = r"C:\Users\Administrator\AppData\Roaming\sparkedu-learner-client\kmm_cache_db.json"
if os.path.isfile(file_path):
os.remove(file_path)
with allure.step("清除前端缓存 域名重新轮询"):
View().input_console_command("await{ }window._NATIVE.localStorage.removeItem{(}'POP_STORAGE_TYPE'{)}")
with allure.step("点击密码登录"):
SparkPCLogin().click_via_pwd()
with allure.step("输入手机号12345678001"):
SparkPCLogin().input_user_phone("12345678001")
with allure.step("输入密码123456"):
SparkPCLogin().input_user_pwd_online("123456")
sleep(5)
with allure.step("点击同意协议"):
SparkPCLogin().click_agree_label()
with allure.step("第一次点击登录按钮"):
SparkPCLogin().click_login_button()
sleep(5)
with allure.step("第二次点击登录按钮"):
SparkPCLogin().click_login_button()
sleep(10)
with allure.step("第三次点击登录按钮"):
SparkPCLogin().click_login_button()
sleep(10)
with allure.step("确认登录成功"):
SparkPCHome().check_spark_icon()
@allure.title("[海外学生端PC腾讯验证码降级--002]")
def test_student_login_low_ten(self):
with allure.step("添加域名屏蔽"):
self.host_list = [{"ip": "1.1.1.1", "host_name": "turing.captcha.qcloud.com"}]
host_update.host_update_by_host_dict(self.host_list)
host_update.wait_dns_flush(ip="1.1.1.1" ,domain= "turing.captcha.qcloud.com")
file_path = r"C:\Users\Administrator\AppData\Roaming\sparkedu-learner-client\kmm_cache_db.json"
if os.path.isfile(file_path):
os.remove(file_path)
subprocess.call(['taskkill', '/F', '/IM', 'SparkMath学生端.exe'])
subprocess.Popen(
['C:\\Users\\Administrator\\AppData\\Local\\Programs\\sparkedu-learner-client\\SparkMath学生端.exe'])
sleep(20)
auto_setup(__file__, logdir=True, devices=["Windows:///?title_re=.*Spark Education*"])
with allure.step("清除前端缓存"):
View().input_console_command("await{ }window._NATIVE.localStorage.removeItem{(}'POP_STORAGE_TYPE'{)}")
with allure.step("输入手机号18333586570"):
SparkPCLogin().input_user_phone("18333586570")
with allure.step("点击同意协议"):
SparkPCLogin().click_agree_label()
with allure.step("点击获取验证码"):
SparkPCLogin().click_get_code()
with allure.step("确认不存在腾讯验证码"):
SparkPCLogin().assert_no_tencent_button()
@allure.title("[海外学生端PC腾讯验证码正常流程--003]")
def test_student_login_normal_ten(self):
auto_setup(__file__, logdir=True, devices=["Windows:///?title_re=.*Spark Education*"])
file_path = r"C:\Users\Administrator\AppData\Roaming\sparkedu-learner-client\kmm_cache_db.json"
if os.path.isfile(file_path):
os.remove(file_path)
with allure.step("清除前端缓存"):
View().input_console_command("await{ }window._NATIVE.localStorage.removeItem{(}'POP_STORAGE_TYPE'{)}")
with allure.step("输入手机号18333586570"):
SparkPCLogin().input_user_phone("18333586570")
with allure.step("点击同意协议"):
SparkPCLogin().click_agree_label()
with allure.step("点击获取验证码"):
SparkPCLogin().click_get_code()
with allure.step("确认存在腾讯验证码"):
SparkPCLogin().assert_exist_tencent_button()
@allure.title("[海外学生端PC磐石登录成功--004]")
def test_student_login_by_pwd_normal(self):
with allure.step("添加域名屏蔽"):
file_path = r"C:\Users\Administrator\AppData\Roaming\sparkedu-learner-client\kmm_cache_db.json"
if os.path.isfile(file_path):
os.remove(file_path)
with allure.step("清除前端缓存"):
View().input_console_command("await{ }window._NATIVE.localStorage.removeItem{(}'POP_STORAGE_TYPE'{)}")
with allure.step("点击密码登录"):
sleep(2)
SparkPCLogin().click_via_pwd()
sleep(3)
with allure.step("输入手机号18333586570"):
SparkPCLogin().input_user_phone("18333586570")
with allure.step("输入密码123456"):
SparkPCLogin().input_user_pwd_online("123456")
sleep(5)
with allure.step("点击同意协议"):
SparkPCLogin().click_agree_label()
with allure.step("点击登录按钮"):
SparkPCLogin().click_login_button()
sleep(5)
with allure.step("确认登录成功"):
default_status = SparkPCLogin().get_login_button()
if default_status:
SparkPCLogin().click_login_button()
sleep(10)
SparkPCHome().check_spark_icon()
@allure.title("[海外学生端PC强制验证码登录进入课堂上课--005]")
def test_student_join_classroom_check(self):
with allure.step("添加域名重定向"):
self.host_list = [{"ip": "127.0.0.1", "host_name": "core-api.sparkeduapi.com"}]
host_update.host_update_by_host_dict(self.host_list)
host_update.wait_dns_flush(ip="127.0.0.1" ,domain= "core-api.sparkeduapi.com")
file_path = r"C:\Users\Administrator\AppData\Roaming\sparkedu-learner-client\kmm_cache_db.json"
if os.path.isfile(file_path):
os.remove(file_path)
subprocess.call(['taskkill', '/F', '/IM', 'SparkMath学生端.exe'])
subprocess.Popen(
['C:\\Users\\Administrator\\AppData\\Local\\Programs\\sparkedu-learner-client\\SparkMath学生端.exe'])
sleep(10)
auto_setup(__file__, logdir=True, devices=["Windows:///?title_re=.*Spark Education*"])
SparkPCHome().login_out()
with allure.step("清除前端缓存"):
View().input_console_command("await{ }window._NATIVE.localStorage.removeItem{(}'POP_STORAGE_TYPE'{)}")
with allure.step("输入手机号15890630602"):
SparkPCLogin().input_user_phone("15890630602")
with allure.step("点击同意协议"):
SparkPCLogin().click_agree_label()
with allure.step("点击输入验证码"):
SparkPCLogin().input_user_code("8888")
with allure.step("点击登录按钮"):
SparkPCLogin().click_login_by_code()
sleep(5)
with allure.step("确认登录成功"):
SparkPCHome().check_spark_icon()
sleep(10)
with allure.step("点击进入课堂按钮"):
SparkPCHome().click_enter_class_button()
sleep(20)
with allure.step("检查课堂内宝箱图标"):
SparkPCClassroom.check_classroom_star_box()
if __name__ == '__main__':
TestSparkStudentLogin().test_student_login_by_pwd_low_fe()