Пример #1
0
def ios_hotel_city_select():
    try:
        # 点击城市搜索
        c.click(0.5, 0.35)
        time.sleep(1)
        address = random_address('ios_list_address')
        print('{}点击的酒店是{}'.format(get_n_time(), address))
        c(text=str(address)).click()
        time.sleep(1)
        # 点击差旅标准
        c.click(0.5, 0.5)
        room_rate = random_address('list_room_rate')
        c.send_keys(room_rate)
        time.sleep(1)
        return True
    except BaseException as e:
        # send_msg(hotel_webhook, '酒店预订城市选择出错')
        print('{}酒店预订城市选择出错'.format(get_n_time(), e))
        now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        pic_file = h_ios_screenshot_path + '{}.jpg'.format(now_time)
        c.screenshot().convert('RGB').save("{}".format(pic_file))
        print('{}报错截图:'.format(get_n_time()))
        print('{}.jpg'.format(
            re_pic_path.replace('/home/GoldenTest/goldentestmanage', '') +
            now_time))
        print('\n')
        _upload(filename='{}.jpg'.format(now_time),
                localpath=h_ios_screenshot_path,
                remotepath=re_pic_path,
                server=server,
                username=username,
                password=password)

        return '{}酒店预订城市选择出错'.format(get_n_time(), e)
Пример #2
0
def ios_click_bookdate(start_date, end_date):
    try:
        print('{}已点击酒店类目'.format(get_n_time()))
        print('{}开始选择入住日期'.format(get_n_time()))
        c(text='共1晚').tap()
        time.sleep(1)
        if c(text='入住').exists:
            # 滑动到下个月 避免点击到不可预订月份
            c.swipe(0.5, 0.6, 0.5, 0.5)
        c(text=str(start_date)).tap()
        time.sleep(1)
        c(text=str(end_date)).tap()
        time.sleep(1)
        messge = '已预订下月的{}号-{}号的酒店'.format(start_date, end_date)
        print(get_n_time() + messge)
        return messge
    except BaseException as e:
        # send_msg(hotel_webhook, '预订日期选择出错')
        print('{}预订日期选择出错{}-'.format(get_n_time(), e))
        now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        pic_file = h_ios_screenshot_path + '{}.jpg'.format(now_time)
        c.screenshot().convert('RGB').save("{}".format(pic_file))
        print('{}报错截图:'.format(get_n_time()))
        print('{}.jpg'.format(
            re_pic_path.replace('/home/GoldenTest/goldentestmanage', '') +
            now_time))
        print('\n')
        _upload(filename='{}.jpg'.format(now_time),
                localpath=h_ios_screenshot_path,
                remotepath=re_pic_path,
                server=server,
                username=username,
                password=password)
        return '{}预订日期选择出错{}-'.format(get_n_time(), e)
Пример #3
0
def ios_hotel_cashier():
    global h_cashier_cost_time
    try:
        time.sleep(1)
        print('{}点击了提交订单按钮'.format(get_n_time()))
        print("{}开始等待'微信支付'文案出现,计算耗时".format(get_n_time()))
        c(text='提交订单').click()
        h_cashier_click_time = time.time()
        while not '微信支付' in c.source():
            h_cashier_appear_time = time.time()
            h_cashier_cost_time = h_cashier_appear_time - h_cashier_click_time
            if h_cashier_cost_time > 10:
                logger.warning('酒店收银台页耗时大于10s')
                break
        h_cashier_appear_time = time.time()
        h_cashier_cost_time = h_cashier_appear_time - h_cashier_click_time
        print("{}已找到'微信支付'文案,开始计算耗时".format(get_n_time()))
        cashier_message = '{}酒店收银台页耗时{}'.format(get_n_time(),
                                                h_cashier_cost_time)
        print(cashier_message)
        time.sleep(1)

        c.click(18, 55)  # 点击返回按钮
        time.sleep(1)
        c(text='放弃').click()
        time.sleep(1)
        c(text='取消订单').click()
        time.sleep(1)
        c(text='确认取消').click()
        print('{}点击了取消订单'.format(get_n_time()))
        time.sleep(1)
        c.click(291, 440)  # 确认时间太长按钮
        time.sleep(1)
        c(text='提交').click()
        time.sleep(1)
        return cashier_message
    except BaseException as e:
        print('{}酒店收银台出错{}'.format(get_n_time(), e))
        now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        pic_file = h_ios_screenshot_path + '{}.jpg'.format(now_time)
        c.screenshot().convert('RGB').save("{}".format(pic_file))
        print('{}报错截图:'.format(get_n_time()))
        print('{}.jpg'.format(
            re_pic_path.replace('/home/GoldenTest/goldentestmanage', '') +
            now_time))
        print('\n')
        _upload(filename='{}.jpg'.format(now_time),
                localpath=h_ios_screenshot_path,
                remotepath=re_pic_path,
                server=server,
                username=username,
                password=password)
        return '{}酒店收银台出错{}'.format(get_n_time(), e)
