class Withdram(Us_Center_action): # 用户资金密码 pwd = config_ini('config.ini', 'default', 'amount_pwd1') # 初始化资金密码 pwd2 = config_ini('config.ini', 'default', 'amount_pwd2') def withdram1(self): if self.check_element_displayed(SecurityCenterLocator.withdrawalpwd): Security_Center(self.driver).new_amount_pwd(self.pwd2) if self.check_element_displayed(BankCardLocator.new_btn): Bank_Card(self.driver).new_bank_card() def withdram(self, data): logging.info('【INFO】进入提款页面,开始执行提款操作:{}'.format( sys._getframe().f_code.co_name)) logging.info('【INFO】开始提款:提款金额:{}...资金密码:{}'.format(data, self.pwd)) self.send_value(WithdrawLocator.w_amount, data) self.send_value(WithdrawLocator.password, self.pwd) text = self.find_element(WithdrawLocator.balance).text logging.info('【INFO】可提款金额:{}...本次提款金额:{}'.format(text, data)) self.click_element(WithdrawLocator.btn) if self.check_element_displayed(WithdrawLocator.tk_button): self.click_element(WithdrawLocator.tk_button) flag = self.check_msg_txt(UserCenterPage.prompt_texts, "已提交") return flag
class TradiGameTestCase(unittest.TestCase): tradition_path = get_project_path() + '\\Data\\game\\traditiongame.yaml' browesr_name = config_ini('config.ini', 'default', 'browesr_name') env_type = config_ini('config.ini', 'default', 'env_type') skin = config_ini('config.ini', 'default', 'skin') data_path = get_project_path() + '\\Data\\game\\hc_game.xls' datas = ExcelUtil(data_path,1).read_excel_addlist() @classmethod def setUpClass(cls): WebDriver.start_browser(cls.browesr_name) cls.driver = WebDriver().get_driver() Login(cls.driver).login_page(cls.env_type,cls.skin,'前端') @classmethod def tearDownClass(cls): WebDriver().driver_quit() @file_data(tradition_path) @unittest.skipIf(excel_test_case(1,'test1_traditiongame'), 'test1_traditiongame case is skip') def test1_traditiongame(self, data): ''' 传统随机/配置游戏文件 :param data: :return: ''' logging.info('开始执行用例: {}'.format(self._testMethodName)) logging.info("【功能检查】传统游戏下注") t = Thread(target=BetGameTime(self.driver).get_hc_game_time) t.start() Us_Center_action(self.driver).to_traditiongame_page(data) TradiGame(self.driver).random_play() @data(*datas) @unittest.skipIf(excel_test_case(1, 'test2_excel_traditiongame'), 'test2_excel_traditiongame case is skip') def test2_excel_traditiongame(self,datas): ''' 信用玩法excel文件配置下注 :return: ''' logging.info('开始执行用例: {}'.format(self._testMethodName)) logging.info("【功能检查】传统游戏下注") t = Thread(target=BetGameTime(self.driver).get_hc_game_time) t.start() TradiGame(self.driver).excel_tradi_gameing(datas)
class AgActivTestCase(unittest.TestCase): # 环境/用户信息 browesr_name = config_ini('config.ini', 'default', 'browesr_name') env_type = config_ini('config.ini', 'default', 'env_type') skin = config_ini('config.ini', 'default', 'skin') # 获取一二级菜单 first = config_ini('agmod.ini', 'menu', 'first_activ') second = config_ini('agmod.ini', 'menu', 'second_activset') # 获取测试数据 data_path = get_project_path() + '\\Data\\activ\\activ_data.xls' datas = ExcelUtil(data_path).read_excel_value_type_getdata() @classmethod def setUpClass(cls): WebDriver.start_browser(cls.browesr_name) cls.driver = WebDriver().get_driver() Login(cls.driver).login_page(cls.env_type, cls.skin, '后台') AgHome(cls.driver).close_ag_pop() @classmethod def tearDownClass(cls): WebDriver().driver_quit() @data(*datas) @unittest.skipIf(excel_test_case(3, 'test1_add_activ'), 'test1_add_activ is skip') def test1_add_activ(self, datas): ''' 配置文件添加活动 :return: ''' logging.info('【INFO】【开始执行用例】{}'.format(self._testMethodName)) # 调用切换菜单进入活动设置页面 AgHome(self.driver).swith_mod(self.first, self.second) logging.info('【INFO】【切换模块】【{}】【{}】'.format(self.first, self.second)) # 调用切换table栏目菜单进入活动设置页面里 AgHome(self.driver).swith_table(self.second) flag = AgActiv(self.driver).test_activ(datas) self.assertTrue(flag, '活动添加失败,请检查')
# -*-conding:utf-8-*- import sys #python find()方法语法:学习 # 检查字符串是否包含该字符串 # str -- 指定检索的字符串 # beg -- 开始索引,默认为0。 # end -- 结束索引,默认为字符串的长度。 检测到自己想要的字符则返回索引,没检测到则返回-1 from Libs.cnfg_util import config_ini pmtpa = config_ini('financial.ini', 'web', 'pmtp') str = '微信转账,支付宝转账' # print(str.find(',')) print(pmtpa) print(pmtpa.find('0', 0, 50)) # 参数直接输入数字就好,输入关键字则回报错 # -1 因为该字符串里面没有0这个字符,返回-1 print(pmtpa.find('通')) # 一般都是默认参数 # 38 返回索引值 # 一般用法 : 用来确认字符串里面是否包含自己想要的字符串 if pmtpa.find(',') != -1: print('判断为真,字符串里面包含检查字符') # list = [1,"qwasd",'微信'] # print(list.find('微信')) # 列表没有这个方法属性 print(str.find('8'))
class AgOfflineTestCase(unittest.TestCase): browesr_name = config_ini('config.ini', 'default', 'browesr_name') env_type = config_ini('config.ini', 'default', 'env_type') skin = config_ini('config.ini', 'default', 'skin') loginfo = login_info(env_type, skin, '前端') first_financial = config_ini('agmod.ini', 'menu', 'first_financial') second_offline = config_ini('agmod.ini', 'menu', 'second_offline') def setUp(self): logging.info('启动测试脚本文件: {}.py'.format(self.__module__)) WebDriver.start_browser(self.browesr_name) self.driver = WebDriver().get_driver() # 前台造数据 logging.info("【INFO】登录前台环境准备公司入款数据......") Login(self.driver).login_page(self.env_type, self.skin, '前端') Us_Center_action(self.driver).to_top_page() TopUp(self.driver).random_offline_top() # 后台登录 Login(self.driver).login_page(self.env_type, self.skin, '后台') AgHome(self.driver).close_ag_pop() # 点击财务管理-公司入款栏目 AgHome(self.driver).swith_mod(self.first_financial, self.second_offline) # 点击进入公司入款栏目 AgHome(self.driver).swith_table(self.second_offline) # 下面一行用于测试 #AgOffline(cls.driver).check_is_page() # 调用公司入款对象-输入用户名-拿到订单号-唯一标识 self.order_number = AgOffline(self.driver).get_order_number( self.loginfo['user']) def tearDown(self): WebDriver().driver_quit() @unittest.skipIf(excel_test_case(2, 'test1_offline_confirm'), 'test1_offline_confirm case is skip') def test1_offline_confirm(self): ''' 公司入款审核确认 :return: ''' logging.info('【INFO】执行case【公司入款审核】【{}】'.format(self._testMethodName)) flag = AgOffline(self.driver).offline_confirm(self.order_number) self.assertTrue(flag, 'case执行失败,公司入款审核异常,请检查') @unittest.skipIf(excel_test_case(2, 'test2_offline_lock'), 'test2_offline_lock case is skip') def test2_offline_lock(self): ''' 公司入款锁定 :return: ''' logging.info('【INFO】执行case【公司入款锁定】【{}】'.format(self._testMethodName)) flag = AgOffline(self.driver).offline_lock(self.order_number) self.assertTrue(flag, 'case执行失败,公司入款锁定异常') @unittest.skipIf(excel_test_case(2, 'test3_offline_cel'), 'test3_offline_cel case is skip') def test3_offline_cel(self): ''' 公司入款取消 :return: ''' logging.info('【INFO】执行case【公司入款取消】【{}】'.format(self._testMethodName)) flag = AgOffline(self.driver).offline_cel(self.order_number) self.assertTrue(flag, 'case执行失败,公司入款取消异常')
class WebTopUpTestCase(unittest.TestCase): # 类属性(环境信息:浏览器,环境,皮肤) file_path = get_project_path() + "\\Data\\financial\\touup_online.yaml" browesr_name = config_ini('config.ini', 'default', 'browesr_name') env_type = config_ini('config.ini', 'default', 'env_type') skin = config_ini('config.ini', 'default', 'skin') online_top = config_ini('financial.ini', 'web', 'pmtp') # 配置文件支付方式 withdram_file_path = get_project_path( ) + "\\Data\\financial\\withdram.yaml" # 根据环境信息获取登录信息(url,user,password) @classmethod def setUpClass(cls): logging.info('启动测试脚本文件: {}.py'.format(cls.__module__)) WebDriver.start_browser(cls.browesr_name) cls.driver = WebDriver().get_driver() Login(cls.driver).login_page(cls.env_type, cls.skin, '前端') @classmethod def tearDownClass(cls): WebDriver().driver_quit() @file_data(file_path) @unittest.skipIf(excel_test_case(2, 'test1_file_top'), 'test1_file_top case is skip') def test1_file_top(self, data): ''' 配置文件yaml支付方式 :param data: :return: ''' flag = False logging.info('【INFO】[开始执行用例]{}'.format(self._testMethodName)) datas = data.split(',') logging.info('【INFO】支付平台:' + datas[0] + '---' + "充值金额:" + datas[1]) try: Us_Center_action(self.driver).to_top_page() print('进入充值页面成功') flag = TopUp(self.driver).check_pay(data) except Exception as err: logging.error(err) self.assertTrue(flag, "案例执行失败") @unittest.skipIf(excel_test_case(2, 'test2_ini_top'), 'test2_ini_top case is skip') def test2_ini_top(self): ''' 配置文件ini线上支付方式 :return: ''' logging.info('【INFO】[开始执行用例]{}'.format(self._testMethodName)) Us_Center_action(self.driver).to_top_page() flag = TopUp(self.driver).random_online_top() self.assertTrue(flag, '案例执行失败') @unittest.skipIf(excel_test_case(2, 'test3_ini_offline'), 'test3_ini_offline case is skip') def test3_ini_offline(self): ''' 配置文件线下转账 :return: ''' logging.info('【INFO】[开始执行用例]{}'.format(self._testMethodName)) Us_Center_action(self.driver).to_top_page() flga = TopUp(self.driver).random_offline_top() if flga == True: print('anlichenggong') else: print('2') self.assertTrue(flga, '案例执行失败') @file_data(withdram_file_path) @unittest.skipIf(excel_test_case(2, 'test4_file_withdraw'), 'test4_file_withdraw case is skip') def test4_file_withdraw(self, data): ''' 配置文件yaml格式提款 :return: ''' logging.info('【INFO】[开始执行用例]{}'.format(self._testMethodName)) Us_Center_action(self.driver).to_withdraw_page() Withdram(self.driver).withdram1() Us_Center_action(self.driver).to_withdraw_page() flag = Withdram(self.driver).withdram(data) self.assertTrue(flag, '案例执行失败')
class GameTestCase(unittest.TestCase): # 配置项循环数/num num = config_ini('game.ini', 'game', 'number') offical_path = get_project_path() + '\\Data\\game\\officialgame.yaml' browesr_name = config_ini('config.ini', 'default', 'browesr_name') env_type = config_ini('config.ini', 'default', 'env_type') skin = config_ini('config.ini', 'default', 'skin') loginfo = login_info(env_type, skin, '前端') game_path = get_project_path() + '\\' data_path = get_project_path() + '\\Data\\game\\hc_game.xls' datas = ExcelUtil(data_path).read_excel_addlist() @classmethod def setUpClass(cls): logging.info('启动测试脚本文件: {}.py'.format(cls.__module__)) WebDriver.start_browser(cls.browesr_name) cls.driver = WebDriver().get_driver() Login(cls.driver).login_page(cls.env_type, cls.skin, '前端') @classmethod def tearDownClass(cls): WebDriver().driver_quit() @file_data(offical_path) @unittest.skipIf(excel_test_case(1, 'test1_officialgame'), 'test1_officialgame case is skip') def test1_officialgame(self, data): ''' 官方随机/配置游戏文件 :param data: :return: ''' logging.info('开始执行用例: {}'.format(self._testMethodName)) logging.info("【功能检查】官方游戏下注") Us_Center_action(self.driver).to_officialgame_page(data) Gameing(self.driver).official_gameing() # @file_data(tradition_path) # @unittest.skipIf(excel_test_case(1, 'test2_traditiongame'), 'test2_traditiongame case is skip') # def test2_traditiongame(self,data): # ''' # 传统随机/配置游戏文件 # :param data: # :return: # ''' # logging.info('开始执行用例: {}'.format(self._testMethodName)) # logging.info("【功能检查】传统游戏下注") # Us_Center_action(self.driver).to_traditiongame_page(data) @data(*datas) @unittest.skipIf(excel_test_case(1, 'test3_game_playtype'), 'test3_game_playtype case is skip') def test3_game_playtype(self, datas): ''' 配置项玩法投注 :return: ''' logging.info('开始执行用例: {}'.format(self._testMethodName)) logging.info("【功能检查】玩法配置项投注") Gameing(self.driver).official_excel_gamging(datas)
class Gameing(Us_Center_action): yamlbs_num = config_ini('game.ini', 'game', 'yamlbs_num') yamlsj_num = config_ini('game.ini', 'game', 'yamlsj_num') def official_gameing(self): ''' 官方游戏随机下注 :return: ''' self.random_play_list(GamePageLocator.play_type) def random_play_list(self, locator): el = self.find_elements(locator) for i in range(len(el)): el[i].click() if self.check_element_displayed(GamePageLocator.random_btn): # 倍数 element = self.find_element(GamePageLocator.pow_num) element.clear() element.send_keys(self.yamlbs_num) #self.send_value(GamePageLocator.random_num,5) 随机注数 temp = self.find_element(GamePageLocator.random_num) temp.clear() temp.send_keys(self.yamlsj_num) # 随机 self.click_element(GamePageLocator.random_btn) time.sleep(0.5) self.click_element(GamePageLocator.confirm_btn) if self.check_msg_txt(UserCenterPage.prompt_text, '投注成功'): logging.info('【功能检查】游戏下注成功') else: logging.info('【功能检查】游戏下注失败,请检查') def official_excel_gamging(self, data): # 根据游戏类型判断调用方法 if data['types'] in '11选5,PK拾,分分彩,时时彩': self.official_lottery_min(data) else: logging.error('【INFO】【游戏类型有误,请检查】【{}】'.format(data['types'])) def official_lottery_min(self, data): ''' 官方游戏 :param data: :return: ''' # 根据游戏ID进入游戏 self.swith_game_page(data['lottery'], data['lottery_id']) # 获取玩法点击 self.get_playtypr_loc_click(data['play1']) if self.check_element_displayed(GamePageLocator.play_num_list): # 循环投注项投注玩法 item = data['item'].split('|') for i in range(len(item)): j = 1 j += i temp = item[i].split(',') for t in range(len(temp)): self.click_element(GamePageLocator.get_game_loc( j, temp[t])) # 获取游戏倍数 ele = self.find_element(GamePageLocator.pow_num) ele.clear() ele.send_keys(data['multip']) # 立即下注按钮 self.click_element(GamePageLocator.fast_btn) if self.check_msg_txt(UserCenterPage.prompt_text, '投注成功'): logging.info('【功能检查】游戏下注成功') else: logging.info('【功能检查】游戏下注失败,请检查') else: logging.info('【INFO】游戏玩法没有点击投注选项,请确认') def swith_game_page(self, data1, data2): ''' 根据ID进入游戏页面 :return: ''' if data1 not in self.driver.title: ''' 根据游戏名判断页面 ''' self.get_url(UserCenterPage.get_officialgame_url(data2)) time.sleep(3) if self.title_in(data1): logging.info('【INFO】【{}】进入页面成功'.format(data1)) else: logging.error('【INFO】【{}】进入页面失败,请检查文件数据'.format(data1)) else: logging.info('【INFO】【{}】处于当前游戏页面'.format(data1)) time.sleep(2) def get_playtypr_loc_click(self, data): ''' 获取玩法locator并点击操作 :param data: :return: ''' self.click_element(GamePageLocator.get_playtype_loc(data))
class AgYueBaoTestCase(unittest.TestCase): browesr_name = config_ini('config.ini', 'default', 'browesr_name') env_type = config_ini('config.ini', 'default', 'env_type') skin = config_ini('config.ini', 'default', 'skin') datas_path = get_project_path() + '\\Data\\activ\\activ_data.xls' first = config_ini('agmod.ini', 'menu', 'first_activ') second = config_ini('agmod.ini', 'menu', 'second_zdyhd') datas = ExcelUtil(datas_path, 1).read_excel_value_type_getdata() loninfo = login_info(env_type, skin, '前端') @classmethod def setUpClass(self): WebDriver.start_browser(self.browesr_name) self.driver = WebDriver().get_driver() # 后台添加余额宝数据 ah = AgHome(self.driver) Login(self.driver).login_page(self.env_type, self.skin, '后台') ah.close_ag_pop() ah.swith_mod(self.first, self.second) ah.swith_table(self.second) self.ac_name = AgYueBao(self.driver).add_yuebao_activ(self.datas[0]) # 前台 Login(self.driver).login_page(self.env_type, self.skin, '前端') @classmethod def tearDownClass(cls): WebDriver().driver_quit() @unittest.skipIf(excel_test_case(3, 'test1_min_amount'), 'test1_min_amount is skip') def test1_min_amount(self): ''' 小于最低限额test :return: data = [['产品名称', '单笔限额', '计算周期(小时)', '利率', '利息上限', '续存次数', '剩余数量', '利息稽核倍数', '操作'], ['2', '2-23', '2小时', '2%', '2', '2', '1', '2倍', '立即购买'], ['3', '23-456', '4小时', '4%', '4', '4', '4', '4倍', '立即购买']] ''' logging.info('开始执行case:{}'.format(self._testMethodName)) logging.info('【功能检查】【余额宝购买金额小于最低限额】') self.data = WebYueBao(self.driver).get_web_yuebao_testdata( self.ac_name, self.loninfo) flag = WebYueBao(self.driver).min_amount_test(self.data) self.assertTrue(flag, '小于最低金额执行失败,请检查!') @unittest.skipIf(excel_test_case(3, 'test2_max_amount'), 'test2_max_amount is skip') def test2_max_amount(self): ''' 超过最大限额test :return: ''' logging.info('开始执行case:{}'.format(self._testMethodName)) logging.info('【功能检查】【余额宝购买金额超过最大限额】') self.data = WebYueBao(self.driver).get_web_yuebao_testdata( self.ac_name, self.loninfo) flag = WebYueBao(self.driver).max_amount_test(self.data) self.assertTrue(flag, '超过最大限额执行失败,请检查!') @unittest.skipIf(excel_test_case(3, 'test3_yuebao_success'), 'ttest3_yuebao_success is skip') def test3_yuebao_success(self): ''' 正确金额购买test :return: ''' logging.info('开始执行case:{}'.format(self._testMethodName)) logging.info('【功能检查】【正确金额购买】') self.data = WebYueBao(self.driver).get_web_yuebao_testdata( self.ac_name, self.loninfo) flag = WebYueBao(self.driver).amount_success(self.data) self.assertTrue(flag, '正确金额购买执行失败,请检查!')
class TopUp(Us_Center_action): r = RandomUtil() name = r.random_name() # 初始化资金密码 pwd = config_ini('config.ini', 'default', 'amount_pwd2') num = get_random_int(1000, 2000) code = config_ini('config.ini', 'default', 'code') pmt = config_ini('financial.ini', 'web', 'pmtp') on_top = config_ini('financial.ini', 'web', 'on_top') # 判断是否有充值通道 def check_pay(self, data): ''' 支付通道检查 :return: ''' flag = False if self.check_element_displayed(TopUpLocator.no_pay): text = self.find_element(TopUpLocator.no_pay).text logging.error(text) logging.info('【INFO】没有充值通道:请检查【{}】'.format( sys._getframe().f_code.co_name)) else: flag = self.data_split(data) return flag # 切割支付方式和金额数据 def data_split(self, datas): flag = False if datas.find(",") != -1: data = datas.split(',') flag = self.swith_pay_type(data[0], data[1]) else: logging.info("【INFO】支付通道或充值金额填写错误,请检查!") return flag # 切换支付平台 def swith_pay_type(self, pay_type, num): ''' 获取支付渠道/切换支付方式 :param pay_type:配置文件获取的支付渠道 :param num: 金额 :return: ''' flag = False onlne_top = ['支付宝', '在线支付', 'QQ钱包', '财付通', '京东', '百度', '企业支付宝', '微信'] offline_top = ['QQ钱包转账', '云闪付转账', '微信转账', '支付宝转账'] if self.check_element_displayed(TopUpLocator.pmt_platform(pay_type)): locator = TopUpLocator.pmt_platform(pay_type) self.click_element(locator) if pay_type == "银行卡转账": flag = self.bank_top1(num) elif pay_type in onlne_top: flag = self.on_top2(pay_type, num) elif pay_type in offline_top: flag = self.offline_top3(pay_type, num) else: logging.error("【INFO】支付通道不存在当前页面,请检查文件数据!") return flag def bank_top1(self, num): ''' 银行卡转账 :return: ''' flag = False # 判断是否有资金密码 if self.check_element_displayed(SecurityCenterLocator.withdrawalpwd): Security_Center(self.driver).new_amount_pwd(self.pwd) # 判断银行卡更换卡弹窗并关闭 self.check_msg_txt(UserCenterPage.prompt_texts, "入款卡已更换") # 判断充值指引弹窗并关闭 self.close_tup_gui() # 随机选择银行并点击 self.random_click_el(TopUpLocator.bank_list) # 输入 self.bank_util_input(num) # 判断存款优惠方案 self.preference() # 判断是否存在选择支付方式有则随机点击 if self.check_element_displayed(TopUpLocator.pay_type): self.random_pay_type(TopUpLocator.pay_type) # 点击提交按钮 self.click_element(TopUpLocator.submit_button) # 判断提示框文字是否为“提交成功”并关闭 time.sleep(1) flag = self.check_msg_txt(UserCenterPage.bank_tc_text, "成功") else: # 点击提交按钮 self.click_element(TopUpLocator.submit_button) # 判断提示框文字是否为“提交成功”并关闭 time.sleep(1) flag = self.check_msg_txt(UserCenterPage.prompt_text, "成功") return flag def on_top2(self, pay_type, num): ''' 线上支付 :param num: :return: ''' # 判断是否有资金密码 if self.check_element_displayed(SecurityCenterLocator.withdrawalpwd): Security_Center(self.driver).new_amount_pwd(self.pwd) self.click_element(TopUpLocator.pmt_platform(pay_type)) self.close_tup_gui() else: self.close_tup_gui() # 随机选择支付渠道 self.random_click_el(TopUpLocator.online_pay) # 通用支付输入方法 self.onpay_util_input(num) # 提交 self.click_element(TopUpLocator.rbank_btn) self.click_element(TopUpLocator.rbank_btn) # 判断优惠方案 self.preference() # 关闭支付多出页面 self.close_other_page() # 判断文本 flag = self.check_msg_txt(UserCenterPage.prompt_text, "提交成功") return flag def offline_top3(self, pay_type, num): ''' 线下转账(微信转账,支付宝转账。。。) :param num: :return: ''' # 判断是否有资金密码 if self.check_element_displayed(SecurityCenterLocator.withdrawalpwd): Security_Center(self.driver).new_amount_pwd(self.pwd) self.click_element(TopUpLocator.pmt_platform(pay_type)) # 随机选择支付渠道 self.random_click_el(TopUpLocator.online_pay) # 输入 self.send_value(TopUpLocator.amount3, num) self.send_value(TopUpLocator.dep_person3, self.name) # 提交 self.click_element(TopUpLocator.rbank_btn) # 优惠方案 time.sleep(1) self.preference() time.sleep(2) # 判断文本 flag = self.check_msg_txt(UserCenterPage.prompt_text, '成功') return flag def random_offline_top(self): ''' 随机一种线下转账:金额随机 :return: ''' flag = False if self.pmt.find(',') != -1: data = self.pmt.split(',') for i in range(len(data) - 1): flag = self.swith_pay_type(data[i], self.num) break else: logging.error("【INFO】配置文件数据写入有误,请检查") return flag def random_online_top(self): ''' 随机一种线上支付:金额随机 :return: ''' flag = False if self.on_top.find(',') != -1: data = self.on_top.split(',') for i in range(len(data) - 1): flag = self.swith_pay_type(data[i], self.num) break else: logging.error("【INFO】配置文件数据写入有误,请检查") return flag def random_click_el(self, locator): ''' 获取一组元素随机点击一个 :param locator: :return: ''' el = self.find_elements(locator) for i in range(len(el)): i = get_random_int(i, len(el) - 1) logging.info('【INFO】【{}】'.format(el[i].text)) el[i].click() break def random_pay_type(self, locator): ''' 转账类型随机选择并判断 :param locator: :return: ''' el = self.find_elements(locator) for i in range(len(el)): i = get_random_int(i, len(el) - 1) el[i].click() text = el[i].text print(text) if "银行柜台" in text: self.send_value(TopUpLocator.bank_counter, self.name) elif "微信" in text: self.check_msg_txt(UserCenterPage.prompt_text, "微信") break def top_gui_close(self): ''' 检查充值指引提示框并关闭 :return: ''' if self.check_element_displayed(TopUpLocator.top_gui): self.click_element(TopUpLocator.top_gui) def preference(self): ''' 存款优惠方案弹窗处理 :return: ''' if self.check_element_displayed(UserCenterPage.msg_prompt): self.random_click_el(TopUpLocator.get_Preference) self.click_element(UserCenterPage.msg_prompt_sbmit) def close_tup_gui(self): ''' 判断是否存在充值指引弹窗并关闭 :return: ''' if self.check_element_displayed(TopUpLocator.top_gui): self.click_element(TopUpLocator.top_gui) else: logging.info("【INFO】该支付渠道没有充值指引!跳过此操作步骤") def onpay_util_input(self, num): ''' 线上支付通用操作 :param num: :return: ''' if self.check_element_displayed(TopUpLocator.pay_for_code): self.send_value(TopUpLocator.pay_for_code, self.code) if self.check_element_displayed(TopUpLocator.online_amount): self.send_value(TopUpLocator.online_amount, num) if self.check_element_displayed(TopUpLocator.get_amount_val): self.random_click_el(TopUpLocator.get_amount_val) def bank_util_input(self, num): ''' 银行卡转账通用输入操作 :return: ''' self.send_value(TopUpLocator.amount1, num) self.send_value(TopUpLocator.dep_person1, self.name) def close_other_page(self): all_page = self.driver.window_handles for page in all_page: self.driver.switch_to.window(page) if "用户中心" not in self.driver.title: self.driver.close() self.switch_window("用户中心")
class TradiGame(Us_Center_action): bet_longhu = config_ini('game.ini','game','bet_longhu') def random_play(self): ''' 信用游戏随机下注 :return: ''' # 快捷按钮点击 self.click_element(TradiGameLocator.fast_btn) # 获取玩法项list el = self.find_elements(TradiGameLocator.tradi_play_list) for i in range(len(el)): self.get_game_time() el[i].click() # 获取投注项list try: element = self.find_elements(TradiGameLocator.play_bet_list) for i in range(len(element)): self.get_game_time() if i%4 == 0: element[i].click() # 输入金额 self.get_game_time() self.send_value(TradiGameLocator.amount,10) # 点击确定按钮 self.get_game_time() self.scroll_element(TradiGameLocator.commit_btn) # 投注二次确认 time.sleep(1) if self.check_element_displayed(TradiGameLocator.second_btn): self.click_element(TradiGameLocator.second_btn) # time.sleep(1) self.bet_text_exit() except Exception as eer: logging.debug(eer) def excel_tradi_gameing(self,data): ''' excel配置玩法项下注 :return: ''' try: # 根据ID判断游戏页面 self.to_swith_game_page(data['lottery'], data['lottery_id']) # 获取玩法locator点击 self.get_game_time() self.click_element(TradiGameLocator.get_tradigame_play_loc(data['play1'])) print(data['play1']) print(data['play2']) # 玩法判断并输入金额 if data['play1'] == '龙虎斗': self.play1_bet_longhu(data['play2'],data['item'],data['amount']) else: self.play2_bet(data['play2'],data['item'],data['amount']) # 点击确定按钮 self.get_game_time() self.scroll_element(TradiGameLocator.commit_btn) # 投注二次确认 time.sleep(0.5) if self.check_element_displayed(TradiGameLocator.second_btn): self.get_game_time() self.find_element(TradiGameLocator.second_btn).click() else: self.click_element(TradiGameLocator.bet_sceeuse_btn) # 投注三次确认 if self.check_element_displayed(TradiGameLocator.three_text): self.find_element(TradiGameLocator.bet_sceeuse_btn).click() # 下注文本检测 time.sleep(0.5) self.bet_text_exit() except Exception as error: logging.error(error) finally: try: self.click_element(TradiGameLocator.bet_sceeuse_btn) except Exception as t: pass def to_swith_game_page(self, data1,data2): ''' 根据游戏名判断页面 :return: ''' if data1 not in self.driver.title: self.get_url(UserCenterPage.get_traditiongame_url(data2)) time.sleep(3) if data1 in self.driver.title: logging.info('【INFO】【{}】进入页面成功'.format(data1)) else: logging.info('【INFO】【{}】进入页面失败,请检查文件数据'.format(data1)) else: logging.info('【INFO】【{}】处于当前游戏页面'.format(data1)) time.sleep(2) def get_game_time(self): ''' 获取期数和时间状态 :return: ''' # 判断和获取到的期数和时间的键值是否一致 # 获取当前url正则 dict_key = re_sub('#[0-9].*', '', self.driver.current_url) if BetGameTime.period_tip.values() in ['未开盘']: logging.info('【游戏未开盘,请检查】') for i in range(4): # 确定在同一游戏页面 if dict_key in BetGameTime.period_tip.keys() and dict_key in BetGameTime.game_time.keys(): # 判断当前期数状态 if BetGameTime.period_tip[dict_key] == '剩余投注时间' and BetGameTime.game_time[dict_key] > 1: break else: try: time.sleep(1) print('3') self.click_element(TradiGameLocator.btn) except Exception as e: logging.debug(e) def bet_text_exit(self): if self.check_element_displayed(TradiGameLocator.text): text = self.find_element(TradiGameLocator.text).text if '成功' in text: logging.info('【功能检查】信用游戏下注成功') self.get_game_time() self.find_element(TradiGameLocator.bet_sceeuse_btn).click() else: self.click_element(TradiGameLocator.bet_sceeuse_btn) else: self.find_element(TradiGameLocator.bet_sceeuse_btn).click() def play2_bet(self,play2,item,amount): ''' 玩法2判断 :return: ''' if play2 == '': items = item.split(',') for i in range(len(items)): el = self.find_element(TradiGameLocator.get_play2_3(items[i])) self.get_game_time() el.send_keys(amount) else: items = item.split(',') for i in range(len(items)): el = self.find_element(TradiGameLocator.get_play2_1(play2, items[i])) self.get_game_time() el.send_keys(amount) def play1_bet_longhu(self,play2,item,amount): ''' 龙虎斗玩法特殊处理 :return: ''' if play2 in self.bet_longhu: items = item.split(',') for i in range(len(items)): el = self.find_element(TradiGameLocator.get_play2_2(play2, items[i])) self.get_game_time() el.send_keys(amount)