def get_menu():
    try:
        a = randint(1, 5)
        for m in range(a):
            d.swipe(500, 1000, 500, 300)
            time.sleep(1)
        takeout_name = d(resourceId="com.yiwosi.kbb:id/tVTitle")[a].get_text()
        logger.info('点击的外卖是{}'.format(takeout_name))
        d(resourceId="com.yiwosi.kbb:id/tVTitle")[a].click()
        takeout_get_menu_time = time.time()
        while not d(resourceId="com.yiwosi.kbb:id/tv_price").exists:
            h_appear_time = time.time()
            h_cost_time = h_appear_time - takeout_get_menu_time
            if h_cost_time > 15:
                logger.warning('等待店铺商品超15s,返回上个页面重新操作')
                d.app_stop(app_name)
                takeout_get_menu_time = time.time()
                break
        logger.info('外卖店铺商品详情页耗时{}'.format(h_cost_time))
        e = EexeclData(file=target_file, sheet_name='详情页')
        e.write_cell(i + 1, 1, i)
        e.write_cell(i + 1, 2, h_cost_time)
        now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        e.write_cell(i + 1, 3, now_time)
        logger.info('外卖店铺商品详情页表格数据更新成功')
    except BaseException as e:
        logger.error('外卖店铺商品详情页出错{}'.format(e))
        send_msg(takeout_webhook, '外卖店铺商品详情页出错')
        now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        d.screenshot(t_screenshot_path + '{}.jpg'.format(now_time))
        get_adb_all_process(now_time)
        time.sleep(1)
        d.app_stop(app_name)
def tran_list():
    click_time = time.time()
    d(text="搜索").click()
    logger.info("点击了火车票搜索")
    while not d(resourceId="com.yiwosi.kbb:id/text_start_time").exists:
        h_appear_time = time.time()
        h_cost_time = h_appear_time - click_time
        if d(text='重新查询').exists:
            d.pess('back')
            time.sleep(1)
            train_city_select()
            tran_list()
            break
        elif h_cost_time > 15:
            logger.warning('等待火车票列表超10s,返回上个页面重新操作')
            d.app_stop(app_name)
            click_time = time.time()
            break
    logger.info('火车票列表页耗时{}'.format(h_cost_time))
    e = EexeclData(file=target_file, sheet_name='列表页')
    e.write_cell(i + 1, 1, i)
    e.write_cell(i + 1, 2, h_cost_time)
    now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
    e.write_cell(i + 1, 3, now_time)
    logger.info('火车票列表页数据更新成功')
def get_takeout_list():
    """
    获取外卖首页列表数据
    """
    try:
        takeout_click_time = time.time()
        while not d(resourceId="com.yiwosi.kbb:id/tVTitle").exists:
            h_appear_time = time.time()
            h_cost_time = h_appear_time - takeout_click_time
            if h_cost_time > 15:
                logger.warning('等待外卖列表超10s,返回上个页面重新操作')
                d.app_stop(app_name)
                takeout_click_time = time.time()
                break
        logger.info('外卖列表页耗时{}'.format(h_cost_time))
        e = EexeclData(file=target_file, sheet_name='列表页')
        e.write_cell(i + 1, 1, i)
        e.write_cell(i + 1, 2, h_cost_time)
        now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        e.write_cell(i + 1, 3, now_time)
        logger.info('外卖列表页表格数据更新成功')
    except BaseException as e:
        logger.error('外卖列表页出错{}'.format(e))
        send_msg(takeout_webhook, '外卖列表页出错')
        now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        d.screenshot(t_screenshot_path + '{}.jpg'.format(now_time))
        get_adb_all_process(now_time)
        time.sleep(1)
        d.app_stop(app_name)
Beispiel #4
0
def app_update():
    """
    检测安卓是否存在新版本
    """
    ip = get_adb()[0]
    d = u2.connect(ip)
    if d(text='稍后再说').exists:
        d(text='稍后再说').click()
        logger.warning('检测到安卓app存在新版本,请及时更新')
        time.sleep(1)
def add_menu():
    try:
        time.sleep(1)

        if d(resourceId="com.yiwosi.kbb:id/car_badge").exists:
        # 情况购物车
            d(resourceId="com.yiwosi.kbb:id/iv_shop_car").click()
            time.sleep(1)
            d(resourceId="com.yiwosi.kbb:id/tViewClear").click()
            time.sleep(1)
            d(text='清空').click()
            time.sleep(2)
        
        for m in range(4):
            d.swipe(500, 1500, 500, 300)
            time.sleep(1)
            # 点击加入购物车按钮
            d(resourceId="com.yiwosi.kbb:id/addbutton")[m].click()
            time.sleep(1)
            if d(resourceId="com.yiwosi.kbb:id/tViewOK").exists:
                d(resourceId="com.yiwosi.kbb:id/tViewOK").click()
                time.sleep(1)
            m+=1
        logger.info('购物车数据添加成功')
        time.sleep(1)
        # 点击去结算按钮
        d(resourceId="com.yiwosi.kbb:id/car_limit").click()
        takeout_add_menu_time = time.time()
        while not d(resourceId="com.yiwosi.kbb:id/text_show_time").exists:
            # 判断送达时间是否存在
            h_appear_time = time.time()
            h_cost_time = h_appear_time - takeout_add_menu_time
            if h_cost_time > 15:
                logger.warning('等待提交订单页面超15s,返回上个页面重新操作')
                takeout_add_menu_time = time.time()
                break
        logger.info('提交订单页面耗时{}'.format(h_cost_time))
        e = EexeclData(file=target_file, sheet_name='提交订单页')
        e.write_cell(i + 1, 1, i)
        e.write_cell(i + 1, 2, h_cost_time)
        now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        e.write_cell(i + 1, 3, now_time)
        logger.info('提交订单页面表格数据更新成功')
        time.sleep(1)
    except BaseException as e:
        logger.error('提交订单页面出错{}'.format(e))
        send_msg(takeout_webhook, '提交订单页面出错')
        now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        d.screenshot(t_screenshot_path + '{}.jpg'.format(now_time))
        get_adb_all_process(now_time)
        time.sleep(1)
        d.app_stop(app_name)
