Пример #1
0
class Switch_window:
    def __init__(self):
        self.driver = webdriver.Chrome()
        self.ha = Action(driver=self.driver)

    def window_switch(self):
        self.ha.open_url(
            "http://tyysdk.tianyuyou.cn/agent.php/front/index/index.html")
        self.ha.click_action("Loginpage", "open_service")
        n = self.driver.window_handles
        print(n)
        mywindow = self.driver.current_window_handle
        for i in n:
            if i != mywindow:
                self.driver.switch_to_window(mywindow)
                time.sleep(3)
                self.driver.switch_to_window(i)
                time.sleep(2)
                self.ha.shut_web_action()
Пример #2
0
 def __init__(self, driver):
     self.ha = Action(driver)
     self.driver = driver
     self.he = Excel_handle()
Пример #3
0
class Login:
    def __init__(self, driver):
        self.ha = Action(driver)
        self.driver = driver
        self.he = Excel_handle()

    def login(self):
        rows = self.he.get_rows()
        try:
            for i in range(1, int(rows) + 1):
                is_run = self.he.get_value(i, 4, 0)
                if is_run == "yes":
                    action_ways = self.he.get_value(i, 5)  # 获取页面操作方法
                    input_data = self.he.get_value(i, 6)  # 获取输入内容
                    # print(input_data)
                    page = self.he.get_value(i, 7)  # 定位页面
                    element = self.he.get_value(i, 8)  # 定位页面元素
                    Expect_page = self.he.get_value(i, 9)  # 定位预期页面
                    Expect_element = self.he.get_value(i, 10)  # 定位预期元素
                    element_number = self.he.get_value(i, 13)  # 定位页面元素位置
                    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 == "element_text":  # 点击元素的文本内容
                        self.ha.element_text(page, element, element_number)
                    if Expect_element != None:  # 如果期待元素为空,则不执行
                        try:
                            time.sleep(3)
                            flag = True
                            self.ha.wait_element_show(Expect_page,
                                                      Expect_element)
                            self.he.write_cell_value(i, 12, "Success", "login")
                            # sessionid = self.driver.execute_script('return Cookies.getItem("xgj_fulltime_session");')
                            # self.he.write_cell_value(i, 11, sessionid,"login")
                            return flag
                        except Exception as e:
                            flag = False
                            self.ha.save_screenshot_action("../screenshot/" +
                                                           Expect_element +
                                                           ".png")
                            self.he.write_cell_value(i, 12, "Fail", "login")
                            return flag
        except Exception as e:
            flag = False
            print(e)
            self.ha.save_screenshot_action("../screenshot/" + element + ".png")
            return flag
        return flag
Пример #4
0
class Check:
    def __init__(self, driver):
        self.ha = Action(driver)
        self.driver = driver
        self.he = Excel_handle()

    def check_students(self):
        rows = self.he.get_rows(2)
        try:
            for i in range(1, int(rows) + 1):
                is_run = self.he.get_value(i, 4, 2)
                module_name = self.he.get_value(i, 2, 2)
                if is_run == "yes":
                    action_ways = self.he.get_value(i, 5, 2)
                    input_data = self.he.get_value(i, 6, 2)
                    page = self.he.get_value(i, 7, 2)
                    element = self.he.get_value(i, 8, 2)
                    Expect_page = self.he.get_value(i, 9, 2)
                    Expect_element = self.he.get_value(i, 10, 2)
                    EXpect_result = self.he.get_value(i, 11, 2)
                    element_number = self.he.get_value(i, 13, 2)
                    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 == "element_text":
                        result = self.ha.element_text(page, element,
                                                      element_number)
                        if EXpect_result == result:
                            flag = True
                            self.he.write_cell_value(i, 12, "Success",
                                                     "check_students")
                        else:
                            flag = False
                            self.ha.save_screenshot_action("../screenshot/" +
                                                           result + ".png")
                            self.he.write_cell_value(i, 12, "Fail",
                                                     "check_students")
                    if Expect_element != None:  # 如果期待元素为空,则不执行
                        try:
                            self.ha.wait_element_show(Expect_page,
                                                      Expect_element)
                            self.he.write_cell_value(i, 12, "Success",
                                                     "check_students")
                        except Exception as e:
                            self.he.write_cell_value(i, 12, "Fail",
                                                     "check_students")
                            self.ha.save_screenshot_action("../screenshot/" +
                                                           Expect_element +
                                                           ".png")
        except Exception as e:
            print(e)
            flag = False
            self.he.write_cell_value(i, 12, "Fail", "check_students")
            self.ha.save_screenshot_action("../screenshot/" + element + ".png")
        return flag
Пример #5
0
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
Пример #6
0
 def __init__(self):
     self.ac = Action()
     self.sess = requests.Session()
