Exemple #1
0
	def activate_window(self, window_name, print_object_list=False):
		'''
			Activate window by name and optionally print its object list.
		'''		
		ldtp.activatewindow(window_name)
		if print_object_list:
			print ldtp.getobjectlist(window_name)	
Exemple #2
0
def guiexist(frm, obj, prefix=False):
  if not prefix:
    return obj if ldtp.guiexist(frm, obj) else None
  else:
    objs = ldtp.getobjectlist(frm)
    objs = filter(lambda x: x.startswith(obj), objs)
    return objs[0] if objs else None
    def list( self, name ):
	#先判断是不是特殊的,如果是就修改成真正要查找的名字 
	self.parent = None
	self.lst_map={}
	if(name in define.special_dlg.keys()):
		name=self.to_list(name)
	if(name in define.special_updlg.keys()):
	    	name=self.to_uplist(name)
	print name
        try :
  	    if 0 == len( name ):
                self.ls = ldtp.getwindowlist()
            elif 1 == ldtp.guiexist( name ):
                self.ls = ldtp.getobjectlist( name )
		self.lst_map=self.cope_lst(name)
            else:
                self.msg = "没有找到窗口"
                return False
        except :
            self.msg = "没有找到窗口"
            return False

        v = len( self.ls )
        if 0 == v:
            self.msg = "没有找到窗口"
            return False
     
        self.msg = "找到" + "%i"%v + "个窗口"
        self.parent = name
        return True
Exemple #4
0
def step_impl(context, popupwin, entry, win):
    click_those = l.getobjectlist(win)
    for thing in click_those:
        l.mouserightclick(win, thing)
        if l.waittillguiexist(popupwin, entry, 1): return
        l.generatekeyevent("<esc>") #close possible menus
        time.sleep(0.5)
    #not found
    assert(False)
Exemple #5
0
def step_impl(context, thing):
    time.sleep(
        2
    )  # opening usually needs a task switch to some UI thread to process it
    for w in l.getwindowlist():
        objs = l.getobjectlist(w)
        if thing in objs:
            assert False
            return
    assert True
def getMatchedKeywordList(windowName, keyword):
    if windowName in GUI_DICT:
        windowName = GUI_DICT[windowName]
    sortedList = []
    for item in ldtp.getobjectlist(windowName):
        if keyword.lower() in item.lower():
            sortedList += [item]
    printSection('The following objects with keyword "%s" have been matched' % keyword)
    unfounds = printFoundReturnUnfound(sortedList)
    printSection('The following objects with keyword "%s" have NOT been matched' % keyword)
    printUnfounds(unfounds)
Exemple #7
0
def capture_translations(app="app",lang="unknown"):


    wins1=l.getwindowlist()
    time.sleep(2) # sometimes the window is not ready yet
    wins=l.getwindowlist()

    img_name = l.imagecapture()

    re_pattern = r"(.*)auto([0-9]+)auto(.*)"

    for w in wins:
        obj = l.getobjectlist(w)
        w_clean = re.sub(re_pattern,"\\1\\3",w)
        for o in obj:
            info = l.getobjectinfo(w,o)
            o_clean = re.sub(re_pattern,"\\1\\3",o)
            if 'label' in info:
                label = l.getobjectproperty(w,o,'label')
                size = None

                # check if we find the "automate language"
                m = re.search(re_pattern, label)
                if m:
                    id_num = m.group(2)
                    size = l.getobjectsize(w,o)
                    if size[0] > 0:
                        translation[id_num] = (w_clean, o_clean)
                        w_o_mapping[(w_clean, o_clean)] = id_num
                        print("Translation #{} is here: ('{}','{}')".format(id_num, w_clean, o_clean))
                        print("Located in picture: {}".format(size))
                    else:
                        size = None

                # or check if we already know the translation from the "automate language"-run
                elif (w, o) in w_o_mapping.keys():
                    id_num = w_o_mapping[(w, o)]
                    size = l.getobjectsize(w,o)
                    if size[0] > 0:
                        print("Found translation #{}".format(id_num))
                    else:
                        size = None

                # in both cases we want a screenshot
                if size:
                    img = cv2.imread(img_name)
                    new_img = cv2.rectangle(img, (size[0], size[1]), (size[0] + size[2], size[1] + size[3]), (0,0,255), 3)
                    cv2.imwrite('{}/translation_{}_{}_{}_{}.png'.format(OUTPUT_DIR, app, lang, id_num, o), new_img)
