def __init__(self): self.config = Config() self.log = Log.MyLog() self.run_path = Config.path_dir self.USER_ID = str(get_value("xc手机号")) self.picture_verification_code = str(get_value("四位图片验证码")) self.login_verification_code = str(get_value("登录验证码"))
def test_contrast_profit_deposit_14(self, d): """ 理财产品比收益 :param d: :return: """ # prd_key = d(resourceId=get_value("比收益理财产品名称")) prd_value = d(resourceId=get_value("比收益理财产品收益")) prd_many = d(resourceId=get_value("比收益理财产品收益差额")) prd_value_list = [] prd_many_list = [] for i in range(prd_value.__len__()): prd_value_list.append(Decimal(prd_value[i].get_text()).quantize(Decimal('0.00'))) print(prd_value_list) for i in range(prd_many.__len__()): prd_many_value = (prd_many[i].get_text()).translate(str.maketrans('+', ' ')).strip() prd_many_list.append(Decimal(prd_many_value).quantize(Decimal('0.00'))) print(prd_many_list) for i in range(prd_value.__len__()-1): prd_db = prd_value_list[i] - prd_many_list[i] print(prd_value_list[i]) print("--------------------------") print(prd_many_list[i]) test.assert_equal_save_picture(d, prd_db, prd_value_list[-1], "收益计算对比") Consts.RESULT_LIST.append('True')
def test_click_buy_product_04(self, d): """ 未登录购买产品弹登录页 :param d: :return: """ if d(resourceId=get_value("登录页关闭")).exists: with pytest.allure.step("数据回收关闭登录页"): action.click_element(d, "登录页关闭") with pytest.allure.step("点击首页推荐银行名称"): time.sleep(2) action.click_element(d, "首页银行名称") with pytest.allure.step("点击购买"): action.click_element(d, "安全购买") with pytest.allure.step("验证是否弹出登录页"): test.assert_title(d, "安全提醒") time.sleep(5) test.assert_element_exists_save_picture( d, d(resourceId=get_value("立即登录按钮")).exists, "弹出登录页") Consts.RESULT_LIST.append('True')
def test_click_all_bank_02(self, d): """ 点击全部银行 :param d: """ with pytest.allure.step("点击全部银行按钮"): action.click_element(d, "全部银行") d(scrollable=True).scroll(steps=10) # 向下滑动 time.sleep(2) d(scrollable=True).scroll(steps=20) # 向下滑动 time.sleep(2) bank_name_list = d(resourceId=get_value("产品名称")) print(bank_name_list) i_bank = random.randint(0 + 1, bank_name_list.__len__() - 1) global i_bank_name i_bank_name = bank_name_list[i_bank].get_text() print(i_bank_name) with pytest.allure.step("点击" + i_bank_name + "跳转"): try: d(resourceId=get_value("产品名称"))[i_bank].click(timeout=10) except: action.display_picture(d, "控件未获取到") logging.error("点击银行名称失败 ") raise global s_bank_name s_bank_name = d(resourceId=get_value("收藏页银行名称")).get_text() test.assert_title(d, "银行") test.assert_equal_save_picture(d, i_bank_name, s_bank_name, "银行名称对比") Consts.RESULT_LIST.append('True')
def test_click_recommend_financing_date_17(self, d): """ 点击银行存款推荐时间选项 :param d: :return: """ with pytest.allure.step("点击直销银行理财选项"): action.click_element(d, "直销银行理财选项") recommend_content = d(resourceId=get_value("推荐内容")) recommend_content_real_financing = ['推荐', '1天', '3-6个月', '6个月以上'] time.sleep(2) for i in range(recommend_content.__len__()): d(resourceId=get_value("推荐内容"))[i].click() time.sleep(1) # if d(resourceId="com.bs.finance:id/tv_tab_title")[i].get_text() == str(recommend_content_real_financing[i]): # with pytest.allure.step("选择" + d(resourceId="com.bs.finance:id/tv_tab_title")[i].get_text() + "选项"): # print("选择" + d(resourceId="com.bs.finance:id/tv_tab_title")[i].get_text() + "选项") # if d(resourceId="com.bs.finance:id/tv_tab_title")[i].get_text() == "推荐": # test.assert_element_exists_save_picture(d, action.element_exists(d, "推荐排名"), "推荐排名显示") # test.assert_element_exists_save_picture(d, action.element_exists(d, "首页银行名称"), "推荐数据查询") # elif d(resourceId="com.bs.finance:id/tv_tab_title")[i].get_text() == "1天": # test.assert_element_exists_save_picture(d, action.element_exists(d, "推荐周期显示"), # "推荐周期1天显示") # test.assert_element_exists_save_picture(d, action.element_exists(d, "首页银行名称"), "推荐数据查询") # elif d(resourceId="com.bs.finance:id/tv_tab_title")[i].get_text() == "3-6个月": # test.assert_element_exists_save_picture(d, action.element_exists(d, "推荐周期显示"), # "推荐周期3-6个月显示") # test.assert_element_exists_save_picture(d, action.element_exists(d, "首页银行名称"), "推荐数据查询") # elif d(resourceId="com.bs.finance:id/tv_tab_title")[i].get_text() == "6个月以上": # test.assert_element_exists_save_picture(d, action.element_exists(d, "推荐周期显示"), # "推荐周期6个月以上显示") # test.assert_element_exists_save_picture(d, action.element_exists(d, "首页银行名称"), "推荐数据查询") d(resourceId=get_value("推荐内容"))[0].click() Consts.RESULT_LIST.append('True')
def test_cancel_bank_collection_06(self, d): with pytest.allure.step("点击取消收藏"): sc_text = d(resourceId=get_value("收藏按钮")).get_text() action.click_element(d, "收藏按钮") click_sc_text = d(resourceId=get_value("收藏按钮")).get_text() test.assert_equal_save_picture(d, sc_text, "已收藏", "未点击收藏按钮显示") test.assert_equal_save_picture(d, click_sc_text, "+收藏", "未点击收藏按钮显示") Consts.RESULT_LIST.append('True')
def setup_class(self): """登录后台""" s = p.get_value('登录') r.input_data('xpath', s['账号输入框'], '17611520838') r.input_data('xpath', s['密码输入框'], 'a123456') r.click('xpath', s['登录按钮点击']) s = p.get_value('商品品牌') #'阿萨德 '+' '+o+' '+y r.click('xpath', s['点击商品管理目录']) r.click('xpath', s['点击商品管理按钮'])
def test_contrast_profit_deposit_04(self, d): """ 银行存款比收益 :param d: :return: """ prd_key = d(resourceId=get_value("比收益产品名称")) prd_value = d(resourceId=get_value("比收益产品收益")) prd_many = d(resourceId=get_value("比收益产品收益差额")) test.assert_profit(d, prd_key, prd_value, prd_many) Consts.RESULT_LIST.append('True')
def input_element(self, d, element_name, input_text): """ :param d: 控件默认为d :param element_name: 控件名称详见yaml文件 :param input_text: 需要输入的内容 :return: 无 """ d(resourceId=get_value(element_name)).wait(timeout=10.0) d(resourceId=get_value(element_name)).set_text(input_text) time.sleep(1)
def click_element(self, d, element_name): """ :param d: 控件默认为d :param element_name: 控件名称详见yaml文件 :return: 无 封装控件点击操作 """ d(resourceId=get_value(element_name)).wait(timeout=10.0) if not d(resourceId=get_value(element_name)).exists: self.display_picture(d, "控件未获取到") d(resourceId=get_value(element_name)).click() time.sleep(1)
def test_click_all_bank_03(self, d): with pytest.allure.step("点击" + i_bank_name + "跳转"): sc_text = d(resourceId=get_value("收藏按钮")).get_text() action.click_element(d, "收藏按钮") click_sc_text = d(resourceId=get_value("收藏按钮")).get_text() test.assert_equal_save_picture(d, sc_text, "+收藏", "未点击收藏按钮显示") test.assert_equal_save_picture(d, click_sc_text, "已收藏", "未点击收藏按钮显示") with pytest.allure.step("点击返回icon返回银行页"): action.click_element(d, "返回icon") Consts.RESULT_LIST.append('True')
def click_element_with_text(self, d, element_name, element_text): """ :param d:控件默认为d :param element_name:控件名称详见yaml文件 :param element_text:控件文本 :return: """ d(resourceId=get_value(element_name), text=str(element_text)).wait(timeout=10.0) d(resourceId=get_value(element_name), text=str(element_text)).click() time.sleep(1)
def test_check_prd_refashion_22(self, d): """ 勾选产品后点击重制验证产品不在比收益展示产品列表中 :param d: :return: """ with pytest.allure.step("恢复数据"): action.click_element(d, "比收益") d(resourceId="com.bs.finance:id/tv_tab_title", text=u"直销银行理财").click(timeout=10) action.click_element(d, "比收益添加按钮") action.click_element(d, "比收益添加产品页收益率选项") with pytest.allure.step("勾选全部复选框"): time.sleep(5) prd_name = d(resourceId=get_value("比收益产品名称")) prd_check = d(resourceId=get_value("比收益收益率复选框")) global prd_name_list prd_name_list = [] for i in range(prd_name.__len__()): prd_name_list.append(prd_name[i].get_text().strip()) with pytest.allure.step("勾选"+prd_name[i].get_text()+"产品"): prd_check[i].click() with pytest.allure.step("点击比收益添加产品页重制按钮"): action.click_element(d, "比收益添加产品页重制按钮") with pytest.allure.step("点击比收益添加产品页完成按钮"): action.click_element(d, "比收益添加产品页完成按钮") time.sleep(1) with pytest.allure.step("获取添加后的产品名称列表"): prd_name_a = [] prd_name_b = [] prd_name_return = d(resourceId=get_value("比收益理财产品名称")) for i in range(prd_name_return.__len__()): prd_name_a.append(prd_name_return[i].get_text()) with pytest.allure.step("向上划动产品列表"): d.swipe_points([(0.578, 0.94), (0.415, 0.507)], 0.2) # 向上划动产品列表 with pytest.allure.step("获取滑动后产品列表"): for i in range(prd_name_return.__len__()): prd_name_b.append(prd_name_return[i].get_text()) prd_name_return_list = list(set(prd_name_a + prd_name_b)) with pytest.allure.step("验证添加产品在比收益产品列表中"): for i in range(prd_name_list.__len__()): assert prd_name_list[i] not in prd_name_return_list Consts.RESULT_LIST.append('True') with pytest.allure.step("恢复数据"): action.click_element(d, "返回icon") time.sleep(2) action.login_out(d) # 登出
def test_check_prd_21(self, d): """ 验证销量排行 :param d: :return: """ with pytest.allure.step("点击添加按钮"): action.click_element(d, "返回icon") action.click_element(d, "比收益") d(resourceId="com.bs.finance:id/tv_tab_title", text=u"直销银行理财").click(timeout=10) action.click_element(d, "比收益添加按钮") with pytest.allure.step("跳转后标题对比"): test.assert_title(d, "添加产品") with pytest.allure.step("点击销量"): action.click_element(d, "比收益销量选项") prd_sv = d(resourceId=get_value("比收益销量显示")) prd_sv_list = [] for i in range(prd_sv.__len__()): prd_sv_list.append(int((prd_sv[i].get_text()).translate(str.maketrans('已售:', ' ')).strip())) with pytest.allure.step("销量对比"): for i in range(prd_sv_list.__len__()): for j in range(prd_sv_list.__len__()-1-i): assert prd_sv_list[j] > prd_sv_list[j+1] Consts.RESULT_LIST.append('True') action.click_element(d, "返回icon") action.click_element(d, "返回icon") time.sleep(1)
def test_choose_bank_deposit_14(self, d): """ 银行存款和直销银行理财切换 :param d: :return: """ global choose_type time.sleep(2) with pytest.allure.step("获取默认选项"): if action.element_exists(d, "银行存款选中下划线"): choose_type = 0 elif action.element_exists(d, "直销银行理财选中下划线"): choose_type = 1 else: choose_type = -1 recommend_content = d(resourceId=get_value("推荐内容")) recommend_content_real_bank = ['推荐', '1天', '1个月内', '1-3个月', '3-6个月', '6个月以上'] recommend_content_real_financing = ['推荐', '1天', '3-6个月', '6个月以上'] recommend_content_test = [] if choose_type == 0: for i in range(recommend_content.__len__()): recommend_content_test.append(recommend_content[i].get_text()) test.assert_equal_save_picture(d, recommend_content_test, recommend_content_real_bank, "获取推荐列表") elif choose_type == 1: for i in range(recommend_content.__len__()): recommend_content_test.append(recommend_content[i].get_text()) # test.assert_equal_save_picture(d, recommend_content_test, recommend_content_real_financing, "获取推荐列表") print(choose_type) Consts.RESULT_LIST.append('True')
def test_sidebar_eject_03(self, d): """ 验证点击左上角图标弹出侧边栏功能 """ global cebian_button # 侧边栏按钮 global realname_status # 实名认证状态 cebian_button = ["我的关注", "我的消息", "我的钱包", "关于我们"] with pytest.allure.step("点击左上角图标"): action.click_element(d, "首页左上角图标") time.sleep(10) with pytest.allure.step("检验侧边栏控件"): for i in range(cebian_button.__len__()): test.assert_element_exists_save_picture( d, d(text=cebian_button[i]).exists, "验证侧边栏" + cebian_button[i] + "按钮控件存在") with pytest.allure.step("验证账号为已登录状态,账号为" + USER_ID): user_id = d(resourceId=get_value("侧边栏账号")).get_text() test.assert_equal_save_picture( d, user_id, USER_ID.replace((USER_ID[3:7]), "****"), "账号" + USER_ID + "已登录状态") Consts.RESULT_LIST.append('True')
def test_choose_financing_15(self, d): """ 直销银行理财和银行存款切换 :param d: :return: """ with pytest.allure.step("点击直销银行理财选项"): recommend_content = d(resourceId=get_value("推荐内容")) recommend_content_real_bank = ['推荐', '1天', '1个月内', '1-3个月', '3-6个月', '6个月以上'] recommend_content_real_financing = ['推荐', '1天', '3-6个月', '6个月以上'] recommend_content_test = [] if choose_type == 0: action.click_element(d, "直销银行理财选项") test.assert_element_exists_save_picture(d, action.element_exists(d, "直销银行理财选中下划线"), "直销银行理财选中下划线显示") time.sleep(1) for i in range(recommend_content.__len__()): recommend_content_test.append(recommend_content[i].get_text()) test.assert_element_exists_save_picture(d, action.element_exists(d, "首页银行名称"), "可查询出产品") # test.assert_equal_save_picture(d, recommend_content_test, recommend_content_real_financing, "获取推荐列表") elif choose_type == 1: action.click_element(d, "银行存款选项") test.assert_element_exists_save_picture(d, action.element_exists(d, "银行存款选中下划线"), "银行存款选中下划线显示") time.sleep(1) for i in range(recommend_content.__len__()): recommend_content_test.append(recommend_content[i].get_text()) test.assert_equal_save_picture(d, recommend_content_test, recommend_content_real_bank, "获取推荐列表") print(choose_type) Consts.RESULT_LIST.append('True')
def test_go_main_01(self, d): """ 首次启动app点击进入比财,如果有广告页点击x关闭, :param d: :return: """ time.sleep(5) with pytest.allure.step("启动页点击进入比财"): action.click_element(d, "启动页进入比财") with pytest.allure.step("如果弹出广告页点x关闭"): if d(resourceId=get_value("广告页")).exists: # 如果弹出广告页 action.click_element(d, "广告页关闭") # 点击x关闭 with pytest.allure.step("验证启动app点击进入比财是否进入首页"): test.assert_element_exists_save_picture(d, d(text="一键登录").exists, "验证是否有文本为一键登录的控件") Consts.RESULT_LIST.append('True')
def test_click_search_01(self, d): """ 点击首页搜索框 :param d: """ action.login_in(d) # 登录 time.sleep(10) with pytest.allure.step("点击首页搜索"): action.click_element(d, "首页搜索") with pytest.allure.step("验证是否跳转成功"): test.assert_element_exists_save_picture(d, d(resourceId=get_value("搜索按钮")).exists, "跳转搜索页搜索按钮显示") type_choose_text = d(resourceId=get_value("选择搜索类型")).get_text() if type_choose_text == "机构": test.assert_equal_save_picture(d, d(resourceId=get_value("搜索文本框")).get_text(), "搜索相关金融机构", "搜索框文本显示") elif type_choose_text == "产品": test.assert_equal_save_picture(d, d(resourceId=get_value("搜索文本框")).get_text(), "搜索相关金融产品", "搜索框文本显示") Consts.RESULT_LIST.append('True')
def assert_title(self, d, title): """ :param d: 控件默认为d :param title: 页面标题 :return: 无 验证页面是否跳转成功 """ if not d(resourceId=get_value("标题")).exists: time.sleep(2) else: self.assert_equal_save_picture( d, title, d(resourceId=get_value("标题")).get_text(), "标题对比") print("页面title为:" + str(d(resourceId=get_value("标题")).get_text())) print("预期页面的title为:" + str(title)) time.sleep(1)
def test_modify_money_05(self, d): """ 修改投资金额 :param d: :return: """ with pytest.allure.step("修改投资金额"): action.click_element(d, "比收益金额选项") # d.swipe_points([(0.501, 0.515), (0.494, 0.581)], 0.2) # 切换2万金额 d.swipe_points([(0.775, 0.543), (0.5, 0.543)], 0.2) # 切换2万金额 time.sleep(5) d.click(0.514, 0.17) with pytest.allure.step("修改金额后对比"): prd_key = d(resourceId=get_value("比收益产品名称")) prd_value = d(resourceId=get_value("比收益产品收益")) prd_many = d(resourceId=get_value("比收益产品收益差额")) test.assert_profit(d, prd_key, prd_value, prd_many) Consts.RESULT_LIST.append('True')
def test_switch_click_search_button_04(self, d): """ 点击搜索页搜索按钮 :param d: """ type_choose_text = d(resourceId=get_value("选择搜索类型")).get_text() with pytest.allure.step("点击首页搜索"): action.click_element(d, "搜索按钮") if type_choose_text == "机构": test.assert_equal_save_picture(d, d(resourceId=get_value("类型展示")).get_text(), "金融机构", "跳转成功") test.assert_element_exists_save_picture(d, d(resourceId=get_value("搜索页展示名称")).exists, "搜索出金融机构") elif type_choose_text == "产品": test.assert_equal_save_picture(d, d(resourceId=get_value("类型展示")).get_text(), "金融产品", "跳转成功") test.assert_element_exists_save_picture(d, d(resourceId=get_value("搜索页展示名称")).exists, "搜索出金融产品") Consts.RESULT_LIST.append('True')
def element_gettext(self, d, element_name): """ 获取控件文本内容 :param d: :param element_name: :return: """ element_text = get_value(element_name) return d(resourceId=element_text).get_text()
def assert_title(self, d, title): """ :param d: 控件默认为d :param title: 页面标题 :return: 无 验证页面是否跳转成功 """ if not d(resourceId=get_value("标题")).exists: time.sleep(2) try: self.assert_equal_save_picture(d, title, d(resourceId=get_value("标题")).get_text(), "标题对比") print("页面title为:" + str(d(resourceId=get_value("标题")).get_text())) print("预期页面的title为:" + str(title)) time.sleep(1) except: self.operation.display_picture(d, "控件未获取到") self.log.error("对比" + title + "控件") raise
def test_click_cp_financing_13(self, d): """ 点击直销银行理财 :param d: :return: """ time.sleep(5) with pytest.allure.step("点击比收益"): action.click_element(d, "比收益") with pytest.allure.step("获取存款产品名称"): deposit_prd = d(resourceId=get_value("比收益产品名称"))[0].get_text() print(deposit_prd) with pytest.allure.step("点击直销银行理财"): d(resourceId="com.bs.finance:id/tv_tab_title", text=u"直销银行理财").click() with pytest.allure.step("获取理财产品名称"): financing_prd = d(resourceId=get_value("比收益理财产品名称"))[0].get_text(timeout=10) with pytest.allure.step("验证产品是否切换"): assert deposit_prd is not financing_prd Consts.RESULT_LIST.append('True')
def test_login_02(self, d): """ 比财账号登录 """ global USER_ID # 使用账号 USER_ID = str(get_value("xc手机号")) picture_verification_code = str(get_value("四位图片验证码")) login_verification_code = str(get_value("登录验证码")) with pytest.allure.step("点击app首页一键登录"): action.click_element(d, "首页一键登录") with pytest.allure.step("在登录页账号输入框输入账号"): action.input_element(d, "登录页账号输入框", USER_ID) with pytest.allure.step("点击获取验证码"): action.click_element(d, "登录页获取验证码按钮") # 点击获取验证码 # 如果弹出4位数字图片验证码 with pytest.allure.step("输入4位验证码"): time.sleep(2) if d(text=u"请填写图像验证码").exists: action.input_element(d, "图片验证码输入框", picture_verification_code) with pytest.allure.step("点击确认按钮"): action.click_element(d, "图片验证码确定按钮") with pytest.allure.step("输入6位验证码"): action.input_element(d, "登录验证码输入框", login_verification_code) with pytest.allure.step("点击立即登录"): action.click_element(d, "立即登录按钮") with pytest.allure.step("验证是否登录成功"): test.assert_element_exists_save_picture( d, not d(resourceId=get_value("首页一键登录")).exists, "验证是否登录") Consts.RESULT_LIST.append('True')
def test_check_prd_20(self, d): """ 勾选产品验证选中产品在比收益展示产品列表中 :param d: :return: """ with pytest.allure.step("勾选全部复选框"): prd_name = d(resourceId=get_value("比收益产品名称")) prd_check = d(resourceId=get_value("比收益收益率复选框")) global prd_name_list prd_name_list = [] time.sleep(2) for i in range(prd_name.__len__()): prd_name_list.append(prd_name[i].get_text().strip()) with pytest.allure.step("勾选"+prd_name[i].get_text()+"产品"): prd_check[i].click() print(prd_name_list) time.sleep(2) with pytest.allure.step("点击比收益添加产品页完成按钮"): action.click_element(d, "比收益添加产品页完成按钮") time.sleep(1) with pytest.allure.step("获取添加后的产品名称列表"): prd_name_a = [] prd_name_b = [] prd_name_return = d(resourceId=get_value("比收益理财产品名称")) for i in range(prd_name_return.__len__()): print(prd_name_return[i].get_text()) prd_name_a.append(prd_name_return[i].get_text()) with pytest.allure.step("向上划动产品列表"): d.swipe_points([(0.578, 0.94), (0.415, 0.507)], 0.2) # 向上划动产品列表 with pytest.allure.step("获取滑动后产品列表"): for i in range(prd_name_return.__len__()): print(prd_name_return[i].get_text()) prd_name_b.append(prd_name_return[i].get_text()) prd_name_return_list = list(set(prd_name_a + prd_name_b)) with pytest.allure.step("验证添加产品在比收益产品列表中"): for i in range(prd_name_list.__len__()): assert prd_name_list[i] in prd_name_return_list Consts.RESULT_LIST.append('True')
def test_return_home_page_19(self, d): """ 返回首页 :param d: """ with pytest.allure.step("返回首页"): action.click_element(d, "返回icon") with pytest.allure.step("验证返回成功"): test.assert_element_exists_save_picture(d, d(resourceId=get_value("首页左上角图标")).exists, "点击查看榜单返回首页") Consts.RESULT_LIST.append('True')
def test_click_assets_03(self, d): """ 点击资产弹登录页 :param d: :return: """ if d(resourceId=get_value("登录页关闭")).exists: with pytest.allure.step("数据回收关闭登录页"): action.click_element(d, "登录页关闭") with pytest.allure.step("点击资产"): action.click_element(d, "资产按钮") with pytest.allure.step("验证是否弹出登录页"): time.sleep(5) test.assert_element_exists_save_picture( d, d(resourceId=get_value("立即登录按钮")).exists, "弹出登录页") Consts.RESULT_LIST.append('True')
def test_click_bicai_07(self, d): """ 点击昨日收益 :param d: :return: """ with pytest.allure.step("点击导航栏比财"): action.click_element(d, "导航栏比财按钮") with pytest.allure.step("验证返回成功"): test.assert_element_exists_save_picture(d, d(resourceId=get_value("首页左上角图标")).exists, "点击查看榜单返回首页") Consts.RESULT_LIST.append('True')