예제 #1
0
def init_application(plan, app, device):
    Saver.save_crawler_log_both(plan.logPath, device.logPath,
                                "Step : init application")
    if Setting.RunInitNodes:
        appController.start_activity(device, app.packageName,
                                     app.launcherActivity)
        while True:
            launcherPage = pageController.get_page_info(plan, app, device)
            if launcherPage.clickableNodesNum == 0:
                Saver.save_crawler_log_both(plan.logPath, device.logPath,
                                            'scroll to left')
                appController.drag_screen_to_left(device)
            else:
                Saver.save_crawler_log_both(plan.logPath, device.logPath,
                                            'stop scroll')
                break
        Saver.save_crawler_log_both(plan.logPath, device.logPath,
                                    'Step : init nodes run begin')
        crawl_init_nodes(plan, app, device, launcherPage)
        del launcherPage
    if Setting.RunInitCase:
        run_init_cases(plan, app, device)
    # when go in mainActivity, will add the nodes in MainActivity to device.unCrawledNodes
    # if crawl main Nodes , after start mainActivity, these nodes can't be added to the page, will get unCrawlable page
    device.unCrawledNodes = []
    del plan, app, device
예제 #2
0
def crawl_init_nodes(plan, app, device, page_before_run):
    Saver.save_crawler_log_both(plan.logPath, device.logPath,
                                "Step : run init nodes")
    device.update_uncrawled_nodes(page_before_run)
    if page_before_run.currentActivity != app.mainActivity or page_before_run.package != app.packageName:
        page_now = pageController.get_page_info(plan, app, device)
        if page_before_run.clickableNodesNum != 0:
            device.update_crawl_page(page_before_run.nodesInfoList)
            if page_before_run.clickableNodesNum > 0:
                page_now = crawl_clickable_nodes(plan, app, device,
                                                 page_before_run, page_now,
                                                 True)
            if page_before_run.longClickableNodesNum > 0:
                page_now = crawl_longclickable_nodes(plan, app, device,
                                                     page_before_run, page_now,
                                                     True)
            if page_before_run.editTextsNum > 0:
                page_now = crawl_edittext(plan, app, device, page_before_run,
                                          page_now, False)
        del plan, app, device, page_before_run
        return page_now
    else:
        Saver.save_crawler_log_both(plan.logPath, device.logPath,
                                    'Is in ' + app.mainActivity)
        del plan, app, device
        return page_before_run
예제 #3
0
def run_test(plan, app, device):
    Saver.save_crawler_log_both(plan.logPath, device.logPath,
                                "Step : run test ")
    device.update_crawl_statue("Running")

    # init device
    appController.clean_device_logcat(device)

    # uninstall & install apk
    if Setting.UnInstallApk:
        appController.uninstall_app(device, app.packageName)
        appController.uninstall_app(device, app.testPackageName)
    if Setting.InstallApk:
        appController.install_app(device, app.apkPath)
        appController.install_app(device, app.testApkPath)

    # init app
    init_application(plan, app, device)

    # begin crawl
    if Setting.CrawlModel == 'Normal' or Setting.CrawlModel == 'Random':
        Saver.save_crawler_log_both(plan.logPath, device.logPath,
                                    "Step : begin to crawl main nodes")
        appController.start_activity(device, app.packageName, app.mainActivity)
        time.sleep(5)
        page = pageController.get_page_info(plan, app, device)
        device.update_begin_crawl_time()
        crawl_main_nodes(plan, app, device, page)
        del page

    crawl_activities(plan, app, device)
    device.endCrawlTime = datetime.datetime.now()
    Saver.save_logcat(plan, device)
    # clean unusable files
    pageController.remove_uidump_xml_file(device)

    # update & save result
    Saver.save_crawler_log_both(
        plan.logPath, device.logPath, "Step : " + device.id + " has Crawled " +
        str(len(device.hasCrawledNodes)) + " nodes.")
    Saver.save_crawler_log_both(
        plan.logPath, device.logPath, "Step : " + device.id + " there are " +
        str(len(device.unCrawledNodes)) + " unCrawled nodes .")
    Saver.save_crawler_log_both(
        plan.logPath, device.logPath, "Step : " + device.id + " has Crawled " +
        str(len(device.hasCrawledActivities)) + " activities .")
    if device.crawlStatue == 'Running':
        device.update_crawl_statue('Passed')
    if device.crawlStatue == "Passed":
        plan.passedDevice += 1
    else:
        plan.failedDevice += 1
예제 #4
0
def crawl_activities(plan, app, device):
    if Setting.CrawlModel == 'Activity':
        for activity in app.activities:
            appController.start_activity(device, app.packageName,
                                         app.launcherActivity)
            time.sleep(3)
            if appController.start_activity(device, app.packageName, activity):
                page = pageController.get_page_info(plan, app, device)
                crawl_nodes_in_an_activity(plan, app, device, activity, page,
                                           page)
                appController.kill_app(app)
                del page
            del activity
    del plan, app, device
예제 #5
0
def crawl_activities(plan, app, device):
    if Setting.CrawlModel == 'Activity':
        for activity in app.activities:
            appController.start_activity(device, app.packageName, app.mainActivity)
            time.sleep(3)
            appController.start_activity(device, app.packageName, activity)
            time.sleep(2)
            info = pageController.get_top_activity_info(device)
            if info['activity'] == activity:
                page = pageController.get_page_info(plan, app, device)
                crawl_nodes_in_an_activity(plan, app, device, activity, page, page)
                appController.kill_app(app)
                del page
            del activity, info
    del plan, app, device
예제 #6
0
def crawl_main_nodes(plan, app, device, page_before_run):
    device.update_uncrawled_nodes(page_before_run)
    page_now = pageController.get_page_info(plan, app, device)
    if pageController.page_is_crawlable(app, device, page_before_run):
        device.update_crawl_page(page_before_run.nodesInfoList)
        if page_before_run.clickableNodesNum > 0:
            page_now = crawl_clickable_nodes(plan, app, device,
                                             page_before_run, page_now, False)
        if page_before_run.longClickableNodesNum > 0:
            page_now = crawl_longclickable_nodes(plan, app, device,
                                                 page_before_run, page_now,
                                                 False)
        if page_before_run.editTextsNum > 0:
            page_now = crawl_edittext(plan, app, device, page_before_run,
                                      page_now, False)
    del plan, app, device, page_before_run
    return page_now