class Charge: def __init__(self,driver): self.ha=Action(driver) self.driver=driver self.he = Excel_handle() def charge(self): rows = self.he.get_rows(7) # try: student_phone = None result=None for i in range(1, int(rows) + 1): is_run = self.he.get_value(i, 4, 7) module_name = self.he.get_value(i, 2, 7) if is_run == "yes": action_ways = self.he.get_value(i, 5, 7) # 操作方法 input_data = self.he.get_value(i, 6, 7) # 输入内容 page = self.he.get_value(i, 7, 7) # 当前页面 element = self.he.get_value(i, 8, 7) # 元素 Expect_page = self.he.get_value(i, 9, 7) # 期望页面 Expect_element = self.he.get_value(i, 10, 7) # 期望元素 EXpect_result = self.he.get_value(i, 11, 7) # 期望结果 element_number = self.he.get_value(i, 13, 7) # 元素位置 pre_page = self.he.get_value(i, 14, 7) # 前置页面 pre_element = self.he.get_value(i, 15, 7) # 前置元素 pre_element_number = self.he.get_value(i, 16, 7) # 前置元素位置 son_page=self.he.get_value(i, 17, 7) son_element=self.he.get_value(i, 18, 7) son_number=self.he.get_value(i, 19, 7) pre_flag = True if action_ways == "open_browser": self.ha.open_url(input_data) self.driver.maximize_window() elif action_ways == "input_action": if input_data == "姓名": input_data = self.ha.create_name() name = input_data elif input_data == "手机号码": input_data = self.ha.createPhone() staff_phone=input_data self.ha.input_action(page, element, str(input_data), element_number) elif action_ways == "search_action": self.ha.input_action(page, element, student_phone, element_number) elif action_ways == "click_action": self.ha.click_action(page, element, element_number) elif action_ways == "clear_action": self.ha.clear_action(page, element, element_number) elif action_ways == "wait": self.ha.wait_action(int(input_data)) elif action_ways == "wait_element": self.ha.wait_element_show(page, element) elif action_ways == "wait_elemnt_click": self.ha.wait_element_click(page, element) elif action_ways == "mouse_menu": self.ha.mouse_menu(page, element, element_number) elif action_ways == "father_son_mouseaction": self.ha.father_son_mouseaction(page, element, pre_page, pre_element, number1=element_number, number2=pre_element_number) elif action_ways == "switch_action": handles = self.ha.switch_page(1) elif action_ways == "father_son_click": self.ha.father_son_click(page, element, pre_page, pre_element, number1=element_number, number2=pre_element_number) elif action_ways == "father_son_input": self.ha.father_son_input(page, element, pre_page, pre_element, result, element_number, pre_element_number) elif action_ways == "father_son_text": result2=self.ha.father_son_text(page, element, pre_page, pre_element, element_number, pre_element_number) self.he.write_cell_value(i, 12, result2, "Charge") elif action_ways == "element_text": result = self.ha.element_text(page, element, element_number) print(result) if result == EXpect_result: self.he.write_cell_value(i, 12, "Success", "Charge") else: self.he.write_cell_value(i, 12, "Fail", "Charge") # self.he.write_cell_value(i, 12, result, "Charge") elif action_ways == "isElementExist": result = self.ha.isElementExist(page, element) if result: # self.he.write_cell_value(i, 12, "Success", "Charge") self.ha.click_action(Expect_page, Expect_element, element_number) if Expect_element != None: # 如果期待元素为空,则不执行 try: self.ha.wait_element_show(Expect_page, Expect_element) self.he.write_cell_value(i, 12, "Success", "Charge") except Exception as e: self.he.write_cell_value(i, 12, "Fail", "Charge") self.ha.save_screenshot_action("../screenshot/" + Expect_element + ".png")
class Create_clue_order: def __init__(self, driver): self.ha = Action(driver) self.driver = driver self.he = Excel_handle() def Create_clue_order(self): rows = self.he.get_rows(4) try: for i in range(1, int(rows) + 1): is_run = self.he.get_value(i, 4, 4) module_name = self.he.get_value(i, 2, 4) if is_run == "yes": action_ways = self.he.get_value(i, 5, 4) # 操作方法 input_data = self.he.get_value(i, 6, 4) # 输入内容 page = self.he.get_value(i, 7, 4) # 当前页面 element = self.he.get_value(i, 8, 4) # 元素 Expect_page = self.he.get_value(i, 9, 4) # 期望页面 Expect_element = self.he.get_value(i, 10, 4) # 期望元素 EXpect_result = self.he.get_value(i, 11, 4) # 期望结果 element_number = self.he.get_value(i, 13, 4) # 元素位置 pre_page = self.he.get_value(i, 14, 4) # 前置页面 pre_element = self.he.get_value(i, 15, 4) # 前置元素 pre_element_number = self.he.get_value(i, 16, 4) # 前置元素位置 son_page = self.he.get_value(i, 17, 4) son_element = self.he.get_value(i, 18, 4) son_number = self.he.get_value(i, 19, 4) pre_flag = True if pre_element != None: try: self.ha.isElementExist(pre_page, pre_element) pre_flag = True except Exception as e: pre_flag = False self.ha.save_screenshot_action("../screenshot/" + pre_element + ".png") if pre_flag == True and pre_element == None: if action_ways == "open_browser": self.ha.open_url(input_data) self.driver.maximize_window() elif action_ways == "input_action": self.ha.input_action(page, element, input_data, element_number) elif action_ways == "click_action": self.ha.click_action(page, element, element_number) elif action_ways == "clear_action": self.ha.clear_action(page, element, element_number) elif action_ways == "wait": self.ha.wait_action(int(input_data)) elif action_ways == "wait_element": self.ha.wait_element_show(page, element) elif action_ways == "wait_elemnt_click": self.ha.wait_element_click(page, element) elif action_ways == "mouse_menu": self.ha.mouse_menu(page, element, element_number) elif action_ways == "father_son_click": print(son_number) self.ha.father_son_click(page, element, son_page, son_element, number1=element_number, number2=son_number) elif action_ways == "element_text": flag = True result = self.ha.element_text( page, element, element_number) if result == EXpect_result: flag = True self.he.write_cell_value( i, 12, "Success", "Create_clue_order") else: flag = False self.he.write_cell_value( i, 12, "Fail", "Create_clue_order") # self.he.write_cell_value(i, 12, result, "Create_clue_order") elif action_ways == "isElementExist": result = self.ha.isElementExist(page, element) if result: # self.he.write_cell_value(i, 12, "Success", "Create_clue_order") self.ha.click_action(Expect_page, Expect_element, element_number) if Expect_element != None: # 如果期待元素为空,则不执行 try: flag = True self.ha.wait_element_show( Expect_page, Expect_element) self.he.write_cell_value( i, 12, "Success", "Create_clue_order") except Exception as e: flag = False self.he.write_cell_value( i, 12, "Fail", "Create_clue_order") self.ha.save_screenshot_action( "../screenshot/" + Expect_element + ".png") except Exception as e: print(e) self.he.write_cell_value(i, 12, "Fail", "Create_clue_order") self.ha.save_screenshot_action("../screenshot/" + element + ".png") return flag
class register: def __init__(self, driver): self.ha = Action(driver) self.driver = driver self.he = Excel_handle() def regist(self): rows = self.he.get_rows(3) student_name = "学生名字" try: for i in range(1, int(rows) + 1): is_run = self.he.get_value(i, 4, 3) module_name = self.he.get_value(i, 2, 3) if is_run == "yes": action_ways = self.he.get_value(i, 5, 3) input_data = self.he.get_value(i, 6, 3) page = self.he.get_value(i, 7, 3) element = self.he.get_value(i, 8, 3) Expect_page = self.he.get_value(i, 9, 3) Expect_element = self.he.get_value(i, 10, 3) EXpect_result = self.he.get_value(i, 11, 3) element_number = self.he.get_value(i, 13, 3) if action_ways == "open_browser": self.ha.open_url(input_data) self.driver.maximize_window() elif action_ways == "input_action": self.ha.input_action(page, element, input_data, element_number) elif action_ways == "click_action": self.ha.click_action(page, element, element_number) elif action_ways == "clear_action": self.ha.clear_action(page, element, element_number) elif action_ways == "wait": self.ha.wait_action(int(input_data)) elif action_ways == "wait_element": self.ha.wait_element_show(page, element) elif action_ways == "wait_elemnt_click": self.ha.wait_element_click(page, element) elif action_ways == "mouse_menu": self.ha.mouse_menu(page, element, number) elif action_ways == "element_text": result = self.ha.element_text(page, element, element_number) if student_name == "学生名字": student_name = result if result == student_name: flag = False self.he.write_cell_value(i, 12, "Fail", "Admission") self.ha.save_screenshot_action("../screenshot/" + student_name + ".png") else: flag = True self.he.write_cell_value(i, 12, "Success", "Admission") if Expect_element != None: # 如果期待元素为空,则不执行 try: flag = True self.ha.wait_element_show(Expect_page, Expect_element) self.he.write_cell_value(i, 12, "Success", "Admission") except Exception as e: flag = False self.he.write_cell_value(i, 12, "Fail", "Admission") self.ha.save_screenshot_action("../screenshot/" + Expect_element + ".png") except Exception as e: print(e) self.he.write_cell_value(i, 12, "Fail", "Admission") self.ha.save_screenshot_action("../screenshot/" + element + ".png") return flag