Exemplo n.º 1
0
 def wrapper(*args, **kwargs):
     res = func(*args, **kwargs)
     if not res:
         return False
     loc, shape = res
     checked = status.get("checkedbox", "")
     text = status.get("text", "")
     selected = status.get("selected", "")
     loc_x, loc_y = loc
     save_path = get_current_dir() + "/Test_Data/td_power_manager/temp.png"
     if checked:
         checked_path = get_current_dir("Test_Data/td_power_manager/verify_screen_saver_works/checked")
         if checked.lower() == "disabled":
             checked_path = get_current_dir("Test_Data/td_power_manager/verify_screen_saver_works/unchecked")
         pic_list = get_folder_items(checked_path)
         assert pic_list != [], "{} not exist".format(checked_path)
         off_x, off_y = -30, -15
         fil_x = loc_x + off_x if loc_x + off_x > 0 else 0
         fil_y = loc_y + off_y if loc_y + off_y > 0 else 0
         filter_dic = {"left": fil_x, "top": fil_y, "width": 30, "height": 30}
         capture_screen_by_loc(save_path, filter_dic)
         for i in pic_list:
             if compare_pic_similarity(checked_path + "/" + i, save_path):
                 break
         else:
             return False
     elif text:
         text_path = get_current_dir("Test_Data/td_power_manager/verify_screen_saver_works/text/{}".format(text))
         pic_list = get_folder_items(text_path)
         assert pic_list != [], "{} not exist".format(text_path)
         off_x, off_y = shape[1] - 10, -15
         fil_x = loc_x + off_x if loc_x + off_x > 0 else 0
         fil_y = loc_y + off_y if loc_y + off_y > 0 else 0
         filter_dic = {"left": fil_x, "top": fil_y, "width": 200, "height": 35}
         capture_screen_by_loc(save_path, filter_dic)
         for i in pic_list:
             if compare_pic_similarity(text_path + "/" + i, save_path):
                 break
         else:
             return False
     elif selected:
         text_path = get_current_dir("Test_Data/td_power_manager/verify_screen_saver_works/selected/{}".format(selected.lower()))
         pic_list = get_folder_items(text_path)
         assert pic_list != [], "{} not exist".format(text_path)
         off_x, off_y = shape[1] - 10, -15
         fil_x = loc_x + off_x if loc_x + off_x > 0 else 0
         fil_y = loc_y + off_y if loc_y + off_y > 0 else 0
         filter_dic = {"left": fil_x, "top": fil_y, "width": 200, "height": 35}
         capture_screen_by_loc(save_path, filter_dic)
         for i in pic_list:
             if compare_pic_similarity(text_path + "/" + i, save_path):
                 break
         else:
             return False
     return True
def set_user_password():
    current_path = get_current_dir("Test_Data")
    temp_path = current_path + "/temp.png"
    user = current_path + "/td_power_manager/user_icon"
    enabled = user + "/enabled"
    change_path = user + "/change"
    SwitchThinProMode("admin")
    time.sleep(1)
    log.info("Open security desktop")
    os.popen(
        "hptc-control-panel --config-panel /etc/hptc-control-panel/applications/hptc-security.desktop"
    )
    time.sleep(4)
    print(user)
    res = wait_element(user)
    if res:
        location, shape = res
        loc_x, loc_y = location
        offset_x, offset_y = 0, -20
        loc = {
            "left": loc_x + offset_x,
            "top": loc_y + offset_y,
            "width": 500,
            "height": 40
        }
        capture_screen_by_loc(temp_path, loc)
        enabled_list = get_folder_items(enabled, file_only=True)
        change_path_list = get_folder_items(change_path, file_only=True)
        flag = True
        for i in enabled_list:
            if compare_pic_similarity(enabled + "/{}".format(i), temp_path):
                break
        else:
            flag = False
        for i in change_path_list:
            change_res = compare_pic_similarity(change_path + "/{}".format(i),
                                                temp_path)
            if change_res:
                break
        else:
            change_res = False
        if flag and change_res:
            print(change_res, "change")
            change_loc, change_shape = change_res
            offset = (change_loc[0] + int(change_shape[1] / 2),
                      change_loc[1] + int(change_shape[0] / 2))
            print(offset)
            return (loc_x + offset_x, loc_y + offset_y), offset
    return False