Exemple #8
0
def capture_translations(app="app",lang="unknown"):


    wins1=l.getwindowlist()
    time.sleep(2) # sometimes the window is not ready yet
    wins=l.getwindowlist()

    img_name = l.imagecapture()

    re_pattern = r"(.*)auto([0-9]+)auto(.*)"

    for w in wins:
        obj = l.getobjectlist(w)
        w_clean = re.sub(re_pattern,"\\1\\3",w)
        for o in obj:
            info = l.getobjectinfo(w,o)
            o_clean = re.sub(re_pattern,"\\1\\3",o)
            if 'label' in info:
                label = l.getobjectproperty(w,o,'label')
                size = None

                # check if we find the "automate language"
                m = re.search(re_pattern, label)
                if m:
                    id_num = m.group(2)
                    size = l.getobjectsize(w,o)
                    if size[0] > 0:
                        translation[id_num] = (w_clean, o_clean)
                        w_o_mapping[(w_clean, o_clean)] = id_num
                        print("Translation #{} is here: ('{}','{}')".format(id_num, w_clean, o_clean))
                        print("Located in picture: {}".format(size))
                    else:
                        size = None

                # or check if we already know the translation from the "automate language"-run
                elif (w, o) in w_o_mapping.keys():
                    id_num = w_o_mapping[(w, o)]
                    size = l.getobjectsize(w,o)
                    if size[0] > 0:
                        print("Found translation #{}".format(id_num))
                    else:
                        size = None

                # in both cases we want a screenshot
                if size:
                    img = cv2.imread(img_name)
                    new_img = cv2.rectangle(img, (size[0], size[1]), (size[0] + size[2], size[1] + size[3]), (0,0,255), 3)
                    cv2.imwrite('/tmp/translation_{}_{}_{}_{}.png'.format(app, lang, id_num, o), new_img)
Exemple #9
0
    def get_object_list(self, window_name):
        """
        Get list of items in given GUI.

        @param window_name: Window name to look for, either full name,
        LDTP's name convention, or a Unix glob.

        @type window_name: string

        @return: list of items in LDTP naming convention.

        @rtype: list
        """
        try:
            self._info("get object list of (%s)" % window_name)
            return ldtp.getobjectlist(window_name)
        except LdtpExecutionError as e:
            raise LdtpExecutionError(e.message)
Exemple #10
0
def __yieldTreeObjects(obj,deep,withparent=True):
    ''' Internal recursive function used by getTree. '''
    if deep < 0 :
        return
    elif deep == 0 :
        if obj :
            yield obj
        return
    elif deep > 0 :
        if obj:
            ol = ldtp.getobjectlist(obj)
            if withparent :
                yield obj
        else:
            ol = ldtp.getapplist()
        for o in ol:
            for r in __yieldTreeObjects(o,deep-1,withparent):
                yield r
Exemple #11
0
def step_impl(context, popupwin, entry, win):
    click_those = l.getobjectlist(win)
    for thing in click_those:
        (x, y, w, h) = l.getobjectsize(win, thing)
        # expecting the object to consist of square shaped icons
        # so let's click in the middle of those
        click_x = x + (h / 2)
        click_y = y + (h / 2)
        while click_x < (x + w):
            context._root["_click_animated"](context,
                                             click_x,
                                             click_y,
                                             button="b3c",
                                             delay=0)
            if l.waittillguiexist(popupwin, entry, 1): return
            l.generatekeyevent("<esc>")  #close possible menus
            time.sleep(0.5)
            click_x += h
    #not found
    assert (False)