Beispiel #6
0
def pre_test(category):
    """
    前置操作
    paramas: app首页的类目名称,如酒店,机票
    """
    try:
        ip = get_adb()[0]
        d = u2.connect(ip)
        if not d.info.get('screenOn'):
            # 如黑屏,则解锁
            d.screen_on()
            time.sleep(1)
            d.swipe_ext("up", 0.7)
            logger.info('检测到已锁屏,已解锁')
        d.watcher.when('resourceId="android:id/aerr_restart"').click()
        d.app_start(app_name)
        time.sleep(5)
        if d(text='稍后再说').exists:
            d(text='稍后再说').click()
            logger.warning('检测到安卓app存在新版本,请及时更新')
            time.sleep(1)
        # app_update()
        d(text='首页').click()
        time.sleep(1)
        d(text=category).click()
        logger.info('已打开{}类目'.format(category))
        time.sleep(1)
    except BaseException as e:
        logger.error('{}前置操作出错_andriod_{}'.format(category,e))
        if category == '酒店':
            send_msg(hotel_webhook, '{}前置操作出错_andriod'.format(category))
        elif category == '机票':
            send_msg(fly_webhook, '{}前置操作出错_andriod'.format(category))
        elif category == '外卖':
            send_msg(takeout_webhook, '{}前置操作出错_andriod'.format(category))
        elif category == '打车':
            send_msg(taxi_webhook, '{}前置操作出错_andriod'.format(category))
        elif category == '火车票':
            send_msg(train_webhook, '{}前置操作出错_andriod'.format(category))
        elif category == '加油':
            send_msg(gasoil_webhook, '{}前置操作出错_andriod'.format(category))                        
        now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        # d.screenshot(screenshot_path + '{}.jpg'.format(now_time))
        get_adb_all_process(now_time)
        time.sleep(1)
        d.app_stop(app_name)
Beispiel #7
0
def fly_city_select():
    """
    机票出发地选择
    """
    d.watcher.when('resourceId="android:id/aerr_restart"').click()
    try:
        time.sleep(1)
        d(resourceId="com.yiwosi.kbb:id/bord_city").click()
        time.sleep(1)
        d(resourceId="com.yiwosi.kbb:id/search_locate_content_et").click()
        time.sleep(1)
        address = random_address('list_address')
        d(focused=True).set_text(address)
        time.sleep(2)
        logger.info('选择的出发城市是{}'.format(address))
        if d(resourceId="com.yiwosi.kbb:id/iv_empty_data").exists:
            logger.warning('没有搜到你要的城市,重新搜索')
            d.press('back')
            time.sleep(1)
            fly_city_select()
        d(resourceId="com.yiwosi.kbb:id/city_name_tv").click()
        time.sleep(1)
        d(resourceId="com.yiwosi.kbb:id/off_city").click()
        time.sleep(1)
        d(resourceId="com.yiwosi.kbb:id/search_locate_content_et").click()
        time.sleep(1)
        address = random_address('list_address')
        d(focused=True).set_text(address)
        time.sleep(2)
        if d(resourceId="com.yiwosi.kbb:id/iv_empty_data").exists:
            logger.warning('没有搜到你要的城市,重新搜索')
            fly_city_select()

        d(resourceId="com.yiwosi.kbb:id/city_name_tv").click()
        logger.info('选择的到达城市是{}'.format(address))
        e = EexeclData(file=target_file, sheet_name='列表页')
        e.write_cell(i + 1, 4, address)

    except BaseException as e:
        logger.error('城市选择出错{}'.format(e))
        send_msg(fly_webhook, '城市选择出错')
        now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        d.screenshot(f_screenshot_path + '{}.jpg'.format(now_time))
        get_adb_all_process(now_time)
        time.sleep(1)
        d.app_stop(app_name)
