Ejemplo n.º 1
0
def re_crawl_mack_error_node(plan, app, device, page_before_run, node,
                             activity):
    appController.start_activity(device, app.packageName, activity)
    page_now = get_page_info(plan, app, device)
    if nodeController.recover_node_shown(plan, app, device, page_now,
                                         page_before_run, node):
        device.save_make_error_node_screen(node)
        if node.crawlOperation == 'tap':
            appController.tap_node(device, node)
        elif node.crawlOperation == 'longclick':
            appController.long_click_node(device, node)
        elif node.crawlOperation == 'type':
            t = appController.get_random_text(8)
            appController.type_text(device, node, t)
        if not appController.app_is_running(device, app):
            Saver.save_error_logcat(plan, device)
            HtmlMaker.make_failed_result_html(plan, app)
            MailSender.send_failed_mail_necessary(plan, app, device, node)
            del plan, app, device, page_before_run, node, activity, page_now
            return False
        else:
            HtmlMaker.make_failed_result_html(plan, app)
            MailSender.send_failed_mail_un_necessary(plan, app, device)
    del plan, app, device, page_before_run, node, activity, page_now
    return True
Ejemplo n.º 2
0
def check_activity_after_operation(plan, app, device, crawl_activity, page_before_run, node):
    Saver.save_crawler_log(device.logPath, "Step : Check page after operation")
    # if app crashed after crawl , save log & start app ,comtinue
    if Setting.TimeModel == 'Limit':
        time_now = datetime.datetime.now()
        if (time_now - device.beginCrawlTime).seconds > (Setting.LimitTime * 60):
            Saver.save_crawler_log_both(plan.logPath, device.logPath, "Step : crawl time out , finish crawl.")
            del plan, app, device, crawl_activity, time_now
            return None
        del time_now
    while True:
        info = get_top_activity_info(device)
        package = info['packagename']
        activity = info['activity']
        if len(package) != 0:
            break
    times = 0
    while activity != crawl_activity:
        if not appController.app_is_running(device, app):
            Saver.save_error_logcat(plan, device)
            appController.clean_device_logcat(device)
            HtmlMaker.make_failed_result_html(plan, app)
            MailSender.send_failed_mail_first(plan, app, device)
            if not re_crawl_mack_error_node(plan, app, device, page_before_run, node, crawl_activity) and Setting.KeepRun:
                appController.kill_app(app)
                appController.start_activity(device, app.packageName, crawl_activity)
            else:
                Saver.save_crawler_log_both(plan.logPath, device.logPath,
                                            "Step : crawl app " + device.crawlStatue + ', break crawling..')
                return None
        Saver.save_crawler_log(device.logPath, 'back to ' + crawl_activity)
        device.save_screen_jump_out(package, activity)
        appController.click_back(device)
        time.sleep(2)
        times += 1
        top_activity_info = get_top_activity_info(device)
        package = top_activity_info['packagename']
        activity = top_activity_info['activity']
        if times > 3:
            Saver.save_crawler_log(device.logPath,
                                   "can't back to " + crawl_activity + " after click back 3 times , Restart app")
            appController.start_activity(device, app.packageName, crawl_activity)
            top_activity_info = get_top_activity_info(device)
            top_app_package = top_activity_info['packagename']
            if top_app_package == app.packageName:
                del package, top_activity_info, top_app_package
                break
    del plan, app, device, crawl_activity, activity
    return get_page_info(plan, app, device)
Ejemplo n.º 3
0
def check_page_after_operation(plan, app, device, page_before_run, node):
    Saver.save_crawler_log(device.logPath, "Step : Check page after operation")
    # if app crashed after crawl , save log & start app ,continue
    if Setting.TimeModel == 'Limit':
        time_now = datetime.datetime.now()
        if (time_now - device.beginCrawlTime).seconds > (Setting.LimitTime *
                                                         60):
            Saver.save_crawler_log_both(
                plan.logPath, device.logPath,
                "Step : crawl time out , finish crawl.")
            del plan, app, device, time_now
            return None
    while True:
        info = get_top_activity_info(device)
        package = info['packagename']
        activity = info['activity']
        if len(package) != 0:
            del info
            break
        del info
    times = 0
    while package != app.packageName:
        if not appController.app_is_running(device, app):
            Saver.save_error_logcat(plan, device)
            appController.clean_device_logcat(device)
            HtmlMaker.make_failed_result_html(plan, app)
            MailSender.send_failed_mail_first(plan, app, device)
            if not re_crawl_mack_error_node(
                    plan, app, device, page_before_run, node,
                    app.launcherActivity) and Setting.KeepRun:
                appController.kill_app(app)
                appController.start_activity(device, app.packageName,
                                             app.launcherActivity)
            else:
                Saver.save_crawler_log_both(
                    plan.logPath, device.logPath, "Step : crawl app " +
                    device.crawlStatue + ', break crawling..')
                del plan, app, device, package, activity
                return None
        Saver.save_crawler_log(device.logPath, 'back to ' + app.packageName)
        device.save_screen_jump_out(package, activity)
        appController.click_back(device)
        times += 1
        top_activity_info = get_top_activity_info(device)
        package = top_activity_info['packagename']
        activity = top_activity_info['activity']
        if times > 3:
            Saver.save_crawler_log(
                device.logPath, "can't back to " + app.packageName +
                " after click back 3 times , Restart app")
            appController.start_activity(device, app.packageName,
                                         app.launcherActivity)
            top_activity_info = get_top_activity_info(device)
            top_app_package = top_activity_info['packagename']
            if top_app_package == app.packageName:
                del top_activity_info, times, top_app_package
                break
    # if keyboard shown , click device back btn to close keyboard
    if appController.keyboard_is_shown(device):
        appController.click_back(device)
    if activity == 'com.mob.tools.MobUIShell':
        Saver.save_crawler_log(device.logPath, "close login web QQ/Weibo")
        appController.click_back(device)
    page = get_page_info(plan, app, device)
    if page is not None and page.currentActivity == app.loginActivity and Setting.Login:
        app.update_loginactivity_entry(node)
        page = login_by_account(plan, page, app, device)
    del plan, app, device, page_before_run, node
    return page