Пример #4
0
def ios_hotel_order():
    global h_order_cost_time
    try:
        time.sleep(1)
        c.swipe(0.5, 0.8, 0.5, 0.5)
        time.sleep(1)
        if '没有找到符合条件的房型' in c.source():
            # 模拟从屏幕最左侧滑动到右侧来返回
            c.swipe(0.01, 0.5, 0.8, 0.5)
            print("{}没有找到符合条件的房型,重新选择".format(get_n_time()))
        print('{}点击了预订按钮'.format(get_n_time()))
        print("{}开始等待'会员多返'文案出现,计算耗时".format(get_n_time()))
        if '订' in c.source():
            c(text='订').click()
            h_order_click_time = time.time()
        else:
            s(nameContains='窗').click()
            # c(text='窗').click()
            time.sleep(1)
            c(text='订').click()
            h_order_click_time = time.time()
        while not '会员多返' in c.source():
            h_order_appear_time = time.time()
            h_order_cost_time = h_order_appear_time - h_order_click_time
            if h_order_cost_time > 10:
                logger.warning('酒店提交订单页耗时大于10s')
                break
        h_order_appear_time = time.time()
        h_order_cost_time = h_order_appear_time - h_order_click_time
        print("{}已找到'会员多返'文案,开始计算耗时".format(get_n_time()))
        order_message = '{}酒店提交订单页耗时{}'.format(get_n_time(), h_order_cost_time)
        print(order_message)
        return order_message
    except BaseException as e:
        print('{}酒店提交订单页出错'.format(get_n_time(), e))
        now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        pic_file = h_ios_screenshot_path + '{}.jpg'.format(now_time)
        c.screenshot().convert('RGB').save("{}".format(pic_file))
        print('{}报错截图:'.format(get_n_time()))
        print('{}.jpg'.format(
            re_pic_path.replace('/home/GoldenTest/goldentestmanage', '') +
            now_time))
        print('\n')
        _upload(filename='{}.jpg'.format(now_time),
                localpath=h_ios_screenshot_path,
                remotepath=re_pic_path,
                server=server,
                username=username,
                password=password)

        return '{}酒店提交订单页出错'.format(get_n_time(), e)
Пример #5
0
def ios_hotel_detail():
    global h_detail_cost_time
    try:
        print('{}随机下滑酒店列表页数据,进入房型页'.format(get_n_time()))

        a = randint(0, 4)
        for m in range(a):
            c.swipe(0.5, 0.8, 0.5, 0.5)
            time.sleep(1)
        time.sleep(1)
        print("{}开始等待'窗'文案出现,计算耗时".format(get_n_time()))
        c.click(500, 500)
        h_detail_click_time = time.time()
        while not "窗" in c.source():
            h_detail_appear_time = time.time()
            h_detail_cost_time = h_detail_appear_time - h_detail_click_time
            if h_detail_cost_time > 10:
                logger.warning('酒店房型页耗时大于10s')
                break
        h_detail_appear_time = time.time()
        h_detail_cost_time = h_detail_appear_time - h_detail_click_time
        print("{}已找到'窗'文案,开始计算耗时".format(get_n_time()))
        detail_message = '{}酒店房型页耗时{}'.format(get_n_time(), h_detail_cost_time)
        print(detail_message)
        return detail_message
    except BaseException as e:
        print('酒店房型页出错'.format(e))
        now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        pic_file = h_ios_screenshot_path + '{}.jpg'.format(now_time)
        c.screenshot().convert('RGB').save("{}".format(pic_file))
        print('{}报错截图:'.format(get_n_time()))
        print('{}.jpg'.format(
            re_pic_path.replace('/home/GoldenTest/goldentestmanage', '') +
            now_time))
        print('\n')
        _upload(filename='{}.jpg'.format(now_time),
                localpath=h_ios_screenshot_path,
                remotepath=re_pic_path,
                server=server,
                username=username,
                password=password)

        return '酒店房型页出错'.format(e)