Beispiel #8
0
def get_gasoil_detail():
    """
    获取油站详情
    """
    try:
        a = randint(1, 6)
        for m in range(a):
            d.swipe(500, 1000, 500, 300)
            time.sleep(1)
        # 选择第一个油站
        gasoil_station_name = d(
            resourceId="com.yiwosi.kbb:id/text_station_name")[0].get_text()
        logger.info('点击的油站是{}'.format(gasoil_station_name))
        d(resourceId="com.yiwosi.kbb:id/text_station_name")[0].click()
        get_gasoil_detail_time = time.time()
        while not d(text="加油金额").exists:
            h_appear_time = time.time()
            h_cost_time = h_appear_time - get_gasoil_detail_time
            if h_cost_time > 15:
                logger.warning('等待油站详情超15s,返回上个页面重新操作')
                d.app_stop(app_name)
                get_gasoil_detail_time = time.time()
                break
        logger.info('提交订单页面耗时{}'.format(h_cost_time))
        e = EexeclData(file=target_file, sheet_name='提交订单页')
        e.write_cell(i + 1, 1, i)
        e.write_cell(i + 1, 2, h_cost_time)
        now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        e.write_cell(i + 1, 3, now_time)
        logger.info('提交订单页面表格数据更新成功')
        time.sleep(1)
    except BaseException as e:
        logger.error('提交订单页出错{}'.format(e))
        send_msg(gasoil_webhook, '提交订单页出错')
        now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        d.screenshot(t_screenshot_path + '{}.jpg'.format(now_time))
        get_adb_all_process(now_time)
        time.sleep(1)
        d.app_stop(app_name)
Beispiel #9
0
def get_gasoil_list():
    """
    加油列表页
    """
    global gasoline_list_elapsed, national_price_elapsed, coupons_banner_elapsed
    try:

        gasoil_click_time = time.time()
        while not d(resourceId="com.yiwosi.kbb:id/text_station_name").exists:
            h_appear_time = time.time()
            h_cost_time = h_appear_time - gasoil_click_time
            if h_cost_time > 15:
                logger.warning('等待加油列表超10s,返回上个页面重新操作')
                d.app_stop(app_name)
                gasoil_click_time = time.time()
                break
        h_appear_time = time.time()
        h_cost_time = h_appear_time - gasoil_click_time
        logger.info('加油列表页耗时{}'.format(h_cost_time))
        e = EexeclData(file=target_file, sheet_name='列表页')
        e.write_cell(i + 1, 1, i)
        e.write_cell(i + 1, 2, h_cost_time)
        now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        e.write_cell(i + 1, 3, now_time)
        logger.info('加油列表表格数据更新成功')

        now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        get_adb_all_process(now_time)
        file_name = '{}adb_{}.log'.format(os.getcwd() + '/Logs/', now_time)
        with open(file_name, 'r', encoding='utf8') as file:
            out_pri = file.read()
            # 获取加油列表/api/gasoline/list 耗时
            gasoline_list_elapsed1 = re.findall('"station_img"(.*)',
                                                out_pri.strip())
            gasoline_list_elapsed = re.findall('"elapsed":(.*)}',
                                               str(gasoline_list_elapsed1))[0]
            logger.info(
                'gasoline_list_elapsed:{}'.format(gasoline_list_elapsed))
            e.write_cell(i + 1, 6, gasoline_list_elapsed)
            e.write_cell(1, 6, "gasoline/list")

            # 获取加油列表/api/national-price 耗时
            national_price_elapsed1 = re.findall('getNationalPrice(.*)',
                                                 out_pri.strip())
            national_price_elapsed = re.findall(
                '"elapsed":(.*)}', str(national_price_elapsed1))[0]
            logger.info(
                'national_price_elapsed:{}'.format(national_price_elapsed))
            e.write_cell(i + 1, 7, national_price_elapsed)
            e.write_cell(1, 7, "national-price")

            # 获取加油列表/api/coupons/banner 耗时
            # coupons_banner_elapsed1 = re.findall('discount_periods(.*)', out_pri.strip())
            # coupons_banner_elapsed = re.findall('"elapsed":(.*),"req_sn"', str(coupons_banner_elapsed1))[0]
            # logger.info('coupons_banner_elapsed:{}'.format(coupons_banner_elapsed))
            # e.write_cell(i + 1, 8, coupons_banner_elapsed)
            # e.write_cell(1, 8, "coupons/banner")

            # /api/banners
            # banners_elapsed1 = re.findall('"message":"banners","data":{"banners"(.*)', out_pri.strip())
            # banners_elapsed = re.findall('"elapsed":(.*),"req_sn"', str(banners_elapsed1))[0]
            # logger.info('banners_elapsed:{}'.format(banners_elapsed))
            # e.write_cell(i + 1, 8, banners_elapsed)
            # e.write_cell(1, 8, "/api/banners")

    except BaseException as e:
        logger.error('加油列表出错{}'.format(e))
        send_msg(gasoil_webhook, '加油列表出错')
        now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        d.screenshot(t_screenshot_path + '{}.jpg'.format(now_time))
        get_adb_all_process(now_time)
        time.sleep(1)