Exemple #12
0
def step_impl(context, thing):
    time.sleep(1)
    win = None
    for w in l.getwindowlist():
        objs = l.getobjectlist(w)
        if thing in objs:
            win = w
            break
    if not win:
        print(f"Failed to find {thing}")
        return
    print("Parent:")
    print(l.getobjectproperty(win, thing, 'parent'))
    (x, y, w, h) = l.getobjectsize(win, thing)
    click_x = x + (w / 2)
    click_y = y + (h / 2)
    print(f"Clicking {click_x}/{click_y} in {x}/{y}+{w}/{h}")
    if click_x < 0 or click_y < 0:
        print(f"I'd rather not click {click_x}/{click_y}")
        print(f"failed to click {thing} in {l.getobjectlist(win)}")
        return
        # assert click_x > 0, f"I'd rather not click {click_x}/{click_y}"
        # assert click_y > 0, f"I'd rather not click {click_x}/{click_y}"
    context._root["_click_animated"](context, click_x, click_y)
Exemple #13
0
 def check_element_exist(self, window, type, name):
     logger.info("check_element_exist")
     logger.info(ldtp.getobjectlist(RHSMGuiLocator().get_locator(window)))
     return ldtp.guiexist(RHSMGuiLocator().get_locator(window), type + name)
Exemple #14
0
 def list_objects(self, window):
     logger.info("get objects list in window: %s" % window)
     all_objects_list = self.__parse_objects(ldtp.getobjectlist(RHSMGuiLocator().get_locator(window)))
     logger.info("sorted all_objects_list: %s" % all_objects_list)
Exemple #15
0
def _resolveNames(context, win, thing=None, ignoreErrors=False):
    """ resolve Label names, as they are called differently once translated
    that should not be necessary if the GUI items have a name set
    """
    lang = context._root.get('my_lang', None)
    indexes = context._root.get('obj_indexes', {})

    feature = context._stack[1]["feature"].filename
    line = context._root["my_line"]
    my_id = f"{feature}_{line}"
    print(f"For {my_id}")
    print(l.getwindowlist())
    if lang is None:
        # save indexes for later
        l.waittillguiexist(win)
        try:
            o_idx = l.getobjectlist(win).index(thing) if thing else None
        except:
            o_idx = None
        indexes[my_id] = (l.getwindowlist().index(win), o_idx)
        context._root["obj_indexes"] = indexes
        print("Saving index")
    else:

        print(f"Override {win} and {thing} with")
        (w_idx, o_idx) = indexes[my_id]
        print(f"  ids {w_idx} and {o_idx}")
        # just wait until we have at least enough windows
        i = 0
        while len(l.getwindowlist()) <= w_idx:
            time.sleep(0.1)
            i = i + 1
            if i > 20:
                break
        window_list = l.getwindowlist()

        # if the window now has a translated name, trying
        # to get it by "last-seen-index"
        if win not in window_list:
            try:
                win_new = window_list[w_idx]
                if not ignoreErrors:
                    assert win[0:3] == win_new[
                        0:
                        3], f"I don't think that {win} is now called {win_new} ..."
                win = win_new
            except:
                if not ignoreErrors: raise
        else:
            print("found the window, nice!")
        # if the thing now has a translated name, trying
        # to get it by "last-seen-index"
        if thing is not None:
            object_list = l.getobjectlist(win)
            print(object_list)
            if thing not in object_list:
                try:
                    thing_new = object_list[o_idx]
                    if not ignoreErrors:
                        assert thing[0:3] == thing_new[
                            0:
                            3], f"I don't think that {thing} is now called {thing_new} ..."
                    thing = thing_new
                except:
                    if not ignoreErrors: raise
            else:
                print("found the thing, nice!")

        print(f"  to {win} and {thing}")
        l.waittillguiexist(win)
    return (win, thing)
