def get_session(cls, sum): base_info = Utility.get_json('..\\config\\base.conf') login_url = "%s://%s:%s/%s/" % ( base_info['PROTOCOL'], base_info['HOSTNAME'], base_info['PORT'], base_info['AURL'],) # print(login_url) base_data = Utility.get_json('..\\config\\Account.conf') login_data = {'userName': base_data[sum]['userName'], 'userPass': base_data[sum]['userPass'], 'checkcode': base_data[sum]['checkcode']} # print(login_data) session = requests.session() resp = session.post(login_url, login_data) # print(resp.text) return session
def test_login(self,base_config_path,data_config_path): # 思路:1.获取测试数据;2.遍历执行每一条测试数据得到运行结果; # 3.实际结果actual与预期结果进行对比,如果一直证明测试通过,否则测试不通过提交缺陷 # 获取所有的登录用到的测试数据及预期结果 data_config_info = Utility.get_json(data_config_path) login_info = Utility.get_excel(data_config_info[0]) for login_data in login_info: Login(self.driver).do_login(base_config_path,login_data) # 判断登录是否成功,同时得到实际结果actual from selenium.webdriver.common.by import By from tools.service import Service if Service.is_element_present(self.driver, By.LINK_TEXT, '注销'): actual = 'login-pass' self.driver.find_element_by_link_text('注销').click() time.sleep(2) else: actual = 'login-fail' time.sleep(2) self.driver.refresh() # 对结果进行断言 flag = Utility.assert_equals(actual,login_data['expect']) if flag: print('test pass') else: print('test fail')
def get_driver(cls, base_config_path): contents = Utility.get_json(base_config_path) from selenium import webdriver driver = getattr(webdriver, contents['BROWSER'])() driver.implicitly_wait(10) driver.maximize_window() return driver
def miss_login(cls, driver, base_config_path): cls.open_page(driver, base_config_path) # 通过字典方式传递cookie信息 contents = Utility.get_json(base_config_path) driver.add_cookie({'name': 'username', 'value': contents['username']}) driver.add_cookie({'name': 'password', 'value': contents['password']}) cls.open_page(driver, base_config_path)
class TransmitRescourcesTest(unittest.TestCase): #获取转交资源的测试数据 contents = Utility.get_json('../conf/yang/public_rescources_testinfo.conf') transmit_info=Utility.tran_tuple(contents[2]) # print(transmit_info) @classmethod def setUpClass(cls): warnings.simplefilter('ignore', ResourceWarning) def setUp(self): self.driver=Service.get_driver('../conf/yang/base.conf') self.driver.implicitly_wait(15) self.driver.maximize_window() #使用管理员进行登录,进入转交责任人 Service.ignor_login_decrypt(self.driver,'../conf/yang/base_admin.conf') self.tran=TransmitRescources(self.driver) def tearDown(self): self.driver.quit() @classmethod def tearDownClass(cls): pass # 测试查询 @parameterized.expand(transmit_info) def test_do_transmit_rescources(self,area_text_value,dpt_text_value,empname_text_value, \ status_text_value, source_text_value,name_text_value,transmit_area_value, transmit_dpt_value,transmit_empname_value,expect ): transmit_rescources_info={ "area_text_value":area_text_value,"dpt_text_value": dpt_text_value, "empname_text_value": empname_text_value,"status_text_value": status_text_value, "source_text_value": source_text_value,'name_text_value':name_text_value, "transmit_area_value": transmit_area_value,"transmit_dpt_value": transmit_dpt_value,"transmit_empname_value": transmit_empname_value} old_num=self.tran.do_query_rescources(transmit_rescources_info) # print(old_num) #随机执行分配 self.tran.do_transmit_rescources(int(old_num),transmit_rescources_info) # #再次执行搜索 new_num = self.tran.do_query_rescources(transmit_rescources_info) # print(new_num) time.sleep(2) if int(old_num) - int(new_num): actual='transmit-success' else: actual='transmit-fail' self.assertEqual(actual,expect)
class OverallTest(unittest.TestCase): # 获取测试数据 contents = Utility.get_json('../conf/peng/testinfo.conf') print(contents[0]) query_week_info = Utility.tran_tuple(contents[8]) print(query_week_info) @classmethod def setUpClass(cls): pass def setUp(self): self.driver = Service.get_driver("../conf/peng/base.conf") self.driver.implicitly_wait(10) self.score = OverallScore(self.driver) def tearDown(self): self.driver.close() @classmethod def tearDownClass(cls): pass @parameterized.expand(query_week_info) def test_query_score(self, s_area, s_name, s_stage, s_direction, s_sclass, expect): query_week_data = { "s_area": s_area, "s_name": s_name, "s_stage": s_stage, "s_direction": s_direction, "s_sclass": s_sclass } self.score.query_score(query_week_data) time.sleep(2) if Service.is_element_present(self.driver, By.CSS_SELECTOR, ".no-records-found > td:nth-child(1)"): actual = "none" else: num = self.score.get_student_total() if int(num) > 0: actual = "query-success" else: actual = "query-fail" self.assertEqual(actual, expect)
class MarketingTest(unittest.TestCase): # 获取测试数据 contents = Utility.get_json('../conf/yun/testinfo.conf') add_marketing_info = Utility.tran_tuple(contents[0]) @classmethod def setUpClass(cls): warnings.simplefilter('ignore', ResourceWarning) def setUp(self): self.driver = Service.get_driver('../conf/yun/base.conf') self.driver.implicitly_wait(15) from lib.marketing import Marketing self.mar = Marketing(self.driver) self.old_total = self.mar.total(self.driver) # 测试增加 @parameterized.expand(add_marketing_info) def test_add(self, region_id, department_id, tel, name, sex, last_status, wechat, qq, school, education, major, workage, age, source, eduexp, experience, last_tracking_remark, expect): add_info = {"cus.region_id": region_id, "cus.department_id": department_id, "cus.tel": tel, "cus.name": name, "cus.sex": sex, "cus.last_status": last_status, "cus.wechat": wechat, "cus.qq": qq, "cus.school": school, "cus.education": education, "cus.major": major, "cus.workage": workage, "cus.age": age, "cus.source": source, "cus.eduexp": eduexp, "cus.experience": experience, "cus.last_tracking_remark": last_tracking_remark, } self.mar.do_add(self.driver, add_info) # self.driver.refresh() # 执行数据后,点击搜索 new_total = self.mar.total(self.driver) if new_total != self.old_total: actual = 'success' else: actual = 'fail' self.assertEqual(actual, expect) def tearDown(self): self.driver.close() @classmethod def tearDownClass(cls): pass
class TechnicalInterviewTest(unittest.TestCase): # 获取测试数据 contents = Utility.get_json('../conf/huang/testinfo.conf') # 获取技术面试的测试数据 add_interview_info = Utility.tran_tuple(contents[4]) @classmethod def setUpClass(cls): warnings.simplefilter('ignore', ResourceWarning) def setUp(self): self.driver = Service.get_driver('../conf/huang/base.conf') self.driver.implicitly_wait(10) self.driver.maximize_window() Service.ignor_login_decrypt(self.driver, '../conf/huang/base.conf') self.ti = TechnicalInterview(self.driver) def tearDown(self): self.driver.quit() @classmethod def tearDownClass(cls): pass # 测试面试 @parameterized.expand(add_interview_info) def test_add_interview(self, outcome, evaluate, expect): add_interview_info = {"outcome": outcome, "evaluate": evaluate} self.ti.do_interview(add_interview_info) # 获取面试的随机值 # studentnum = self.ti.click_interview() outcome_list = Service.get_page_ele( self.driver, '//*[@id="stuInfo_table"]/tbody/tr[1]/td[8]') # print(studentnum) # print(outcome_list) if outcome in outcome_list: actual = 'add-success' else: actual = 'add-fail' self.assertEqual(actual, expect)
class LoginTest(unittest.TestCase): content = Utility.get_json('../conf/yang/testinfo.conf') login_info = Utility.tran_tuple(content[0]) @classmethod def setUpClass(cls): warnings.simplefilter('ignore', ResourceWarning) def setUp(self): self.driver = Service.get_driver('../conf/yang/base.conf') self.driver.implicitly_wait(15) self.driver.maximize_window() from lib.login import Login self.login = Login(self.driver) def tearDown(self): self.driver.close() @classmethod def tearDownClass(cls): pass #测试登录 @parameterized.expand(login_info) def test_login(self, uname, psword, code, expect): self.login.do_login(uname, psword, code, '../conf/yang/base.conf') # time.sleep(25) from selenium.webdriver.common.by import By #如果存在注销链接 time.sleep(3) if Service.is_element_present(self.driver, By.PARTIAL_LINK_TEXT, "修改密码"): actual = "login-success" #退出系统 self.login.click_logout() else: actual = "login-fail" time.sleep(1) # Utility.get_error_png(self.driver) self.assertEqual(actual, expect)
from selenium.webdriver.common.by import By from lib.finance_manage import FinanceManage from tools.service import Service from tools.utility import Utility from parameterized import parameterized import unittest import time query_flow_datas = Utility.get_json("../config/testdata.conf") query_data = Utility.get_excel_GUI_tuple(query_flow_datas[1]) class TestLogin(unittest.TestCase): def setUp(self): self.driver = Service.get_driver('../config/base.conf') Service.open_page(self.driver, '../config/base.conf') self.finance = FinanceManage(self.driver) def tearDown(self): time.sleep(2) self.driver.quit() # 测试查询按钮 @parameterized.expand(query_data) def test_login(self, one_subject, two_subject,expect): contents = {'one_subject': one_subject, 'two_subject': two_subject} self.finance.finance_query(contents) # 断言
import unittest from parameterized import parameterized from lib.interview import InterViewApi from tools.utility import Utility test_data_conf_path = '../conf/testdata.json' base_conf = '../conf/base_jiang.json' test_data = Utility.get_json(test_data_conf_path) Inter_test_data = Utility.get_excel_dict_tup_list(test_data["interview_api"]) print(Inter_test_data) class InterViewTest(unittest.TestCase): def setUp(self) -> None: self.Inter = InterViewApi(base_conf) def tearDown(self) -> None: pass @parameterized.expand(Inter_test_data) def test_inter(self, inter_data): inter_resp = self.Inter.do_interview(inter_data) inter_resp_code = inter_resp.status_code inter_resp_content = inter_resp.text print(inter_resp_code) actual = inter_resp_content expect = inter_data['expect'] # print(actual) # print(expect)
class PublicRescourcesTest(unittest.TestCase): #获取查询公共池的数据 contents = Utility.get_json('../conf/yang/public_rescources_testinfo.conf') query_public_info = Utility.tran_tuple(contents[0]) #获取废弃的数据 claim_public_info = Utility.tran_tuple(contents[1]) # print(claim_public_info) @classmethod def setUpClass(cls): warnings.simplefilter('ignore', ResourceWarning) def setUp(self): self.driver = Service.get_driver('../conf/yang/base.conf') self.driver.implicitly_wait(15) self.driver.maximize_window() Service.ignor_login_decrypt(self.driver, '../conf/yang/base.conf') from lib.public_rescources import PublicRescources self.pu = PublicRescources(self.driver) def tearDown(self): self.driver.close() @classmethod def tearDownClass(cls): pass #测试搜索 @parameterized.expand(query_public_info) # @unittest.skip("忽略搜索") def test_do_query_public(self,area_value,dpt_value,abandoned_value,status_value,source_value ,\ education_value,name_value,expect): query_public_info = { "area_value": area_value, 'dpt_value': dpt_value, 'abandoned_value': abandoned_value, 'status_value': status_value, 'source_value': source_value, 'education_value': education_value, 'name_value': name_value } driver = self.driver self.pu.do_query_public(query_public_info) time.sleep(4) #获取页面元素 num = Service.get_num( driver, '//*[@id="content"]/div[3]/div/div[1]/div[2]/div[4]/div[1]/span[1]' ) print(num) if int(num) > 0: actual = 'query-success' else: actual = 'query-fail' self.assertEqual(actual, expect) #测试认领 @parameterized.expand(claim_public_info) def test_do_claim_rescources(self, temp, expect): #获取此生页面显示数量 time.sleep(2) old_num = Service.get_num( self.driver, '//*[@id="content"]/div[3]/div/div[1]/div[2]/div[4]/div[1]/span[1]' ) self.pu.do_claim_rescources(int(old_num)) #点击默认搜索 self.driver.refresh() self.pu.click_public_query() time.sleep(2) new_num = Service.get_num( self.driver, '//*[@id="content"]/div[3]/div/div[1]/div[2]/div[4]/div[1]/span[1]' ) if int(old_num) - int(new_num) == 1: actual = 'claim-success' else: actual = 'claim-fail' self.assertEqual(actual, expect)
class ApplicationForExtraWorkTest(unittest.TestCase): # 获取测试数据 contents = Utility.get_json('../conf/huang/testinfo.conf') # 获取加班申请的测试数据 add_overtime_info = Utility.tran_tuple(contents[7]) print(add_overtime_info) @classmethod def setUpClass(cls): warnings.simplefilter('ignore', ResourceWarning) def setUp(self): self.driver = Service.get_driver('../conf/huang/base.conf') self.driver.implicitly_wait(10) self.driver.maximize_window() Service.ignor_login_decrypt(self.driver, '../conf/huang/base.conf') self.afew = ApplicationForExtraWork(self.driver) def tearDown(self): # pass self.driver.quit() @classmethod def tearDownClass(cls): pass #测试值班申请 @parameterized.expand(add_overtime_info) def test_add_overtime(self, start_time, end_time, accounting, hours, region, reason, expect): add_overtime_info = { "start_time": start_time, "end_time": end_time, "accounting": accounting, "hours": hours, "region": region, "reason": reason } overtime_info = { "start_js": "document.querySelector(\"#addApply-form > div > div > div:nth-child(2) > div:nth-child(1) > input\")", "end_js": "document.querySelector(\"#addApply-form > div > div > div:nth-child(2) > div:nth-child(2) > input\")", "start_time": "2020-05-10 09:30", "end_time": "2020-05-10 11:30", "accounting": "结算工资", "hours": "2小时", "region": "成都", "reason": "没钱要赚更多的钱买买买" } # print(add_overtime_info) self.afew.do_overtime(add_overtime_info) reason_list = Service.get_page_ele( self.driver, '//*[@id="apply-table"]/tbody/tr[1]/td[7]/span') if reason in reason_list: actual = 'add-success' else: actual = 'add-fail' self.assertEqual(actual, expect)
class StudentTest(unittest.TestCase): # 获取测试数据 contents = Utility.get_json('../conf/peng/testinfo.conf') print(contents[0]) query_student_info = Utility.tran_tuple(contents[0]) print(query_student_info) edit_student_info = Utility.tran_tuple(contents[1]) @classmethod def setUpClass(cls): pass def setUp(self): self.driver = Service.get_driver("../conf/peng/base.conf") self.driver.implicitly_wait(10) self.student = Student(self.driver) def tearDown(self): self.driver.close() @classmethod def tearDownClass(cls): pass @parameterized.expand(query_student_info) # @unittest.skip("忽略查询学员") def test_query_student(self, area, sname, state, direction, sclass, expect): query_student_data = { "s_area": area, "s_name": sname, "s_state": state, "s_direction": direction, "s_sclass": sclass } self.student.query_student(query_student_data) time.sleep(2) num = self.student.get_student_total() if int(num) > 0: actual = "query-success" else: actual = "query-fail" self.assertEqual(actual, expect) @parameterized.expand(edit_student_info) def test_edit_student(self, edit_name, edit_state, edit_tel, edit_source, expect): edit_student_data = { "edit_name": edit_name, "edit_state": edit_state, "edit_tel": edit_tel, "edit_source": edit_source } self.student.do_edit_student(edit_student_data) # 进行搜索 self.driver.refresh() time.sleep(2) self.student.input_name(edit_name) self.student.click_query_button() list = [] contents = self.driver.find_elements_by_xpath( "/html/body/div[8]/div[2]/div/div/div/div[2]/div[2]/div[2]/table/tbody/tr/td[6]" ) for content in contents: list.append(content.text) if edit_state in list: actual = "edit-success" else: actual = "edit-fail" self.assertEqual(actual, expect)
class serviceTest(unittest.TestCase): # 获取测试数据 contents = Utility.get_json('../conf/yun/testinfo.conf') #班级管理查询 management_query_info = Utility.tran_tuple(contents[1]) # 班级管理新增 management_add_info = Utility.tran_tuple(contents[2]) #学员考勤 confirm = Utility.tran_tuple(contents[3]) #学员请假查询 leave_query = Utility.tran_tuple(contents[4]) #学员请假修改 change_leave = Utility.tran_tuple(contents[5]) #学员请假新增 add_leave = Utility.tran_tuple(contents[6]) #学员转班 change_class = Utility.tran_tuple(contents[7]) @classmethod def setUpClass(cls): warnings.simplefilter('ignore', ResourceWarning) def setUp(self): self.driver = Service.get_driver('../conf/yun/base.conf') self.driver.implicitly_wait(15) self.cla = Class_service(self.driver) # 测试班级管理查询 @parameterized.expand(management_query_info) #@unittest.skip("忽略增加") def test_query_data(self, regionId, status, expect): query_data_info = {"regionId": regionId, "status": status} self.cla.do_query(query_data_info) total = Service.get_num( self.driver, '//*[@id="cmDiv"]/div[2]/div[2]/div[4]/div[1]/span[1]') if total != 0: actual = 'success' else: actual = 'fail' self.assertEqual(actual, expect) # 测试班级管理查询 @parameterized.expand(management_add_info) #@unittest.skip("忽略增加") def test_add_data(self, class_no, orientation, opening_time, class_headmaster_id, expect): add_data_info = { "c.class_no": class_no, "c.orientation": orientation, "c.opening_time": opening_time, "c.class_headmaster_id": class_headmaster_id } old_total = self.cla.do_add(add_data_info) import time time.sleep(2) new_total = Service.get_num( self.driver, '//*[@id="cmDiv"]/div[2]/div[2]/div[4]/div[1]/span[1]') if new_total != old_total: actual = 'success' else: actual = 'fail' self.assertEqual(actual, expect) #测试考勤 @parameterized.expand(confirm) #@unittest.skip("忽略增加") def test_confirm_data(self, attendance, expect): confirm_data_info = {"attendance": attendance} old_total = self.cla.do_confirm(confirm_data_info) import time time.sleep(2) new_total = Service.get_kaoqin( self.driver, '/html/body/div[8]/div[2]/div/div/div/div[3]/div/div/div/div[1]/div[2]/div/div[1]/div[2]/div[2]/table/tbody/tr[1]/td[7]' ) if new_total != old_total: actual = 'success' else: actual = 'fail' self.assertEqual(actual, expect) #学员请假查询 @parameterized.expand(leave_query) #@unittest.skip("忽略增加") def test_confirm_data(self, region_id, leave_status, expect): confirm_data_info = { "region_id": region_id, "leave_status": leave_status } old_total = self.cla.do_leave_query(confirm_data_info) import time time.sleep(2) new_total = Service.get_num( self.driver, '//*[@id="content"]/div[2]/div/div/div/div[2]/div[2]/div[4]/div[1]/span[1]' ) if new_total != old_total: actual = 'success' else: actual = 'fail' self.assertEqual(actual, expect) # 学员请假修改动作 @parameterized.expand(change_leave) #@unittest.skip("忽略增加") def test_change_leave_data(self, stuName, reason, expect): change_leave_data_info = {"sl.stuName": stuName, "sl.reason": reason} old_text = self.cla.change_leave(change_leave_data_info) import time time.sleep(2) new_text = self.driver.find_element_by_xpath( '/html/body/div[8]/div[2]/div/div/div/div[2]/div[2]/div[2]/table/tbody/tr/td[4]/span' ).text if new_text != old_text: actual = 'success' else: actual = 'fail' self.assertEqual(actual, expect) # 学员请假新增动作 @parameterized.expand(add_leave) #@unittest.skip("忽略增加") def test_add_leave_data(self, start_time, end_time, leave_type, days, stuName, leave_count, reason, comment, expect): add_leave_data_info = { "sl.start_time": start_time, "sl.end_time": end_time, "sl.leave_type": leave_type, "sl.days": days, "sl.stuName": stuName, "sl.leave_count": leave_count, "sl.reason": reason, "sl.comment": comment } old_tatol = self.cla.change_leave(add_leave_data_info) import time time.sleep(2) new_tatol = Service.get_num( self.driver, '//*[@id="content"]/div[2]/div/div/div/div[2]/div[2]/div[4]/div[1]/span[1]' ) if new_tatol != old_tatol: actual = 'success' else: actual = 'fail' self.assertEqual(actual, expect) # 学员转班 @parameterized.expand(change_class) #@unittest.skip("忽略增加") def test_change_class_data(self, regionId, stuClass, expect): change_class_info = {"regionId": regionId, "stuClass": stuClass} old_text = self.cla.do_change_class(change_class_info) import time time.sleep(2) new_text = self.driver.find_element_by_xpath( '/html/body/div[8]/div[2]/div/div/div/div[2]/div[2]/div[2]/table/tbody/tr[1]/td[4]' ).text if new_text != old_text: actual = 'success' else: actual = 'fail' self.assertEqual(actual, expect) def tearDown(self): self.driver.close() @classmethod def tearDownClass(cls): pass
def open_page(cls, driver, path): contents = Utility.get_json(path) URL = '%s://%s:%s/%s' % (contents['PROTOCOL'], contents['HOSTNAME'], contents['PORT'], contents['AURL']) # print(URL) driver.get(URL)
from selenium.webdriver.common.by import By from lib.login import Login from tools.service import Service from tools.utility import Utility from parameterized import parameterized import unittest import time login_datas = Utility.get_json("../config/testdata.conf") login_data = Utility.get_excel_GUI_tuple(login_datas[0]) class TestLogin(unittest.TestCase): def setUp(self): self.driver = Service.get_driver('../config/base.conf') Service.open_page(self.driver, '../config/base.conf') self.login = Login(self.driver) def tearDown(self): time.sleep(2) self.driver.quit() # 测试登录功能 @parameterized.expand(login_data) def test_login(self, login_userName, login_userPASS, login_checkcode, login_expect): contents = {'username': login_userName, 'password': login_userPASS, 'checkcode': login_checkcode} self.login.excute_login(contents)
class CouresArrangementTest(unittest.TestCase): #获取测试数据 contents = Utility.get_json('../conf/huang/testinfo.conf') # 获取添加的测试数据 add_course_info = Utility.tran_tuple(contents[1]) #获取查询的测试数据 query_course_info = Utility.tran_tuple(contents[2]) #获取修改的测试数据 alter_course_info = Utility.tran_tuple(contents[3]) @classmethod def setUpClass(cls): warnings.simplefilter('ignore', ResourceWarning) def setUp(self): self.driver = Service.get_driver('../conf/huang/base.conf') self.driver.implicitly_wait(10) self.driver.maximize_window() Service.ignor_login_decrypt(self.driver, '../conf/huang/base.conf') self.ca = CourseArrangement(self.driver) def tearDown(self): self.driver.quit() @classmethod def tearDownClass(cls): pass #测试增加 @parameterized.expand(add_course_info) @unittest.skip('fa') def test_add_course(self, start_time, end_time, teacher, classroom, classcode, course, expect): add_course_info = { "start_time": start_time, "end_time": end_time, "teacher": teacher, "classroom": classroom, "classcode": classcode, "course": course } self.ca.do_add_course(add_course_info) # 执行测试后搜索 self.ca.do_query(self.ca.query_all_course_info) teacher_list = Service.get_page_ele( self.driver, '//*[@id="course_table"]/tbody/tr[1]/td[1]') if teacher in teacher_list: actual = 'add-success' else: actual = 'add-fail' self.assertEqual(actual, expect) # 测试查询 @parameterized.expand(query_course_info) @unittest.skip('fa') def test_query_coure(self, campus, teacher, speialty, start_tiame, end_tiame, expect): query_all_course_info = { 'campus': campus, 'teacher': teacher, 'specialty': speialty, 'start_time': start_tiame, 'end_time': end_tiame } self.ca.do_query(query_all_course_info) query_num = Service.get_num( self.driver, '//*[@id="course"]/div[2]/div[2]/div[4]/div[1]/span[1]') if int(query_num) > 0: actual = 'query-success' else: actual = 'query-fail' self.assertEqual(actual, expect) # 测试修改 @parameterized.expand(alter_course_info) def test_alter_course(self, start_time, end_time, teacher, classroom, classcode, course, expect): alter_course_info = { "start_time": start_time, "end_time": end_time, "teacher": teacher, "classroom": classroom, "classcode": classcode, "course": course } self.ca.do_alter_course(alter_course_info) # classnum = self.ca.click_alter() teacher_list = Service.get_page_ele( self.driver, f'//*[@id="course_table"]/tbody/tr[1]/td[1]') if teacher in teacher_list: actual = 'alter-success' else: actual = 'alter-fail' self.assertEqual(actual, expect)
class WeekMarkTest(unittest.TestCase): # 获取测试数据 contents = Utility.get_json('../conf/peng/testinfo.conf') print(contents[0]) query_week_info = Utility.tran_tuple(contents[2]) print(query_week_info) import_week_info = Utility.tran_tuple(contents[3]) import_week_info_plus = Utility.tran_tuple(contents[4]) @classmethod def setUpClass(cls): pass def setUp(self): self.driver = Service.get_driver("../conf/peng/base.conf") self.driver.implicitly_wait(10) self.week = WeekMark(self.driver) def tearDown(self): self.driver.close() @classmethod def tearDownClass(cls): pass @parameterized.expand(query_week_info) # @unittest.skip("忽略查询") def test_query_week(self, s_name, s_area, s_sclass, expect): query_week_data = { "s_name": s_name, "s_area": s_area, "s_sclass": s_sclass } self.week.query_mark(query_week_data) time.sleep(2) num = self.week.get_student_total() if int(num) > 0: actual = "query-success" else: actual = "query-fail" self.assertEqual(actual, expect) @parameterized.expand(import_week_info) # @unittest.skip("忽略录用") def test_import_week(self, s_sclass, stage, week, score, expect): import_week_data = { "s_sclass": s_sclass, "stage": stage, "week": week, "score": score } self.week.do_week_mark(import_week_data) if Service.is_element_present(self.driver, By.XPATH, "/html/body/div[11]/div/div/div[1]/h4"): actual = "import-fail" else: actual = "import-success" self.assertEqual(actual, expect) @parameterized.expand(import_week_info_plus) # @unittest.skip("") def test_import_week_two(self, s_sclass, stage, week, file, expect): import_week_data_plus = { "s_sclass": s_sclass, "stage": stage, "week": week, "file": file } self.week.do_import(import_week_data_plus) time.sleep(2) if Service.is_element_present( self.driver, By.CSS_SELECTOR, ".bootbox > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > h4:nth-child(2)" ): actual = "import-fail" else: actual = "import-success" self.assertEqual(actual, expect)
class TeacherOnDutyTest(unittest.TestCase): # 获取测试数据 contents = Utility.get_json('../conf/huang/testinfo.conf') # 获取新增教师值班的测试数据 add_duty_info = Utility.tran_tuple(contents[5]) # 获取修改教室值班的数据 alter_duty_info = Utility.tran_tuple(contents[6]) @classmethod def setUpClass(cls): warnings.simplefilter('ignore',ResourceWarning) def setUp(self): self.driver = Service.get_driver('../conf/huang/base.conf') self.driver.implicitly_wait(10) self.driver.maximize_window() Service.ignor_login_decrypt(self.driver,'../conf/huang/base.conf') self.tod = TeacherOnDuty(self.driver) def tearDown(self): self.driver.quit() @classmethod def tearDownClass(cls): pass # 测试新增值班 @parameterized.expand(add_duty_info) def test_add_duty(self,teacher,duty_time,expect): add_duty_info = {"teacher":teacher,"duty_time":duty_time} self.tod.do_add_duty(add_duty_info) teachername_list = Service.get_page_ele(self.driver,'//*[@id="duty_table"]/tbody/tr[1]/td[2]') print(teacher) print(teachername_list) if teacher in teachername_list: actual = 'add-success' else: actual = 'add-fail' self.assertEqual(actual,expect) #测试修改值班 @parameterized.expand(alter_duty_info) def test_alter_duty(self,teacher,duty_time,expect): alter_duty_info = {"teacher": teacher,"duty_time": duty_time} # 执行修改 self.tod.do_alter_duty(alter_duty_info) #获取修改的随机数 alternum = self.tod.click_alter() # 获取界面老师名字元素 teachername_list = Service.get_page_ele(self.driver, f'//*[@id="duty_table"]/tbody/tr[{alternum}]/td[2]') if teacher in teachername_list: actual = 'alter-success' else: actual = 'alter-fail' self.assertEqual(actual, expect)