Beispiel #10
0
def fly_order():
    try:
        time.sleep(1)
        # 点击机票列表第一个数据
        d.click(0.862, 0.359)
        d_click_time = time.time()
        while not d(text="提交订单").exists:
            d_appear_time = time.time()
            d_cost_time = d_appear_time - d_click_time
            if d_cost_time > 10:
                logger.warning('等待机票订单页跳转超时')
                d.app_stop(app_name)
                d_click_time = time.time()
                break
        time.sleep(1)
        logger.info('提交订单页耗时{}'.format(d_cost_time))
        e = EexeclData(file=target_file, sheet_name='提交订单页')
        e.write_cell(i + 1, 1, i)
        e.write_cell(i + 1, 2, d_cost_time)
        now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        e.write_cell(i + 1, 3, now_time)
        logger.info('提交订单页表格数据更新成功')
        time.sleep(1)
        d(text="张海浩").click()
        time.sleep(1)
        d(text="提交订单").click()
        e_click_time = time.time()
        if d(resourceId="com.yiwosi.kbb:id/commitTV").exists:
            # 出现当前航班售价有变化,请刷新价格的提示时重新操作
            d(resourceId="com.yiwosi.kbb:id/commitTV").click()
        logger.info('点击了提交订单')
        while not d(resourceId="com.yiwosi.kbb:id/tViewWechat").exists:
            e_appear_time = time.time()
            e_cost_time = e_appear_time - e_click_time
            if e_cost_time > 30:
                logger.error('等待微信支付超10s')
                d.app_stop(app_name)
                e_click_time = time.time()
                break
        logger.info('跳转收银台页耗时{}'.format(e_cost_time))
        e = EexeclData(file=target_file, sheet_name='收银台页')
        e.write_cell(i + 1, 1, i)
        e.write_cell(i + 1, 2, e_cost_time)
        now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        e.write_cell(i + 1, 3, now_time)
        price = d(resourceId="com.yiwosi.kbb:id/text_price").get_text()
        e.write_cell(i + 1, 4, '价格{}'.format(price))
        logger.info('收银台页表格数据更新成功')
        time.sleep(1)
        d.press('back')
        d(text="取消订单").click()
        time.sleep(1)
        d(text="确认").click()
        time.sleep(1)
        d(text="确认").click()
        time.sleep(1)
        d.press('back')
        time.sleep(1)
        d.press('back')
        time.sleep(1)
        d.press('back')
        time.sleep(1)
        d.press('back')
        time.sleep(1)
        d.press('back')
        time.sleep(1)
        # if not d(resourceId="com.yiwosi.kbb:id/text_hotel_name").exists:
        #     text_hotel_name = d(resourceId="com.yiwosi.kbb:id/text_hotel_name").get_text()
        #     logger.error('提交订单页异常,当前酒店名称{}'.format(text_hotel_name))
        #     send_msg(fly_webhook, '提交订单页异常')
        #     os.popen('adb -s {} logcat - c > {}adb.log'.format(ip, now_time))
        #     now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        #     d.screenshot(screenshot_path + '{}.jpg'.format(now_time))
        #     time.sleep(1)

        # now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        # get_adb_all_process(now_time)
        # file_name = '{}adb_{}.log'.format(os.getcwd() + '/Logs/', now_time)
        # with open(file_name, 'r', encoding='utf8') as file:
        #     out_pri = file.read()
        #     try:
        #         hotel_detail_elapsed1 = re.findall('third_hotel_id":(.*)', out_pri.strip())
        #         hotel_detail_elapsed = re.findall('"elapsed":(.*)', str(hotel_detail_elapsed1[0]).strip())
        #         logger.info('hotel_detail_elapsed:{}'.format(hotel_detail_elapsed[0]))
        #         e.write_cell(i + 1, 6, hotel_detail_elapsed[0])
        #     except:
        #         pass
        #     try:
        #         order_prepare = re.findall('night_num":1},"elapsed":(.*)}', out_pri.strip())
        #         logger.info('order_prepare{}'.format(order_prepare[0]))
        #         e.write_cell(i + 1, 6, order_prepare[0])
        #     except:
        #         pass
        #     try:
        #         points_index1 = re.findall('"equal_to_rmb":(.*)"req_sn"', out_pri.strip())
        #         points_index = re.findall('"elapsed":(.*),', points_index1[0])
        #         logger.info('points_index{}'.format(points_index[0]))
        #         e.write_cell(i + 1, 7, points_index[0])
        #     except:
        #         pass
        #     try:
        #         titles1 = re.findall('titles(.*)}', out_pri.strip())
        #         titles = re.findall('elapsed":(.*)', titles1[0])
        #         logger.info('titles{}'.format(titles[0]))
        #         e.write_cell(i + 1, 8, titles[0])
        #     except:
        #         pass

        #     try:
        #         getUserLastOrderById1 = re.findall('"message":"getUserLastOrderById",(.*)}', out_pri.strip())
        #         getUserLastOrderById = re.findall('elapsed":(.*)', getUserLastOrderById1[0])
        #         logger.info('getUserLastOrderById{}'.format(getUserLastOrderById[0]))
        #         e.write_cell(i + 1, 9, getUserLastOrderById[0])
        #     except:
        #         pass

        #     try:
        #         availableCoupons1 = re.findall('"use_platform"(.*)', out_pri.strip())
        #         availableCoupons = re.findall('"elapsed":(.*),"req_sn":', availableCoupons1[-1])
        #         logger.info('availableCoupons{}'.format(availableCoupons[0]))
        #         e.write_cell(i + 1, 9, getUserLastOrderById[0])
        #     except:
        #         pass

    except BaseException as e:
        logger.error('提交订单页出错{}'.format(e))
        send_msg(fly_webhook, '提交订单页出错')
        now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        d.screenshot(f_screenshot_path + '{}.jpg'.format(now_time))
        get_adb_all_process(now_time)
        time.sleep(1)
        d.app_stop(app_name)
