def verification_modify_result(self, modify_ele, modif_path, expect): Service.get_tier_ele(modify_ele, By.XPATH, modif_path).click() # 姓名框 modify_name_ele = Service.get_ele( self.driver, By.CSS_SELECTOR, "#modifyForm > div > div:nth-child(2) > div.col-md-8.col-sm-6.col-xs-6 > " "div.col-md-6.col-sm-8.col-xs-8.form-group > input") # 在姓名后输入日期 current_time = Service.format_date() current_content = Service.input_value_date_ele(modify_name_ele, current_time) # 点击 保存 Service.get_ele( self.driver, By.CSS_SELECTOR, "#form-modify > div > div > div.modal-footer > button").click() # 修改完成,用修改后的姓名,查询一次 TraineesManagement.name_input_query(self.driver, current_content) TraineesManagement.basic_information_query_ele(self.driver) if Service.get_ele(self.driver, By.CSS_SELECTOR, "#stuInfo_table > tbody > tr > td:nth-child(1)" ).text == current_content: actual = "basic-pass" else: actual = "basic-fail" self.assertEqual(actual, expect)
def verification_check_result(self, check_ele, check_path): Service.get_tier_ele(check_ele, By.CSS_SELECTOR, check_path).click() # 判断 查看功能 if Service.is_Element_present(self.driver, By.CSS_SELECTOR, "#seeStuInfo-modal > div > div"): # 关闭页面 Service.get_ele( self.driver, By.CSS_SELECTOR, "#seeStuInfo-modal > div > div > div.modal-header > button > span:nth-child(1)" ).click() else: print("查看功能出错") self.driver.quit()
def test_common_resource_pool(self, query_info, expect): # cookie self.common_resource_pool_init() # 调用查询操作 CommonResourcePool.common_resource_pool_query(self.driver, query_info) # 先记录,当前查询条件下,学生人数 common_resource_one_result = self.verification_common_resource_pool_result( self.driver) # 学生数量不为 0 if int(common_resource_one_result) != 0: # 判断学生数量 一页数据大于10,分页 if int(common_resource_one_result) > 10: # 翻页功能 page_count_ele = Service.get_eles( self.driver, By.CSS_SELECTOR, "#content > div.con-body > div > div.bootstrap-table > div.fixed-table-container > " "div.fixed-table-pagination > div.pull-right.pagination > ul li" ) # 选择最后一页 Service.get_tier_ele( page_count_ele[len(page_count_ele) - 1 - 1], By.TAG_NAME, "a").click() # 校验显示是否正确 query_count_result_again = Service.get_ele( self.driver, By.XPATH, "//span[@class='pagination-info']").text result_again = re.match('^显示.*到.*?(\d+)', query_count_result_again).group(1) if int(result_again) == int(common_resource_one_result): pass else: print("翻页功能异常") self.driver.close() # 当前页展示信息个数 query_result_count = Service.get_eles( self.driver, By.XPATH, "//table[@id='public-pool-table']/tbody/tr") # 选中第一个 Service.get_tier_ele( query_result_count[0], By.XPATH, "//table[@id='public-pool-table']/tbody/tr[1]/td[1]/input" ).click() # 本页最后一个 css_count = "#public-pool-table > tbody:nth-child(2) > tr:nth-child(%d) > td:nth-child(1) > input:nth-child(1)" % ( len(query_result_count)) time.sleep(2) Service.get_tier_ele( query_result_count[len(query_result_count) - 1], By.CSS_SELECTOR, css_count).click() # 不分页 elif int(common_resource_one_result) > 1: # 当前页展示信息个数 query_result_count = Service.get_eles( self.driver, By.XPATH, "//table[@id='public-pool-table']/tbody/tr") # 选中第一个 Service.get_tier_ele( query_result_count[0], By.XPATH, "//table[@id='public-pool-table']/tbody/tr[1]/td[1]/input" ).click() # 本页最后一个 css_count = "#public-pool-table > tbody:nth-child(2) > tr:nth-child(%d) > td:nth-child(1) > input:nth-child(1)" % ( len(query_result_count)) time.sleep(2) Service.get_tier_ele( query_result_count[len(query_result_count) - 1], By.CSS_SELECTOR, css_count).click() # 一条数据 else: # 当前页展示信息个数 query_result_count = Service.get_ele( self.driver, By.XPATH, "//table[@id='public-pool-table']/tbody/tr") # 选中第一个 Service.get_tier_ele( query_result_count, By.XPATH, "//table[@id='public-pool-table']/tbody/tr[1]/input" ).click() else: print("当前条件下,查询数据为空") self.driver.quit() time.sleep(3) # 执行认领 操作 CommonResourcePool.common_resource_pool_claim(self.driver) Service.get_ele(self.driver, By.CSS_SELECTOR, "button.btn-primary:nth-child(2)").click() time.sleep(1) self.driver.refresh() # 二次验证判断,提交到的人或区域的学生人数 # 查询 CommonResourcePool.common_resource_pool_query(self.driver, query_info) common_resource_two_result = self.verification_common_resource_pool_result( self.driver) # print(int(common_resource_one_result)) # print(int(common_resource_two_result)) if int(common_resource_one_result) > int(common_resource_two_result): actual = "common-resource-pass" else: actual = "common-resource-fail" self.assertEqual(actual, expect) self.driver.quit()
def verification_today_morning_exam(self, exam_data, expect): # 判断当前条件下,有无数据 判断有无元素,以及有多少个 today_morning_query_result = self.verification_morning_exam_result( self.driver) # 学生数量不为 0 if int(today_morning_query_result) != 0: # 判断学生数量 一页数据大于10,分页 if int(today_morning_query_result) > 10: # 翻页功能 page_count_ele = Service.get_eles( self.driver, By.CSS_SELECTOR, "#mornExam > div.bootstrap-table > div.fixed-table-container > " "div.fixed-table-pagination > div.pull-right.pagination > ul li" ) # 选择最后一页 Service.get_tier_ele( page_count_ele[len(page_count_ele) - 1 - 1], By.TAG_NAME, "a").click() # 校验显示是否正确 query_count_result_again = Service.get_ele( self.driver, By.XPATH, "//span[@class='pagination-info']").text result_again = re.match('^显示.*到.*?(\d+)', query_count_result_again).group(1) if int(result_again) == int(today_morning_query_result): pass else: print("翻页功能异常") self.driver.close() # 当前页展示信息个数 query_result_count = Service.get_eles( self.driver, By.CSS_SELECTOR, "#mornExam-table > tbody > tr") if len(query_result_count) > 1: # 挨个晨考 for count_exam in range(len(query_result_count)): query_select = Service.get_tier_ele( query_result_count[count_exam], By.CSS_SELECTOR, "#mornExam-table > tbody > tr:nth-child(%d) > td:nth-child(6)" % (count_exam + 1)) # 晨考 按钮 Service.get_ele( self.driver, By.CSS_SELECTOR, "#mornExam-table > tbody > tr:nth-child(%d) > td:nth-child(7) > button" % (count_exam + 1)).click() condtion = self.grade_today_morning_exam( query_select, exam_data) if condtion: if exam_data["score"] == Service.get_ele( self.driver, By.CSS_SELECTOR, "#mornExam-table > tbody > tr:nth-child(%d) > td:nth-child(6)" % (count_exam + 1)).text: actual = "today-attendance-pass" else: actual = "today-attendance-pass" else: actual = "exam-null" if actual == "exam-null": self.assertEqual(actual, "exam-null") else: self.assertEqual(actual, expect) else: query_select = Service.get_ele( self.driver, By.CSS_SELECTOR, "#mornExam-table > tbody > tr:nth-child(1) > td:nth-child(6)" ) # 晨考 按钮 Service.get_ele( self.driver, By.CSS_SELECTOR, "#mornExam-table > tbody > tr:nth-child(1) > td:nth-child(7) > button" ).click() # 调用判断晨考是否评分 condtion = self.grade_today_morning_exam( query_select, exam_data) if condtion: if exam_data["score"] == Service.get_ele( self.driver, By.CSS_SELECTOR, "#mornExam-table > tbody > tr:nth-child(1) > td:nth-child(6)" ).text: actual = "today-attendance-pass" else: actual = "today-attendance-pass" else: actual = "exam-null" if actual == "exam-null": self.assertEqual(actual, "exam-null") else: self.assertEqual(actual, expect) # 不分页 elif int(today_morning_query_result) > 1: # 当前页展示信息个数 query_result_count = Service.get_eles( self.driver, By.CSS_SELECTOR, "#mornExam-table > tbody > tr") # 挨个晨考 for count_exam in range(len(query_result_count)): query_select = Service.get_ele( self.driver, By.CSS_SELECTOR, "#mornExam-table > tbody > tr:nth-child(%d) > td:nth-child(6)" % (count_exam + 1)) # 晨考 按钮 Service.get_ele( self.driver, By.CSS_SELECTOR, "#mornExam-table > tbody > tr:nth-child(%d) > td:nth-child(7) > button" % (count_exam + 1)).click() condtion = self.grade_today_morning_exam( query_select, exam_data) if condtion: if exam_data["score"] == Service.get_ele( self.driver, By.CSS_SELECTOR, "#mornExam-table > tbody > tr:nth-child(%d) > td:nth-child(6)" % (count_exam + 1)).text: actual = "today-attendance-pass" else: actual = "today-attendance-pass" else: actual = "exam-null" if actual == "exam-null": self.assertEqual(actual, "exam-null") else: self.assertEqual(actual, expect) # 一条数据,用全选,选中元素,然后分班 else: query_select = Service.get_ele( self.driver, By.CSS_SELECTOR, "#mornExam-table > tbody > tr:nth-child(1) > td:nth-child(6)" ) # 晨考 按钮 Service.get_ele( self.driver, By.CSS_SELECTOR, "#mornExam-table > tbody > tr:nth-child(1) > td:nth-child(7) > button" ).click() condtion = self.grade_today_morning_exam( query_select, exam_data) if condtion: if exam_data["score"] == Service.get_ele( self.driver, By.CSS_SELECTOR, "#mornExam-table > tbody > tr:nth-child(1) > td:nth-child(6)" ).text: actual = "today-attendance-pass" else: actual = "today-attendance-pass" else: actual = "exam-null" if actual == "exam-null": self.assertEqual(actual, "exam-null") else: self.assertEqual(actual, expect) else: print("当前条件下,查询数据为空") self.driver.quit()
def test_trainees_management(self, trainees_management_info, expect): # cookie self.common_resource_pool_init() # 调用查询操作 TraineesManagement.basic_information_query(self.driver, trainees_management_info) # 判断当前条件下,有无数据 basic_query_result = self.verification_trainees_management_result( self.driver) # 学生数量不为 0 if int(basic_query_result) != 0: # 判断学生数量 一页数据大于10,分页 if int(basic_query_result) > 10: # 翻页功能 page_count_ele = Service.get_eles( self.driver, By.CSS_SELECTOR, "#stuInfo > div.bootstrap-table > div.fixed-table-container > " "div.fixed-table-pagination > div.pull-right.pagination > ul li" ) # 选择最后一页 Service.get_tier_ele( page_count_ele[len(page_count_ele) - 1 - 1], By.TAG_NAME, "a").click() # 校验显示是否正确 query_count_result_again = Service.get_ele( self.driver, By.XPATH, "//span[@class='pagination-info']").text result_again = re.match('^显示.*到.*?(\d+)', query_count_result_again).group(1) if int(result_again) == int(basic_query_result): pass else: print("翻页功能异常") self.driver.close() # 当前页展示信息个数 query_result_count = Service.get_eles( self.driver, By.CSS_SELECTOR, "#stuInfo_table > tbody > tr") if len(query_result_count) > 1: # 选中第一个 查看功能 self.verification_check_result( query_result_count[0], "//table[@id='stuInfo_table']/tbody/tr[1]/td[12]/input/button[1]" ) # 本页最后一个 css_count = "#stuInfo_table > tbody > tr:nth-child(%d) > td:nth-child(12) > button:nth-child(1)" % ( len(query_result_count)) time.sleep(2) self.verification_check_result( query_result_count[len(query_result_count) - 1], css_count) # 调用修改功能 第一个 self.verification_modify_result( query_result_count[0], "//table[@id='stuInfo_table']/tbody/tr/td[12]/button[2]", expect) else: query_result_count_one = Service.get_ele( self.driver, By.CSS_SELECTOR, "#stuInfo_table > tbody > tr") # 选中唯一个 查看功能#stuInfo_table > tbody > tr > td:nth-child(12) > button:nth-child(1) self.verification_check_result( query_result_count_one, "#stuInfo_table > tbody > tr > td:nth-child(12) > " "button:nth-child(1)") # 调用修改功能#stuInfo_table > tbody > tr > td:nth-child(12) > button:nth-child(1) self.verification_modify_result( query_result_count_one, "//table[@id='stuInfo_table']/tbody/tr/td[12]/button[2]", expect) # 不分页 elif int(basic_query_result) > 1: # 当前页展示信息个数 query_result_count = Service.get_eles( self.driver, By.CSS_SELECTOR, "#stuInfo_table > tbody > tr") # 选中第一个 查看功能 self.verification_check_result( query_result_count[0], "//table[@id='stuInfo_table']/tbody/tr[1]/td[12]/input/button[1]" ) # 本页最后一个 css_count = "#stuInfo_table > tbody > tr:nth-child(%d) > td:nth-child(12) > button:nth-child(1)" % ( len(query_result_count)) time.sleep(2) self.verification_check_result( query_result_count[len(query_result_count) - 1], css_count) # 调用修改功能 最后一个 self.verification_modify_result( query_result_count[len(query_result_count) - 1], "//table[@id='stuInfo_table']/tbody/tr/td[12]/button[2]", expect) # 一条数据 else: # 当前页展示信息个数 query_result_count = Service.get_ele( self.driver, By.CSS_SELECTOR, "#stuInfo_table > tbody > tr") # 选中一个 查看功能 self.verification_check_result( query_result_count, "#stuInfo_table > tbody > tr > td:nth-child(12) > button:nth-child(1)" ) # 调用修改功能 self.verification_modify_result( query_result_count, "//table[@id='stuInfo_table']/tbody/tr/td[12]/button[2]", expect) else: print("当前条件下,查询数据为空") self.driver.quit() # 退出 self.driver.quit()
def test_today_attendance(self, today_name, today_status, expect): # cookie self.course_arrangement_init() # 批量考勤 # 判断当前条件下,有无数据 判断有无元素,以及有多少个 class_query_result = self.verification_today_attendance_result( self.driver) # 学生数量不为 0 if int(class_query_result) != 0: # 判断学生数量 一页数据大于10,分页 if int(class_query_result) > 10: # 翻页功能 page_count_ele = Service.get_eles( self.driver, By.CSS_SELECTOR, "#atten > div.bootstrap-table > div.fixed-table-container > " "div.fixed-table-pagination > div.pull-right.pagination > ul li" ) # 选择最后一页 Service.get_tier_ele( page_count_ele[len(page_count_ele) - 1 - 1], By.TAG_NAME, "a").click() # 校验显示是否正确 query_count_result_again = Service.get_ele( self.driver, By.XPATH, "//span[@class='pagination-info']").text result_again = re.match('^显示.*到.*?(\d+)', query_count_result_again).group(1) if int(result_again) == int(class_query_result): pass else: print("翻页功能异常") self.driver.close() # 当前页展示信息个数 query_result_count = Service.get_eles( self.driver, By.CSS_SELECTOR, "#attendance_table > tbody > tr") if len(query_result_count) > 1: # 选中第一个 one_query_select = Service.get_tier_ele( query_result_count[0], By.XPATH, "//*[@id='attendance_table']/tbody/tr[1]/td[7]/select") Service.get_select_result(one_query_select, today_status["status"]) # 本页最后一个 css_count = "#attendance_table > tbody > tr:nth-child(%d) > td:nth-child(7) > " \ "select" % (len(query_result_count)) # # 得到姓名,验证一下 # css_count_name = Service.get_ele(self.driver,By.CSS_SELECTOR, # "#attendance_table > tbody > tr:nth-child(%d) > " # "td:nth-child(1)"%(len(query_result_count))).text time.sleep(2) two_query_select = Service.get_tier_ele( query_result_count[len(query_result_count) - 1], By.CSS_SELECTOR, css_count) Service.get_select_result(two_query_select, today_status["status"]) # 批量 操作 TodayAttendance.today_attendance_check(self.driver) else: # 选中第一个 one_query_select = Service.get_tier_ele( query_result_count[0], By.XPATH, "//*[@id='attendance_table']/tbody/tr[1]/td[7]/select") Service.get_select_result(one_query_select, today_status["status"]) # 批量 操作 TodayAttendance.today_attendance_check(self.driver) # 不分页 elif int(class_query_result) > 1: # 当前页展示信息个数 query_result_count = Service.get_eles( self.driver, By.CSS_SELECTOR, "#attendance_table > tbody > tr") # 选中第一个 one_query_select = Service.get_tier_ele( query_result_count[0], By.XPATH, "//*[@id='attendance_table']/tbody/tr[1]/td[7]/select") Service.get_select_result(one_query_select, today_status["status"]) # 本页最后一个 css_count = "#attendance_table > tbody > tr:nth-child(%d) > td:nth-child(7) > " \ "select" % (len(query_result_count)) # # 得到姓名,验证一下 # css_count_name = Service.get_ele(self.driver,By.CSS_SELECTOR, # "#attendance_table > tbody > tr:nth-child(%d) > " # "td:nth-child(1)"%(len(query_result_count))).text time.sleep(2) two_query_select = Service.get_tier_ele( query_result_count[len(query_result_count) - 1], By.CSS_SELECTOR, css_count) Service.get_select_result(two_query_select, today_status["status"]) # 批量 操作 TodayAttendance.today_attendance_check(self.driver) # 一条数据,用全选,选中元素,然后分班 else: self.single_today_attendance(today_status["status"], expect) else: print("当前条件下,查询数据为空") self.driver.quit() # 单个学生 TodayAttendance.today_attendance_query(self.driver, today_name["name"]) # 验证学生考勤 self.single_today_attendance(today_status["status"], expect) self.driver.quit()
def test_allocating_resource(self,allocating_resource_info,expect): # cookie登录 self.allocating_resource_test_init() # 查询 AllocatingResource.allocating_resource_query_operation(self.driver, allocating_resource_info) # 先判断,当前查询条件下,学生人数 allocating_one_result = self.verification_allocating_result(self.driver) # 学生数量不为 0 if int(allocating_one_result) != 0: # 判断学生数量 一页数据大于10,分页 if int(allocating_one_result) > 10: # 翻页功能 page_count_ele = Service.get_eles(self.driver, By.CSS_SELECTOR, "#content > div.con-body > div > div.bootstrap-table > div.fixed-table-container > " "div.fixed-table-pagination > div.pull-right.pagination > ul li") # 选择最后一页 Service.get_tier_ele(page_count_ele[len(page_count_ele) - 1 - 1], By.TAG_NAME, "a").click() # 校验显示是否正确 query_count_result_again = Service.get_ele(self.driver, By.XPATH, "//span[@class='pagination-info']").text result_again = re.match('^显示.*到.*?(\d+)', query_count_result_again).group(1) if int(result_again) == int(allocating_one_result): pass else: print("翻页功能异常") self.driver.close() # 当前页展示信息个数 query_result_count = Service.get_eles(self.driver, By.XPATH, "//table[@id='allot-table']/tbody/tr") # 选中第一个 Service.get_tier_ele(query_result_count[0], By.XPATH, "//table[@id='allot-table']/tbody/tr[1]/td[1]/input").click() # 本页最后一个 css_count = "#allot-table > tbody:nth-child(2) > tr:nth-child(%d) > td:nth-child(1) > input:nth-child(1)" % ( len(query_result_count)) time.sleep(2) Service.get_tier_ele(query_result_count[len(query_result_count) - 1], By.CSS_SELECTOR, css_count).click() # 不分页 elif int(allocating_one_result) > 1: # 当前页展示信息个数 query_result_count = Service.get_eles(self.driver, By.XPATH, "//table[@id='allot-table']/tbody/tr") # 选中第一个 Service.get_tier_ele(query_result_count[0], By.XPATH, "//table[@id='allot-table']/tbody/tr[1]/td[1]/input").click() # 本页最后一个 css_count = "#allot-table > tbody:nth-child(2) > tr:nth-child(%d) > td:nth-child(1) > input:nth-child(1)" % ( len(query_result_count)) time.sleep(2) Service.get_tier_ele(query_result_count[len(query_result_count) - 1], By.CSS_SELECTOR, css_count).click() # 一条数据 else: # 当前页展示信息个数 query_result_count = Service.get_ele(self.driver, By.XPATH, "//table[@id='allot-table']/tbody/tr") # 选中第一个 Service.get_tier_ele(query_result_count, By.XPATH, "//table[@id='allot-table']/tbody/tr[1]/td[1]/input").click() else: print("当前条件下,查询数据为空") self.driver.quit() # 执行提交 AllocatingResource.allocating_resource_submit_operation(self.driver,allocating_resource_info) Service.get_ele(self.driver,By.CSS_SELECTOR ,"html body.modal-open div.bootbox.modal.fade.mydialog.in " "div.modal-dialog.modal-sm div.modal-content div.modal-footer button.btn.btn-primary").click() time.sleep(1) self.driver.refresh() # 二次验证判断,提交到的人或区域的学生人数 # 查询 AllocatingResource.allocating_resource_query_operation(self.driver, allocating_resource_info) allocating_two_result = self.verification_allocating_result(self.driver) # print(int(allocating_one_result)) # print(int(allocating_two_result)) if int(allocating_one_result) > int(allocating_two_result): actual = "allocation-pass" else: actual = "allocation-fail" self.assertEqual(actual, expect) self.driver.quit()