Пример #7
0
class Request_ways():
    def __init__(self):
        self.ac = Action()
        self.sess = requests.Session()

    """封装接口请求  cookie_location表示cookie是web还是app"""

    def post_url(self, url, data, cookie, take_headers, header=None):
        if take_headers != None:
            if self.ac.is_login():
                header["Cookie"] = Cookie_handle().get_cookie("seesion")
            else:
                self.ac.PC_Login()
                header["Cookie"] = Cookie_handle().get_cookie("seesion")
        else:
            pass
        if cookie == "student":
            if self.ac.mobile_is_Login():
                header["Cookie"] = Cookie_handle().get_cookie("seesion")
            else:
                self.ac.mobile_Login()
                header["Cookie"] = Cookie_handle().get_cookie("seesion")
        elif cookie == "teacher":
            if self.ac.teacher_is_login():
                header["Cookie"] = Cookie_handle().get_cookie("seesion")
            else:
                self.ac.teacher_login()
                header["Cookie"] = Cookie_handle().get_cookie("seesion")
        response = self.sess.post(url, data=data, headers=header, verify=False)
        res = response.text
        return res

    def get_url(self, url, data, cookie, take_headers, header=None):
        if take_headers != None:
            if self.ac.is_login():
                header["Cookie"] = Cookie_handle().get_cookie("seesion")
            else:
                self.ac.Login()
                header["Cookie"] = Cookie_handle().get_cookie("seesion")
        else:
            pass
        if cookie == "student":
            if self.ac.mobile_is_Login():
                header["Cookie"] = Cookie_handle().get_cookie("seesion")
            else:
                self.ac.mobile_Login()
                header["Cookie"] = Cookie_handle().get_cookie("seesion")
        elif cookie == "teacher":
            if self.ac.teacher_is_login():
                header["Cookie"] = Cookie_handle().get_cookie("seesion")
            else:
                self.ac.teacher_login()
                header["Cookie"] = Cookie_handle().get_cookie("seesion")
        response = self.sess.get(url,
                                 params=data,
                                 headers=header,
                                 verify=False,
                                 allow_redirects=True)
        res = response.text
        return res

    def do_request(self,
                   url,
                   method,
                   data,
                   cookie=None,
                   take_headers=None,
                   header=None):
        if method == "POST":
            res = self.post_url(url, data, cookie, take_headers, header)
        elif method == "GET":
            res = self.get_url(url, data, cookie, take_headers, header)
        try:
            res = json.loads(res)
        except:
            print(res)
            print("内容不是json格式")
        return res
Пример #8
0
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")
Пример #9
0
class Clue_action:
    def __init__(self, driver):
        self.ha = Action(driver)
        self.driver = driver
        self.he = Excel_handle()

    def add_clue(self):
        rows = self.he.get_rows(8)
        try:
            for i in range(1, int(rows) + 1):
                is_run = self.he.get_value(i, 4, 8)
                if is_run == "yes":
                    action_ways = self.he.get_value(i, 5, 8)
                    input_data = self.he.get_value(i, 6, 8)
                    # print(input_data)
                    page = self.he.get_value(i, 7, 8)
                    element = self.he.get_value(i, 8, 8)
                    Expect_page = self.he.get_value(i, 9, 8)
                    Expect_element = self.he.get_value(i, 10, 8)
                    EXpect_result = self.he.get_value(i, 11, 8)
                    element_number = self.he.get_value(i, 13, 8)
                    pre_condition = self.he.get_value(i, 14, 8)
                    if action_ways == "open_browser":
                        self.ha.open_url(input_data)
                        self.driver.maximize_window()  # 最大化屏幕
                    elif action_ways == "input_action":
                        if pre_condition == "日期":  # 输入日期判断
                            self.ha.data_input(page, element, element_number)
                            input_data = input_data.strftime("%Y-%m-%d")
                        if input_data == "姓名":
                            input_data = self.ha.create_name()
                            name = input_data
                        elif input_data == "手机号码":
                            input_data = self.ha.createPhone()
                        elif input_data == "证件号码":
                            input_data = self.ha.ident_generator()
                        elif input_data == "学籍号":
                            input_data = self.ha.registration_number()
                        self.ha.input_action(page, element, input_data,
                                             element_number)
                    elif action_ways == "click_action":
                        if pre_condition == "日期":  # 输入日期判断
                            self.ha.scroll_page(page, element, element_number)
                        else:
                            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 == "page_scroll":
                        self.ha.page_scroll(page, element, element_number)
                    elif action_ways == "scroll_page":
                        self.ha.scroll_page(page, element, element_number)
                    elif action_ways == "element_text":
                        result = self.ha.element_text(page, element,
                                                      element_number)
                        print(result)
                        if result == EXpect_result:
                            flag = True
                            self.he.write_cell_value(i, 12, "Success",
                                                     "add_clue_phone")
                        else:
                            flag = False
                            self.ha.save_screenshot_action(
                                "../screenshot/login.png")
                            self.he.write_cell_value(i, 12, "Fail",
                                                     "add_clue_phone")

                    if Expect_element != None:  # 如果期待元素为空,则不执行
                        try:
                            flag = True
                            self.ha.wait_element_show(Expect_page,
                                                      Expect_element)
                            self.he.write_cell_value(i, 12, "Success",
                                                     "add_clue_phone")
                        except Exception as e:
                            flag = False
                            self.ha.save_screenshot_action("../screenshot/" +
                                                           Expect_element +
                                                           ".png")
                            self.he.write_cell_value(i, 12, "Fail",
                                                     "add_clue_phone")
        except Exception as e:
            flag = False
            self.he.write_cell_value(i, 12, "Fail", "add_clue_phone")
            self.ha.save_screenshot_action("../screenshot/" + element + ".png")
        return flag