Exemple #16
0
def step_impl(context, win):
    lang = context._root.get('my_lang', None)
    w_o_mapping = context._root.get('w_o_mapping', {})
    feature = context._stack[1]["feature"].filename
    line = context._root["my_line"]
    po_map = context._root.get('po_map', {})
    locator_map = context._root.get('locator_map', {})

    (win, _) = _resolveNames(context, win)

    # _resolveNames() already saved the indexes - we can quit now
    if lang is None:
        return

    img_name = l.imagecapture()

    re_pattern = r"(.*)auto([0-9]+)auto(.*)"
    time.sleep(1)
    obj = l.getobjectlist(win)
    w_clean = re.sub(re_pattern, "\\1\\3", win)

    # avoiding multiple appearances with the same filename
    multi_appear = {}
    for o in obj:
        print(f"Get info for {o}")
        info = l.getobjectinfo(win, o)
        o_clean = re.sub(re_pattern, "\\1\\3", o)
        # "or o_clean" means that the pattern can be applied
        if 'label' in info or o_clean:
            if 'label' in info:
                print("Get real label")
                label = l.getobjectproperty(win, o, 'label')
            else:
                print("Use object as label")
                label = o
            print(f"   label: {label}")
            size = None
            if label is None:
                print("label is none")
                continue

            try:
                size = l.getobjectsize(win, o)
                if size[0] < 0:
                    size = None
            except Exception as e:
                print(e)
                size = None
            # check if we find the "automate language"
            m = re.search(re_pattern, label)
            if m:
                print(f"Found automate here: {label}")
                id_num = m.group(2)
                if size:
                    # store "translation ID" (i.e. po-line number) for later
                    w_o_mapping[(w_clean, o_clean, line)] = id_num
                    print("Translation #{} is here: ('{}','{}')".format(
                        id_num, w_clean, o_clean))
                    print("Located in picture: {}".format(size))

            # or check if we already know the translation from the "automate language"-run
            elif (win, o, line) in w_o_mapping.keys():
                print(f"Found mapping: {label}")
                id_num = w_o_mapping[(win, o, line)]
                if size:
                    print("Found translation #{}".format(id_num))

                    # SMELL: move to feature function and execute only once
                    if not os.path.exists(OUTPUT_DIR):
                        os.makedirs(OUTPUT_DIR)
                    img = cv2.imread(img_name)
                    x = size[0]
                    y = size[1]
                    w = size[2]
                    h = size[3]
                    new_img = cv2.rectangle(img, (x, y), (x + w, y + h),
                                            (0, 0, 255), 3)
                    timestamp = int(time.time())
                    filename = f"{feature}_{lang}_po{id_num}_featureline_{line}_{timestamp}"
                    # for multiple ocurrances of one translation in the same window and same step
                    multi_appear[filename] = multi_appear.get(filename, 0) + 1
                    filename = f"{filename}_{multi_appear[filename]}.png"
                    cv2.imwrite(os.path.join(OUTPUT_DIR, filename), new_img)

                    if timestamp not in locator_map:
                        locator_map[timestamp] = []

                    locator_map[timestamp].append({
                        "x": x,
                        "y": y,
                        "w": w,
                        "h": h,
                        "timestamp": timestamp,
                        "name": f"PO{id_num}",
                        "filename": filename
                    })

            else:
                print("Neither Automate nor mapping")
    context._root["w_o_mapping"] = w_o_mapping
    context._root["locator_map"] = locator_map
def getTypeList(windowName, *objectTypes):
    if windowName in GUI_DICT:
        windowName = GUI_DICT[windowName]
    return sortObjectList(ldtp.getobjectlist(windowName), objectTypes)
Exemple #18
0
 def renew(self, control):
     try:
         return ldtp.getobjectlist(*_ldtp_args(control))
     except ldtp.client_exception.LdtpExecutionError:
         return False
Exemple #19
0
 def renew(self, control):
     try:
         return ldtp.getobjectlist(*_ldtp_args(control))
     except ldtp.client_exception.LdtpExecutionError:
         return False
def main():
    print ldtp.getobjectlist("frmSubscriptionManager")
    if not (RHSMGuiBase.check_object_exist('main-window',
                                           'nosubscriptions-in-filter-label')):
        raise FailException("Can't find the no-subscriptions text!")
def main():
    print ldtp.getobjectlist("frmSubscriptionManager") 
    if not(RHSMGuiBase.check_object_exist('main-window','nosubscriptions-in-filter-label')):
        raise FailException("Can't find the no-subscriptions text!")