示例#1
0
def load_example(filename):
    (items, descs) = analyze.load_case(filename)

    printdesc(items, descs)

    good_ids = get_good_ids(items, descs)

    return (items, descs, good_ids)
示例#2
0
def seetext(dev, text, observer):
    for i in range(config.CHECK_RETRY_LIMIT):
        gui_state = observer.grab_state(dev, no_img=True)
        items = gui_state.get('items')
        text = text.lower()
        for itemid in items:
            item = items[itemid]
            if text_in_item(text, item):
                return True
        if config.CHECK_OTHER_WINDOWS:
            for winid in range(2, 10):
                targetfile = "/tmp/win.xml"
                if not sense.grab_extra_win(dev, winid, targetfile):
                    break
                items = analyze.load_case(targetfile)[0]
                for itemid in items:
                    if text_in_item(text, items[itemid]):
                        return True

        time.sleep(1)
    logger.warn("see %s timeout", text)
    return False
示例#3
0
def gen_hints(app=None):
    if app is None:
        appdb.collect_apps("../apks/")
        apps = appdb.apps
    else:
        apps = [app]
    for app in apps:
        scr_clas = classify.getmodel("../model/", "../guis", app)
        for screen in tags.tag:
            elem_clas = elements.getmodel("../model/", "../guis/", app)
            locs = {}
            screenhint = 0
            fail_tag = set()
            elem_hint = set()
            for filename in glob.glob("../guis/%s*%s.xml" % (app, screen)):
                (items, descs) = analyze.load_case(filename)
                tree = analyze.analyze_items(items, descs)

                xmldata = open(filename).read()

                actfile = filename.replace('.xml', '.txt')
                actname = open(actfile).read()

                imgfile = filename.replace('.xml', '.png')
                imgdata = sense.load_image(imgfile)

                guess_scr = scr_clas.classify(xmldata, actname, imgfile)
                if guess_scr != screen:
                    screenhint += 1

                for itemid in items:
                    if itemid in descs:
                        loc = locator.get_locator(items, itemid)
                        tag = descs[itemid]
                        if loc is not None:
                            locs[tag] = locs.get(tag, []) + [loc]
                        else:
                            fail_tag.add(tag)

                for tag in tags.tag[screen]:
                    nodeid = find_element(tag, elem_clas, tree, screen,
                                          imgdata)
                    if nodeid is None:
                        if nodeid in descs.values():
                            elem_hint.add(tag)
                        continue
                    for itemid in items:
                        if itemid in descs and descs[itemid] == tag:
                            if not itemid in tree[nodeid]['raw']:
                                elem_hint.add(tag)

            for tag in locs:
                taglocs = set()
                for loc in locs[tag]:
                    taglocs.add("%s" % loc)

                while taglocs:
                    print("%s %s @%s %s" % (app, screen, tag, taglocs.pop()))

            for tag in fail_tag:
                if tag in elem_hint:
                    print("FAIL for %s %s %s" % (app, screen, tag))

            for tag in elem_hint:
                print("ELEMHINT for %s %s %s" % (app, screen, tag))

            if screenhint:
                print("SCREENHINT for %s %s" % (app, screen))
示例#4
0
import elements
import tags

empty_re = re.compile("WebView[^/>]+/>")

tags.load("../etc/tags.txt")

total_pt_cnt = 0
err_cnt = 0
for filename in glob.glob("../guis/*.xml"):
    imgfile = filename.replace('.xml', '.png')
    if not os.path.exists(imgfile):
        print("%s NOIMG" % filename)

    scrname = filename.split('/')[-1].split('.')[0].split('_')[-1]
    (items, descs) = analyze.load_case(filename)
    tree = analyze.analyze_items(items, descs)
    if items and descs and tree:
        tag_cnt = {}
        for itemid in tree:
            node = tree[itemid]
            if node['tags']:
                firsttag = node['tags'][0]
                tag_cnt[firsttag] = tag_cnt.get(firsttag, 0) + 1
        for tag in tag_cnt:
            if tags.valid(scrname, tag):
                if tag_cnt[tag] > 1:
                    if tag in elements.SINGLE_LABEL:
                        print("%s DUPTAG %s %d" %
                              (filename, tag, tag_cnt[tag]))
            else:
示例#5
0
def guess(filename, lasttag=None):
    basename = filename.replace('.xml', '')
    (items, descs) = analyze.load_case(filename)
    #    if descs:
    #        return

    appname = basename.split('/')[-1].split('.')[0].split('_')[0]
    scrname = basename.split('/')[-1].split('.')[0].split('_')[-1]
    imgfile = filename.replace('.xml', '.png')

    if not appname in tag_db:
        tag_db[appname] = {}
    if appname in tag_db:
        for tag in tag_db[appname]:
            xid = tag_db[appname][tag]
            for itemid in items:
                if items[itemid]['id'] == xid:
                    descs[itemid] = tag

    print("%s Current:" % basename)
    util.printdesc(items, descs)
    #    analyze.printitems(items)
    tree = analyze.analyze([filename])[0]
    util.print_tree(tree, descs)

    viewproc = subprocess.Popen([config.picviewer_path, basename + ".png"])

    prompt = ''
    while True:
        print(tags.tag['universal'])
        if scrname in tags.tag:
            print(tags.tag[scrname])
        line = input(prompt + "> ")
        parts = line.split(' ')
        cmd = parts[0]

        if cmd == '':
            util.save_desc(basename, descs)
            break
        elif cmd[0] == 'q':
            viewproc.kill()
            sys.exit(0)

        elif cmd[0] == 'l':
            listid = int(parts[1])
            listtype = parts[2]
            guess_list(listid, listtype, items, descs)
            util.printdesc(items, descs)

        elif cmd[0] == 'a':
            auto_guess(filename, items, descs)
            util.print_tree(tree, descs)

        elif cmd[0] == 'y':
            util.save_desc(basename, descs)
            break

        elif cmd[0] >= '0' and cmd[0] <= '9':
            if len(parts) > 1:
                lasttag = parts[1]
                util.mark_item(parts, items, descs, scrname, tag_db[appname])
                util.print_tree(tree, descs)
            else:
                if lasttag is None:
                    print(util.describe(items[int(cmd)]))
                else:
                    util.mark_item([cmd, lasttag], items, descs, scrname,
                                   tag_db[appname])
                    util.print_tree(tree, descs)
        elif cmd[0] == 'd':
            if cmd == 'dr':
                recursive = True
            else:
                recursive = False
            util.remove_mark(parts[1:], items, descs, recursive)
            util.print_tree(tree, descs)

        elif cmd[0] == ';':
            util.print_tree(tree, descs)
        elif cmd[0] == '!':
            util.printitems(items)
        elif cmd[0] == 'c':
            element_clas = elements.getmodel("../model/", "../guis/", None)
            imgdata = skimage.io.imread(imgfile, as_grey=True)
            imgdata = skimage.transform.resize(imgdata,
                                               (config.height, config.width))
            treeinfo = analyze.collect_treeinfo(tree)
            for itemid in tree:
                (guess_element,
                 score) = element_clas.classify(scrname, tree, itemid, imgdata,
                                                treeinfo)
                if guess_element != 'NONE':
                    descs[itemid] = guess_element
            util.print_tree(tree, descs)
        elif cmd[0] == '?':
            print(util.describe(items[int(parts[1])]))
        else:
            print("Unknown command")

    viewproc.kill()