Beispiel #11
0
def fly_detail():
    """
    机票详情
    """
    d.watcher.when('resourceId="android:id/aerr_restart"').click()
    try:
        time.sleep(1)
        a = randint(0, 3)
        for m in range(a):
            d.swipe(500, 1000, 500, 300)
            time.sleep(1)
        time.sleep(1)
        # 通过坐标点击页面第一个数据
        d.click(0.438, 0.315)
        logger.info('点击了飞机列表页')
        b_click_time = time.time()
        while not d(text="退改规则 | 行李托运规则").exists:
            # 接口超时处理
            # 当超时时间大于10s时返回上一层,重新操作
            b_appear_time = time.time()
            b_cost_time = b_appear_time - b_click_time
            if b_cost_time > 10:
                logger.warning('等待机票详情页超时')
                d.app_stop(app_name)
                b_click_time = time.time()

                break
        b_appear_time = time.time()
        b_cost_time = b_appear_time - b_click_time
        logger.info('机票详情页{}'.format(b_cost_time))
        e = EexeclData(file=target_file, sheet_name='详情页')
        e.write_cell(i + 1, 1, i)
        e.write_cell(i + 1, 2, b_cost_time)
        now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        e.write_cell(i + 1, 3, now_time)
        # e.write_cell(i + 1, 4, hotel_name)
        logger.info('详情页表格数据更新成功')
        time.sleep(1)
        d.swipe(500, 1000, 500, 300)

        # now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        # get_adb_all_process(now_time)
        # file_name = '{}adb_{}.log'.format(os.getcwd() + '/Logs/', now_time)
        # with open(file_name, 'r', encoding='utf8') as file:
        #     out_pri = file.read()

        #     try:
        #         hotel_detail_elapsed1 = re.findall('third_hotel_id":(.*)', out_pri.strip())
        #         hotel_detail_elapsed = re.findall('"elapsed":(.*)}', str(hotel_detail_elapsed1[0]).strip())
        #         logger.info('hotel_detail_elapsed:{}'.format(hotel_detail_elapsed[0]))
        #         e.write_cell(i + 1, 6, hotel_detail_elapsed[0])
        #     except:
        #         pass

    except BaseException as e:
        logger.error('详情页出错{}'.format(e))
        send_msg(fly_webhook, '详情页出错')
        now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        d.screenshot(f_screenshot_path + '{}.jpg'.format(now_time))
        get_adb_all_process(now_time)
        time.sleep(1)
        d.app_stop(app_name)
Beispiel #12
0
def fly_list():
    d.watcher.when('resourceId="android:id/aerr_restart"').click()
    try:
        time.sleep(1)
        click_time = time.time()
        d(text="搜索").click()
        logger.info("点击了机票搜索")
        while not d(text="时间").exists:
            # 接口超时处理
            # 当超时时间大于10s时返回上一层,重新操作
            h_appear_time = time.time()
            h_cost_time = h_appear_time - click_time
            if h_cost_time > 15:
                logger.warning('等待机票列表超10s,返回上个页面重新操作')
                d.app_stop(app_name)
                click_time = time.time()
                break
        if d(text="重新搜索").exists:
            logger.warning("没有符合条件的航班,重新搜索")
            time.sleep(1)
            d.press('back')
            time.sleep(1)
            fly_city_select()
            fly_list()
        else:
            h_appear_time = time.time()
            h_cost_time = h_appear_time - click_time
            logger.info('机票列表页耗时{}'.format(h_cost_time))
            e = EexeclData(file=target_file, sheet_name='列表页')
            e.write_cell(i + 1, 1, i)
            e.write_cell(i + 1, 2, h_cost_time)
            now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
            e.write_cell(i + 1, 3, now_time)
            logger.info('列表页表格数据更新成功')

        # now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        # get_adb_all_process(now_time)
        # file_name = '{}adb_{}.log'.format(os.getcwd() + '/Logs/', now_time)
        # with open(file_name, 'r', encoding='utf8') as file:
        #     out_pri = file.read()
        #     try:
        #         checkUpgrade_elapsed = re.findall('checkUpgrade","data":{"upgrade":null},"elapsed":(.*),"req_sn":', out_pri.strip())
        #         logger.info('checkUpgrade:{}'.format(checkUpgrade_elapsed[0]))
        #         e.write_cell(i + 1, 7, checkUpgrade_elapsed[0])
        #     except:
        #         pass

        #     try:

        #         couponsBanner_elapsed1 = re.findall('"unreceived_coupons":(.*),"req_sn":', out_pri.strip())
        #         couponsBanner_elapsed = re.findall(r'\d+\.\d+', str(couponsBanner_elapsed1))
        #         logger.info('couponsBanner_elapsed:{}'.format(couponsBanner_elapsed[0]))
        #         e.write_cell(i + 1, 8, couponsBanner_elapsed[0])
        #     except:
        #         pass

        #     try:
        #         brand_elapsed = re.findall('单床房"}]}],"elapsed":(.*)}', out_pri.strip())
        #         logger.info('brand_elapsed:{}'.format(brand_elapsed[0]))
        #         e.write_cell(i + 1, 9, brand_elapsed[0])
        #     except:
        #         pass

        #     try:
        #         createUserIntegrate1 = re.findall('createUserIntegrate(.*)}', out_pri.strip())
        #         createUserIntegrate = re.findall('"elapsed":(.*)', str(createUserIntegrate1[0]))
        #         logger.info('createUserIntegrate:{}'.format(createUserIntegrate[0]))
        #         e.write_cell(i + 1, 6, createUserIntegrate[0])
        #     except:
        #         pass

        #     try:
        #         hotel_list1 = re.findall('精选双早/延迟退房"]}},"elapsed":(.*)}', out_pri.strip())
        #         logger.info('brand_elapsed:{}'.format(hotel_list1[0]))
        #         e.write_cell(i + 1, 10, hotel_list1[0])
        #     except:
        #         pass

    except BaseException as e:
        logger.error('机票列表页出错{}'.format(e))
        send_msg(fly_webhook, '列表页出错')
        now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        d.screenshot(f_screenshot_path + '{}.jpg'.format(now_time))
        get_adb_all_process(now_time)
        time.sleep(1)
        d.app_stop(app_name)