Пример #10
0
 def __init__(self):
     self.driver = webdriver.Chrome()
     self.ha = Action(driver=self.driver)
Пример #11
0
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
Пример #12
0
class Clue_action:
    def __init__(self,driver):
        self.ha=Action(driver)
        self.driver=driver
        self.he = Excel_handle()
    def add_clue(self):
        rows = self.he.get_rows(1)
        try:
            for i in range(1, int(rows) + 1):
                is_run = self.he.get_value(i, 4, 1)
                if is_run == "yes":
                    action_ways = self.he.get_value(i, 5, 1)
                    input_data = self.he.get_value(i, 6, 1)
                    # print(input_data)
                    page = self.he.get_value(i, 7, 1)
                    element = self.he.get_value(i, 8, 1)
                    Expect_page = self.he.get_value(i, 9, 1)
                    Expect_element = self.he.get_value(i, 10, 1)
                    EXpect_result = self.he.get_value(i, 11, 1)
                    element_number = self.he.get_value(i, 13, 1)
                    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()
                        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 == "element_text":
                        result = self.ha.element_text(page, element, element_number)
                        if result == name:
                            flag = True
                            self.he.write_cell_value(i, 12, "Success","add_clue")
                        else:
                            flag = False
                            self.ha.save_screenshot_action("../screenshot/login.png")
                            self.he.write_cell_value(i, 12, "Fail","add_clue")
                    if Expect_element != None:  # 如果期待元素为空,则不执行
                        try:
                            flag = True
                            self.ha.wait_element_show(Expect_page, Expect_element)
                            self.he.write_cell_value(i, 12, "Success","add_clue")
                        except Exception as e:
                            flag = False
                            self.ha.save_screenshot_action("../screenshot/"+Expect_element+".png")
                            self.he.write_cell_value(i, 12, "Fail","add_clue")
        except Exception as e:
            print(e)
            flag = False
            self.he.write_cell_value(i, 12, "Fail","add_clue")
            self.ha.save_screenshot_action("../screenshot/"+element+".png")
        return flag
Пример #13
0
 def setUp(self):
     self.driver = webdriver.Chrome()
     self.he = Excel_handle()
     self.ha = Action(self.driver)
Пример #14
0
class Test_charge(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome()
        self.he = Excel_handle()
        self.ha = Action(self.driver)

    def test_charge(self):
        self.driver.maximize_window()
        rows = self.he.get_rows()
        try:
            for i in range(1, int(rows) + 1):
                is_run = self.he.get_value(i, 4)
                if is_run == "yes":
                    action_ways = self.he.get_value(i, 5)
                    input_data = self.he.get_value(i, 6)
                    page = self.he.get_value(i, 7)
                    element = self.he.get_value(i, 8)
                    Expect_page = self.he.get_value(i, 9)
                    Expect_element = self.he.get_value(i, 10)
                    element_number = self.he.get_value(i, 13)
                    if action_ways == "open_browser":
                        self.ha.open_url(input_data)
                    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)
                    if Expect_element != None:
                        time.sleep(1)
                        flag = self.ha.isElementExist(Expect_page,
                                                      Expect_element)
                        if flag:
                            self.he.write_cell_value(i, 12, "Success")
                        else:
                            self.ha.save_screenshot_action(
                                "../screenshot/login.png")
                            self.he.write_cell_value(i, 12, "Fail")
                        time.sleep(1)
                        self.assertTrue(flag, "用例执行成功")

        except Exception as e:
            print(e)
            self.ha.save_screenshot_action("../screenshot/" + element + ".png")

    def tearDown(self):
        self.ha.shut_web_action()