Exemplo n.º 3
0
 def __capture_part_screen(self, icon_path, position: tuple) -> tuple:
     save_path = get_current_dir("loc_demo.png")
     if not position:
         return picture_operator.wait_element(icon_path, offset=(0, 0))
     if not len(position) == 4:
         raise KeyError(
             "Position must be a tuple as: (left, top, width, height)")
     left, top, width, height = position
     current_x, current_y = self.loc
     pos = {
         "left": current_x + left,
         "top": current_y + top,
         "width": width,
         "height": height
     }
     capture_screen_by_loc(file_path=save_path, loc_dic=pos)
     items = get_folder_items(icon_path, file_only=True, filter_name=".png")
     pic_path_list = list(
         map(lambda file_name: icon_path + f"/{file_name}", items))
     for pic_item in pic_path_list:
         element_shape = compare_pic_similarity(img=pic_item, tmp=save_path)
         if element_shape:
             loc, size = element_shape
             loc_x, loc_y = loc
             current_left, current_top = current_x + left + loc_x, current_y + top + loc_y
             return (current_left, current_top), size
     return ()
def set_user_password(**kwargs):
    current_path = common_function.get_current_dir("Test_Data")
    temp_path = current_path + "/temp.png"
    user = current_path + "/td_power_manager/user_icon"
    enabled = user + "/enabled"
    change_path = user + "/change"
    SwitchThinProMode("admin")
    time.sleep(1)
    log.info("Open security desktop")
    os.popen("hptc-control-panel --config-panel /etc/hptc-control-panel/applications/hptc-security.desktop")
    time.sleep(2)
    res = picture_operator.wait_element(user)
    if res:
        location, shape = res
        loc_x, loc_y = location
        offset_x, offset_y = 0, -20
        loc = {"left": loc_x + offset_x, "top": loc_y + offset_y, "width": 500, "height": 40}
        picture_operator.capture_screen_by_loc(temp_path, loc)
        enabled_list = common_function.get_folder_items(enabled, file_only=True)
        change_path_list = common_function.get_folder_items(change_path, file_only=True)
        flag = True
        for i in enabled_list:
            if picture_operator.compare_pic_similarity(enabled + "/{}".format(i), temp_path):
                break
        else:
            flag = False
        for i in change_path_list:
            change_res = picture_operator.compare_pic_similarity(change_path + "/{}".format(i), temp_path)
            if change_res:
                break
        else:
            change_res = False
        if flag and change_res:
            change_loc, change_shape = change_res
            offset = (change_loc[0] + int(change_shape[1] / 2), change_loc[1] + int(change_shape[0] / 2))
            res = (loc_x + offset_x, loc_y + offset_y), offset
            loc, offset = res
            loc_x, loc_y = loc[0] + offset[0], loc[1] + offset[1]
            tool.click(loc_x, loc_y)
            time.sleep(1)
            tool.tap_key("1", 1)
            tool.tap_key("Tab", 1)
            tool.tap_key("1", 1)
            tool.tap_key(tool.keyboard.enter_key, 2)
            os.popen("hptc-control-panel --term")
 def check_picture(path, cs):
     print(cs)
     file_path = "/".join(os.path.realpath(path).split("\\"))
     if not os.path.exists(file_path):
         os.makedirs(file_path)
     file_list = os.listdir(file_path)
     for p in file_list:
         if "png" in p or "jpg" in p:
             pic_name = file_path + "/{}".format(p)
             if compare_pic_similarity(pic_name, cs):
                 return True
     return False