def hotel_roomtype():
    try:
        time.sleep(1)
        if d(text="展开").exists:
            d(text="展开").click()
            time.sleep(1)
            d.swipe(500, 1000, 500, 300)
            time.sleep(1)
            d_click_time = time.time()
            d(resourceId="com.yiwosi.kbb:id/text_breakfast").click()
        else:
            d_click_time = time.time()
            d(resourceId="com.yiwosi.kbb:id/text_breakfast").click()
        while not d(resourceId="com.yiwosi.kbb:id/tViewBook").exists:
            d_appear_time = time.time()
            d_cost_time = d_appear_time - d_click_time
            if d_cost_time > 10:
                logger.warning('等待预订按钮超10s,返回上个页面重新操作')
                d.press('back')
                time.sleep(1)
                d.press('back')
                time.sleep(1)
                d.press('back')
                time.sleep(1)
                hotel_city_select()
                hotel_list()
                hotel_detail()
                break
        d_appear_time = time.time()
        d_cost_time = d_appear_time - d_click_time
        time.sleep(1)
        text_room_type = d(resourceId="com.yiwosi.kbb:id/text_room_type").get_text()
        logger.info('点击的提交订单页{}'.format(text_room_type))
        logger.info('提交订单页耗时{}'.format(d_cost_time))
        e = EexeclData(file=target_file, sheet_name='提交订单页')
        e.write_cell(i + 1, 1, i)
        e.write_cell(i + 1, 2, d_cost_time)
        now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        e.write_cell(i + 1, 3, now_time)
        e.write_cell(i + 1, 4, text_room_type)
        logger.info('提交订单页表格数据更新成功')
        time.sleep(1)
        d(resourceId="com.yiwosi.kbb:id/tViewBook").click()
        time.sleep(1)
        if d(text="确认").exists:
            d(text="确认").click()
            logger.info("酒店房型太火爆了,返回重新选择")
            time.sleep(1)
            d.press("back")
            time.sleep(1)
            if d(text="狠心离开").exists:
                d(text="狠心离开").click()
                time.sleep(1)
            d.press("back")
            time.sleep(1)
            hotel_name = d(resourceId="com.yiwosi.kbb:id/text_name")[0].get_text()
            logger.info('点击的酒店是{}'.format(hotel_name))
            d(resourceId="com.yiwosi.kbb:id/text_name")[0].click()
            time.sleep(1)
            if d(text="展开").exists:
                d(text="展开").click()
                time.sleep(1)
                d.swipe(500, 1000, 500, 300)
                time.sleep(1)
                d(resourceId="com.yiwosi.kbb:id/text_breakfast").click()
            else:
                d(resourceId="com.yiwosi.kbb:id/text_breakfast").click()
            
            text_room_type = d(resourceId="com.yiwosi.kbb:id/text_room_type").get_text()
            logger.info('点击的提交订单页{}'.format(text_room_type))
            time.sleep(1)
            d(resourceId="com.yiwosi.kbb:id/tViewBook").click()
            time.sleep(1)
        # if not d(resourceId="com.yiwosi.kbb:id/text_hotel_name").exists:
        #     text_hotel_name = d(resourceId="com.yiwosi.kbb:id/text_hotel_name").get_text()
        #     logger.error('提交订单页异常,当前酒店名称{}'.format(text_hotel_name))
        #     send_msg(hotel_webhook, '提交订单页异常')
        #     os.popen('adb -s {} logcat - c > {}adb.log'.format(ip, now_time))
        #     now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        #     d.screenshot(h_screenshot_path + '{}.jpg'.format(now_time))
        #     time.sleep(1)

        now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        get_adb_all_process(now_time)
        file_name = '{}adb_{}.log'.format(os.getcwd() + '/Logs/', now_time)
        with open(file_name, 'r', encoding='utf8') as file:
            out_pri = file.read()
            try:
                hotel_detail_elapsed1 = re.findall('third_hotel_id":(.*)', out_pri.strip())
                hotel_detail_elapsed = re.findall('"elapsed":(.*)', str(hotel_detail_elapsed1[0]).strip())
                logger.info('hotel_detail_elapsed:{}'.format(hotel_detail_elapsed[0]))
                e.write_cell(i + 1, 6, hotel_detail_elapsed[0])
            except:
                pass
            try:
                order_prepare = re.findall('night_num":1},"elapsed":(.*)}', out_pri.strip())
                logger.info('order_prepare{}'.format(order_prepare[0]))
                e.write_cell(i + 1, 6, order_prepare[0])
            except:
                pass
            try:
                points_index1 = re.findall('"equal_to_rmb":(.*)"req_sn"', out_pri.strip())
                points_index = re.findall('"elapsed":(.*),', points_index1[0])
                logger.info('points_index{}'.format(points_index[0]))
                e.write_cell(i + 1, 7, points_index[0])
            except:
                pass
            try:
                titles1 = re.findall('titles(.*)}', out_pri.strip())
                titles = re.findall('elapsed":(.*)', titles1[0])
                logger.info('titles{}'.format(titles[0]))
                e.write_cell(i + 1, 8, titles[0])
            except:
                pass

            try:
                getUserLastOrderById1 = re.findall('"message":"getUserLastOrderById",(.*)}', out_pri.strip())
                getUserLastOrderById = re.findall('elapsed":(.*)', getUserLastOrderById1[0])
                logger.info('getUserLastOrderById{}'.format(getUserLastOrderById[0]))
                e.write_cell(i + 1, 9, getUserLastOrderById[0])
            except:
                pass

            try:
                availableCoupons1 = re.findall('"use_platform":"0"(.*)', out_pri.strip())
                availableCoupons = re.findall('"elapsed":(.*),"req_sn":', availableCoupons1[-1])
                logger.info('availableCoupons{}'.format(availableCoupons[0]))
                e.write_cell(i + 1, 10, availableCoupons[0])
            except:
                pass

    except BaseException as e:
        logger.error('提交订单页出错{}'.format(e))
        send_msg(hotel_webhook, '提交订单页出错')
        now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        d.screenshot(h_screenshot_path + '{}.jpg'.format(now_time))
        get_adb_all_process(now_time)
        time.sleep(1)
        d.app_stop(app_name)