Пример #6
0
def ios_hotel_list():
    global h_cost_time
    try:
        print("{}点击了搜索酒店".format(get_n_time()))
        print("{}开始等待'默认排序'文案出现,计算耗时".format(get_n_time()))
        c(text='搜索酒店').tap()
        click_time = time.time()
        while not '默认排序' in c.source():
            h_appear_time = time.time()
            h_cost_time = h_appear_time - click_time
            if c(text='没有找到符合条件的房型').exists:
                print("{}没有搜索到酒店,开始返回上个页面重新操作".format(get_n_time()))
                time.sleep(1)
                c.swipe(0.01, 0.5, 0.8, 0.5)
                ios_hotel_city_select()
                break
        h_appear_time = time.time()
        h_cost_time = h_appear_time - click_time
        print("{}已找到'默认排序'文案,开始计算耗时".format(get_n_time()))
        list_message = '{}列表页耗时{}'.format(get_n_time(), h_cost_time)
        print(list_message)
        return list_message
    except BaseException as e:
        print('{}酒店列表页出错'.format(get_n_time(), e))
        now_time = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
        pic_file = h_ios_screenshot_path + '{}.jpg'.format(now_time)
        c.screenshot().convert('RGB').save("{}".format(pic_file))
        print('{}报错截图:'.format(get_n_time()))
        print('{}.jpg'.format(
            re_pic_path.replace('/home/GoldenTest/goldentestmanage', '') +
            now_time))
        print('\n')
        _upload(filename='{}.jpg'.format(now_time),
                localpath=h_ios_screenshot_path,
                remotepath=re_pic_path,
                server=server,
                username=username,
                password=password)

        return '{}酒店列表页出错'.format(get_n_time(), e)
Пример #7
0
 # filename为文件名称,report_dir报告输出位置,title测试标题,tester测试测试人员,desc描述类目此处需写死为 酒店,机票, 打车, 火车票, 订餐, 加油中的一个
 runner = TestRunner(suite,
                     filename=filename,
                     report_dir=fp,
                     title="生产IOS酒店UI测试报告",
                     tester="罗松",
                     desc="酒店")
 i = 0
 while i < ios_hotel_test_times:
     i += 1
     runner.run()
 req = runner.get_reports()  # 取出测试报告数据
 success = req['success']  # 执行成功数
 all = req['all']  # 总案例数
 fail = req['fail']  # 执行失败数(断言失败场景)
 error = req['error']  # 执行异常数(非失败场景,如脚本异常导致的失败)
 pass_rate = req['pass_rate']  # 成功率
 desc = req['desc']
 begin_time = req['begin_time']  # 执行开始时间
 file_path = remotepath + filename
 _upload(filename=filename,
         localpath=fp + '\\',
         remotepath=remotepath,
         server=server,
         username=username,
         password=password)
 auto_test_result_sql = 'insert into auto_test_result (`all`, success, fail, error, pass_rate, `desc`, begin_time, file_path, source, env, created_at'
 auto_test_result_sql += ') values ("{}","{}","{}","{}", "{}","{}","{}","{}", "ios", "0",now());'.format(
     all, success, fail, error, pass_rate, desc, begin_time,
     (file_path.replace('/home/GoldenTest/goldentestmanage', '')))
 sql_insert(auto_test_result_sql)