def start_test(self): test_suite = unittest.TestSuite() loader = unittest.TestLoader() for value in self.test_case_data.values(): tests_case = loader.loadTestsFromName(value) test_suite.addTests(tests_case) file_path = Utility.create_path_by_time() with open(file_path, 'w') as file: runner = HTMLTestRunner(stream=file, verbosity=2) runner.run(test_suite)
import unittest from parameterized import parameterized from woniuBoss.lib.resource import ResourceAPI from woniuBoss.tools.utility import Utility test_data_conf_path = '../conf/testdata.json' base_conf_path = '../conf/base.json' # base_conf_data = Utility.get_json(base_conf_path) test_data_json = Utility.get_json(test_data_conf_path) basic_test_data = Utility.get_excel_dict_tup_list( test_data_json['resource_basic_api']) class ResourceTest(unittest.TestCase): @classmethod def setUpClass(cls) -> None: cls.resource = ResourceAPI(base_conf_path) @classmethod def tearDownClass(cls) -> None: cls.resource.session.close() @parameterized.expand(basic_test_data) def test_01_decode_resource(self, test_data): if test_data['method'] == 'GET': test_resp = self.resource.get_request(test_data) test_resp_code = test_resp.status_code if str(test_resp_code) == '200': actual_status = ''
import unittest from parameterized import parameterized from woniuBoss.lib.student import StudentApi from woniuBoss.tools.utility import Utility test_data_conf_path = '../conf/testdata.json' base_conf_path = '../conf/base.json' # base_conf_data = Utility.get_json(base_conf_path) test_data_json = Utility.get_json(test_data_conf_path) basic_test_data = Utility.get_excel_dict_tup_list( test_data_json['student_basic_api']) decode_test_data = Utility.get_excel_dict_tup_list( test_data_json['student_decode_api']) often_test_data = Utility.get_excel_dict_tup_list( test_data_json['student_often_api']) morningtest_test_data = Utility.get_excel_dict_tup_list( test_data_json['student_morningtest_api']) query_leave_test_data = Utility.get_excel_dict_tup_list( test_data_json['student_query_leave_api']) save_leave_test_data = Utility.get_excel_dict_tup_list( test_data_json['student_save_leave_api']) attend_result_test_data = Utility.get_excel_dict_tup_list( test_data_json['student_attend_result_api']) stage_test_test_data = Utility.get_excel_dict_tup_list( test_data_json['student_stage_test_api']) exam_record_test_data = Utility.get_excel_dict_tup_list( test_data_json['student_exam_record_api']) manage_class_test_data = Utility.get_excel_dict_tup_list( test_data_json['student_manage_class_api'])
# 该模块封装与登陆有关的测试 from selenium.webdriver.common.by import By from woniuBoss.lib.login import Login from woniuBoss.tools.service import Service from woniuBoss.tools.utility import Utility import unittest from parameterized import parameterized # 获取登陆用的测试数据的配置 test_conf = Utility.get_json('../conf/testdata.json') # 通过配置获取登陆数据 login_info = Utility.get_excel_dict_tup_list(test_conf["login"]) # # 1.获取测试数据 2。 对每条数据执行 # # 3.实际结果actual与与其结果进行对比,如果一致则测试通过 class LoginTest(unittest.TestCase): @classmethod def setUpClass(cls) -> None: conf_path = '../conf/base.json' cls.driver = Service.get_driver(conf_path) Service.open_page(cls.driver, conf_path) @classmethod def tearDownClass(cls) -> None: cls.driver.quit() def setUp(self) -> None:
import unittest from parameterized import parameterized from woniuBoss.lib.login import LoginApi from woniuBoss.tools.utility import Utility test_data_conf = '../conf/testdata.json' base_conf = '../conf/base.json' test_data_conf = Utility.get_json(test_data_conf) login_test_data = Utility.get_excel_dict_tup_list(test_data_conf['login_api']) # print(login_test_data) class LoginTest(unittest.TestCase): @classmethod def setUpClass(cls) -> None: pass def setUp(self) -> None: self.logIn = LoginApi() def tearDown(self) -> None: self.logIn.session.close() @parameterized.expand(login_test_data) def test_login(self, login_data): print(login_data) login_resp = self.logIn.do_login(login_data) login_resp_code = login_resp.status_code
def __init__(self): self.test_case_data = Utility.get_json('../conf/test_case_ui.json')
def input_upass(self, driver, password): upass = driver.find_element_by_css_selector('input[name=userPass]') Utility.send_input(upass, password)
def input_uname(self, driver, username): uname = driver.find_element_by_css_selector('input[name=userName]') Utility.send_input(uname, username)
def input_student_number(self, driver, student_No): subcode_input_ele = driver.find_element_by_css_selector('input[name=stuNo]') Utility.send_input(subcode_input_ele, student_No)
def input_subcode(self, driver, subcode): subcode_input_ele = driver.find_element_by_css_selector('input[name=secondPass]') Utility.send_input(subcode_input_ele, subcode)
# 该模块封装与登陆有关的测试 import time import unittest from parameterized import parameterized from selenium import webdriver from selenium.webdriver.common.by import By from woniuBoss.lib.login import Login from woniuBoss.lib.student import Student from woniuBoss.tools.service import Service from woniuBoss.tools.utility import Utility test_conf = Utility.get_json('../conf/testdata.json') student_basic_decode_data = Utility.get_excel_dict_tup_list( test_conf["student_basic_decode_ui"]) student_basic_search_name_data = Utility.get_excel_dict_tup_list( test_conf["student_basic_search_name_ui"]) conf_path = '../conf/base.json' login_data = { "userName": "******", "userPass": "******", } # driver = Service.get_driver(conf_path) # Service().open_page(driver,conf_path) # Login().do_login(driver, data_dic=login_data) # time.sleep(1) # Service().open_page(driver, conf_path, page='student')