def hotel_detail():
    """
    酒店详情
    """
    d.watcher.when('resourceId="android:id/aerr_restart"').click()
    try:   
        time.sleep(1)
        a = randint(0, 3)
        for m in range(a):
            d.swipe(500, 1000, 500, 300)
            time.sleep(1)
        time.sleep(1)
        count_hotel = d(resourceId="com.yiwosi.kbb:id/text_name").count
        if count_hotel > 2:
            c = randint(0, count_hotel - 2)
        else:
            c = 0
        # 	com.yiwosi.kbb:id/text_room_type_name
        hotel_name = d(resourceId="com.yiwosi.kbb:id/text_name")[c].get_text()
        logger.info('点击的酒店是{}'.format(hotel_name))
        b_click_time = time.time()
        d(resourceId="com.yiwosi.kbb:id/text_name")[c].click()
        while not d(resourceId="com.yiwosi.kbb:id/text_hotel_name").exists:
            # 接口超时处理
            # 当超时时间大于10s时返回上一层,重新操作
            b_appear_time = time.time()
            b_cost_time = b_appear_time - b_click_time
            if b_cost_time > 10:
                logger.warning('等待酒店房型超10s,返回上个页面重新操作')
                d.press('back')
                time.sleep(1)
                d.press('back')
                time.sleep(1)
                hotel_city_select()
                hotel_list()
                hotel_detail()
                break
        b_appear_time = time.time()
        b_cost_time = b_appear_time - b_click_time
        logger.info('酒店详情页耗时{}'.format(b_cost_time))
        e = EexeclData(file=target_file, sheet_name='详情页')
        e.write_cell(i + 1, 1, i)
        e.write_cell(i + 1, 2, b_cost_time)
        now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        e.write_cell(i + 1, 3, now_time)
        e.write_cell(i + 1, 4, hotel_name)
        logger.info('详情页表格数据更新成功')
        time.sleep(1)
        d.swipe(500, 1000, 500, 300)
        if d(text="未搜索到相关店铺,换个关键字试试").exists and d(text="差旅标准低于房型价格,无积分房型,请修改差旅标准").exists:
            logger.warning('没有搜索到酒店房型,开始返回上个页面重新操作')
            time.sleep(1)
            d.press('back')
            time.sleep(1)
            d.press('back')
            time.sleep(1)
            hotel_city_select()
            hotel_list()
            hotel_detail()
        
        now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        get_adb_all_process(now_time)
        file_name = '{}adb_{}.log'.format(os.getcwd() + '/Logs/', now_time)
        with open(file_name, 'r', encoding='utf8') as file:
            out_pri = file.read()
            try:
                hotel_detail_elapsed1 = re.findall('third_hotel_id":(.*)', out_pri.strip())
                hotel_detail_elapsed = re.findall('"elapsed":(.*)}', str(hotel_detail_elapsed1[0]).strip())
                logger.info('hotel_detail_elapsed:{}'.format(hotel_detail_elapsed[0]))
                e.write_cell(i + 1, 6, hotel_detail_elapsed[0])
            except:
                pass

    except BaseException as e:
        logger.error('详情页出错{}'.format(e))
        send_msg(hotel_webhook, '详情页出错')
        now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        d.screenshot(h_screenshot_path + '{}.jpg'.format(now_time))
        get_adb_all_process(now_time)
        time.sleep(1)
        d.app_stop(app_name)
