コード例 #1
0
def run_ui_traversal(scenario, scenarios, emulator_id, smart_input_results, smart_input_assignment):
    smart_input_for_activity = smart_input_results.get(scenario.static_analysis_result.activity_name)

    start_app(emulator_id, scenarios.package)

    start_activity(emulator_id, scenarios.package, scenario.static_analysis_result.activity_name)

    device, serialno = ViewClient.connectToDeviceOrExit(serialno=emulator_id)
    vc = ViewClient(device, serialno, autodump=False)

    # try dumping 5 times, before timing out
    dump_tries = 0
    dump_error = True
    while dump_error and dump_tries < 5:
        dump_error = False
        dump_tries += 1
        try:
            vc.dump(sleep=5)
        except Exception:
            dump_error = True
    if dump_error:
        raise SoftTimeLimitExceeded()

    edittexts = vc.findViewsWithAttribute("class", "android.widget.EditText")
    logger.info("EditText views: %s" % str(edittexts))
    clickable_views = vc.findViewsWithAttribute("clickable", "true")
    logger.info("Clickable views: %s" % str(clickable_views))
    listviews = vc.findViewsWithAttribute("class", "android.widget.ListView")
    logger.info("ListViews: %s" % str(listviews))

    fill_edit_texts(edittexts, smart_input_for_activity, smart_input_assignment, vc, emulator_id)

    click_clickable_views(clickable_views, vc, device, emulator_id)
コード例 #2
0
def check():
    print("check")
    os.system("adb shell cmd statusbar expand-notifications")

    from com.dtmilano.android.viewclient import ViewClient

    device, serialno=ViewClient.connectToDeviceOrExit()
    vc=ViewClient(device=device, serialno=serialno)

    Icon=vc.findViewsWithAttribute("resource-id","com.android.systemui:id/mobile_combo_card")
    time.sleep(1)
    vc.dump()
    Mode=(Icon[0].getContentDescription())
    List=list(Mode)
    L1=List[0]
    L2=List[1]
    global String
    String= L1+ L2
    print(String)
    Split=Mode.split(' ')
    
    L3=Split[1]
    
    L4=Split[2]
    combine=L3+" " + L4
    print(combine)
          
    sets=String+" " + combine
    print(sets)
    
    global gets
    gets=String+" "+ L3
    print(gets)
コード例 #3
0
def loadScreenshots():
    # Read all chats in list
    device, serialno = ViewClient.connectToDeviceOrExit()
    device.press('KEYCODE_HOME')
    device.startActivity(component=component)
    ViewClient.sleep(TOUCH_LONG_SLEEP)
    vc = ViewClient(device, serialno, autodump=True)
    putMainScreen(vc)
    toStart(vc)  ##coments if necessary continue a extraction
    vc.dump()
    new_chats = True
    while new_chats:  #check screen changes (in chat list) after dragging

        # track the chat list beginning.
        brute_chatList = vc.findViewsWithAttribute('class',
                                                   'android.view.ViewGroup')

        if brute_chatList[0] is None:
            logging.error('Cant go back to Facebook Home')
            quit()

        # capture new chats in screen list
        chatList = []
        new_chats = False

        for c in brute_chatList[0].children:
            if len(c.getText()) > 0 and c.getText(
            ) != 'Online' and not c.getContentDescription() in visitedChats:
                print c.getContentDescription().encode('utf-8')
                chatList.append(c)
                new_chats = True
        print "new Chats:(", len(chatList), ")", 'total ', len(visitedChats)
        # process new chats
        for chat in chatList:
            print '->' + chat.getContentDescription().encode(
                'utf-8'), chat.getTag(), chat.getUniqueId()
            path = ''
            if isinstance(chat.getContentDescription(), unicode):
                path = unicode(
                    extraction_path + '/' +
                    norm_unicode_filename(chat.getContentDescription()))
            if isinstance(chat.getContentDescription(), str):
                path = extraction_path + '/' + werkzeug.utils.secure_filename(
                    chat.getContentDescription().encode('utf-8'))

            os.mkdir(path, 0777)

            device, serialno = ViewClient.connectToDeviceOrExit()
            vc = ViewClient(device, serialno)

            chat.touch()
            #print 'touching...'
            if vc.isKeyboardShown():
                device.press('KEYCODE_BACK')
            root = vc.findViewsWithAttribute('class', 'android.view.ViewGroup')
            #print "Grupo:", len(root), root[0].getContentDescription(), root[0].getText()
            vc = ViewClient(device, serialno)

            # snapshot screen
            screenshot_count = 1
            before_dump = ''
            strScreen = StringIO.StringIO()
            vc.traverse(transform=ViewClient.TRAVERSE_CITPS, stream=strScreen)
            after_dump = strScreen.getvalue()
            while before_dump != after_dump:  #check screen changes (in msgs list) after dragging
                before_dump = after_dump
                print 'screenshot', screenshot_count
                device.takeSnapshot().save(
                    path + '/screenshot_' + str(screenshot_count) + ".png",
                    'PNG')
                device, serialno = ViewClient.connectToDeviceOrExit()
                vc = ViewClient(device, serialno)
                #print 'connected?',device.checkConnected()
                device.dragDip((169.0, 297.0), (173.0, 600.0), 1000, 20, 0)

                attemptCount = 0
                while attemptCount < 5:
                    try:
                        attemptCount = attemptCount + 1
                        vc = ViewClient(device, serialno)
                        break
                    except:
                        print 'Houston...we have a problem (BEEP) - small drag tilt'
                        device.dragDip((169.0, 297.0), (173.0, 310.0), 1000,
                                       20, 0)
                if attemptCount == 5:
                    print 'ERROR'
                    exit(1)
                strScreen = StringIO.StringIO()
                vc.traverse(transform=ViewClient.TRAVERSE_CITPS,
                            stream=strScreen)
                after_dump = strScreen.getvalue()
                screenshot_count = screenshot_count + 1
            visitedChats.append(chat.getContentDescription())
            putMainScreen(vc)
            #device.press('KEYCODE_BACK');
        # drag chat list
        device.dragDip((173.0, 560.0), (169.0, 150.0), 1000, 20, 0)
        vc = ViewClient(device, serialno)
        #Am i in FBM home?
        print 'put main screen'
        putMainScreen(vc)

    print 'Total chats:', len(visitedChats)