def hotel_list():
    d.watcher.when('resourceId="android:id/aerr_restart"').click()
    try:
        # d.send_keys(room_rate, clear=True)
        time.sleep(1)
        d(text="搜索酒店").click()
        logger.info("点击了搜索酒店")
        click_time = time.time()
        while not d(resourceId="com.yiwosi.kbb:id/text_name").exists:
            # 接口超时处理
            # 当超时时间大于10s时返回上一层,重新操作
            h_appear_time = time.time()
            h_cost_time = h_appear_time - click_time
            if d(resourceId="com.yiwosi.kbb:id/text_no_room_type").exists:
                logger.warning('没有搜索到酒店,开始返回上个页面重新操作')
                time.sleep(1)
                d.press('back')
                hotel_city_select()
                hotel_list()
                break
            if h_cost_time > 10:
                logger.warning('等待酒店名称超10s,返回上个页面重新操作')
                d.press('back')
                time.sleep(1)
                hotel_city_select()
                hotel_list()
                # d(text="搜索酒店").click()
                # logger.info("点击了搜索酒店")
                click_time = time.time()
                break
        
        # if d(resourceId="com.yiwosi.kbb:id/text_no_room_type").exists:
        #     logger.warning('没有搜索到酒店,开始返回上个页面重新操作')
        #     time.sleep(1)
        #     d.press('back')
        #     hotel_city_select()
        #     hotel_list()
        # else:
        h_appear_time = time.time()
        h_cost_time = h_appear_time - click_time
        logger.info('列表页耗时{}'.format(h_cost_time))
        e = EexeclData(file=target_file, sheet_name='列表页')
        e.write_cell(i + 1, 1, i)
        e.write_cell(i + 1, 2, h_cost_time)
        now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        e.write_cell(i + 1, 3, now_time)
        logger.info('列表页表格数据更新成功')
        
        now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        get_adb_all_process(now_time)
        file_name = '{}adb_{}.log'.format(os.getcwd() + '/Logs/', now_time)
        with open(file_name, 'r', encoding='utf8') as file:
            out_pri = file.read()
            try:
                checkUpgrade_elapsed = re.findall('checkUpgrade","data":{"upgrade":null},"elapsed":(.*),"req_sn":', out_pri.strip())
                logger.info('checkUpgrade:{}'.format(checkUpgrade_elapsed[0]))
                e.write_cell(i + 1, 7, checkUpgrade_elapsed[0])
            except:
                pass

            try:

                couponsBanner_elapsed1 = re.findall('"unreceived_coupons":(.*),"req_sn":', out_pri.strip())
                couponsBanner_elapsed = re.findall(r'\d+\.\d+', str(couponsBanner_elapsed1))
                logger.info('couponsBanner_elapsed:{}'.format(couponsBanner_elapsed[0]))  
                e.write_cell(i + 1, 8, couponsBanner_elapsed[0])
            except:
                pass

            try:
                brand_elapsed = re.findall('单床房"}]}],"elapsed":(.*)}', out_pri.strip())
                logger.info('brand_elapsed:{}'.format(brand_elapsed[0]))
                e.write_cell(i + 1, 9, brand_elapsed[0])
            except:
                pass

            try:
                createUserIntegrate1 = re.findall('createUserIntegrate(.*)}', out_pri.strip())
                createUserIntegrate = re.findall('"elapsed":(.*)', str(createUserIntegrate1[0]))
                logger.info('createUserIntegrate:{}'.format(createUserIntegrate[0]))
                e.write_cell(i + 1, 6, createUserIntegrate[0])
            except:
                pass

            try:
                hotel_list1 = re.findall('精选双早/延迟退房"]}},"elapsed":(.*)}', out_pri.strip())
                logger.info('brand_elapsed:{}'.format(hotel_list1[0]))
                e.write_cell(i + 1, 10, hotel_list1[0])
            except:
                pass


    except BaseException as e:
        logger.error('列表页出错{}'.format(e))
        send_msg(hotel_webhook, '列表页出错')
        now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        d.screenshot(h_screenshot_path + '{}.jpg'.format(now_time))
        get_adb_all_process(now_time)
        time.sleep(1)
        d.app_stop(app_name)