def test_my_offers_click_edit_button_success(self): """编辑按钮""" # 登陆成功后跳转到广告列表页面 self.login_driver.user_login_click_my_offers(self.login_driver) # 设置页面锚点为顶端 self.my_offers_driver.js_scroll_top() # 获取第一条广告的信息 try: edit_otc_mysql = MysqlPool("mysql") get_member_id = "select member_id from member.tm_member_identity where identity = %s " member_id = edit_otc_mysql.getOne(get_member_id, "*****@*****.**") get_otc_info = "select * from otc.tb_otc_advert where member_id = %s and STATE != 90 order by STATE,CREATE_TIME desc limit 1" otc_info = edit_otc_mysql.getAll(get_otc_info, (member_id['member_id'], )) self.log.info("广告详情:{}".format(otc_info)) pass # 点击第一条广告编辑按钮 except Exception as e: self.log.info(e) finally: edit_otc_mysql.dispose() self.my_offers_driver.click(self.my_offers_driver.a_edit_offer) time.sleep(10) # 获取跳转后的URL edit_url = self.driver.current_url assert str( otc_info[0]['ID']) in edit_url, "数据库广告ID:{},跳转广告URL:{}".format( otc_info[0]['ID'], edit_url) self.driver.refresh() time.sleep(5)
def test_my_offers_click_status_button_success(self): """修改广告上下架状态""" # 登陆成功后跳转到广告列表页面 self.login_driver.user_login_click_my_offers(self.login_driver) # 设置页面锚点为顶端 self.my_offers_driver.js_scroll_top() # 获取所有上下架状态选择框 switch_status_elements = self.my_offers_driver.find_elements( self.my_offers_driver.span_switch) # 随机获取任意广告 switch_status_position = random.randint( 0, len(switch_status_elements) - 1) # 获取该条广告的数据库信息 try: otc_mysql = MysqlPool("mysql") get_member_id = "select member_id from member.tm_member_identity where identity = %s " member_id = otc_mysql.getOne(get_member_id, "*****@*****.**") get_otc_info = "select ID,STATE from otc.tb_otc_advert where member_id = %s and STATE != 90 order by STATE,CREATE_TIME desc" otc_info = otc_mysql.getAll(get_otc_info, (member_id['member_id'], )) otc_info_state = otc_info[switch_status_position]['STATE'] otc_info_id = otc_info[switch_status_position]['ID'] self.log.info("STATE:{},ID:{}".format(otc_info_state, otc_info_id)) except Exception as e: self.log.info("获取广告信息数据库错误:{}".format(e)) finally: otc_mysql.dispose() # 获取该条广告的页面信息 switch_status_element_text = switch_status_elements[ switch_status_position].text self.log.info("页面广告上下架信息:{}".format(switch_status_element_text)) if switch_status_element_text == "on": switch_status_elements[switch_status_position].click() time.sleep(5) assert "off" == switch_status_elements[ switch_status_position].text, "页面广告信息".format( switch_status_elements[switch_status_position].text) elif switch_status_element_text == "off": switch_status_elements[switch_status_position].click() time.sleep(5) assert "on" == switch_status_elements[ switch_status_position].text, "页面广告信息".format( switch_status_elements[switch_status_position].text) self.driver.refresh() time.sleep(5)
def test_my_offers_click_delete_button_success(self): """删除按钮""" # 登陆成功后跳转到广告列表页面 self.login_driver.user_login_click_my_offers(self.login_driver) # 设置页面锚点为顶端 self.my_offers_driver.js_scroll_top() # 获取第一条广告的信息 try: delete_otc_mysql = MysqlPool("mysql") get_member_id = "select member_id from member.tm_member_identity where identity = %s " member_id = delete_otc_mysql.getOne(get_member_id, "*****@*****.**") get_otc_info = "select ID,STATE from otc.tb_otc_advert where member_id = %s and STATE != 90 order by STATE,CREATE_TIME desc limit 1" otc_info = delete_otc_mysql.getAll(get_otc_info, (member_id['member_id'], )) otc_advert_id = otc_info[0]['ID'] except Exception as e: self.log.info("获取广告信息数据库错误:{}".format(e)) finally: delete_otc_mysql.dispose() # 点击第一条广告删除按钮 self.my_offers_driver.click(self.my_offers_driver.a_delete_offer) time.sleep(5) # 获取删除提示框取消按钮 alert_cancel_button_elements = self.my_offers_driver.find_elements( self.my_offers_driver.alert_cancel_button) time.sleep(5) # 点击取消按钮(第二个元素) alert_cancel_button_elements[len(alert_cancel_button_elements) - 1].click() time.sleep(5) try: delete_otc_cancel_mysql = MysqlPool("mysql") get_otc_cancel_status = "select STATE from otc.tb_otc_advert where ID = %s" otc_cancel_status = delete_otc_cancel_mysql.getOne( get_otc_cancel_status, otc_advert_id) assert otc_cancel_status['STATE'] == otc_info[0][ 'STATE'], "广告状态:{}".format(otc_info[0]['STATE']) time.sleep(5) except Exception as e: self.log.info("取消按钮数据库异常:{}".format(e)) finally: delete_otc_cancel_mysql.dispose() # 再次点击第一条广告删除按钮 self.my_offers_driver.click(self.my_offers_driver.a_delete_offer) # 获取删除提示框确认按钮 alert_confirm_button_elements = self.my_offers_driver.find_elements( self.my_offers_driver.alert_confirm_button) time.sleep(5) # 点击确认按钮(第二个元素) alert_confirm_button_elements[len(alert_confirm_button_elements) - 1].click() time.sleep(5) try: delete_otc_confirm_mysql = MysqlPool("mysql") get_otc_confirm_status = "select STATE from otc.tb_otc_advert where ID = %s" otc_confirm_status = delete_otc_confirm_mysql.getOne( get_otc_confirm_status, otc_advert_id) assert otc_confirm_status['STATE'] == 90, "广告状态:{}".format( otc_confirm_status['STATE']) except Exception as e: self.log.info("确认按钮数据库异常:{}".format(e)) finally: delete_otc_confirm_mysql.dispose() self.driver.refresh() time.sleep(5)
def test_my_offers_home_page_success(self): """测试首页广告信息""" # 登陆成功后跳转到广告列表页面 self.login_driver.user_login_click_my_offers(self.login_driver) # 设置页面锚点为顶端 self.my_offers_driver.js_scroll_top() # 获取当前页面所有广告 my_offers_elements = self.my_offers_driver.find_elements( self.my_offers_driver.div_my_offer) # 获取数据库中所有广告 try: otc_mysql = MysqlPool("mysql") get_member_id = "select member_id from member.tm_member_identity where identity = %s " member_id = otc_mysql.getOne(get_member_id, "*****@*****.**") get_otc_info = "select * from otc.tb_otc_advert where member_id = %s and STATE != 90 order by STATE,CREATE_TIME desc limit 0,19" otc_info = otc_mysql.getAll(get_otc_info, (member_id['member_id'], )) self.log.info("广告详情:{}".format(otc_info)) except Exception as e: self.log.info(e) finally: otc_mysql.dispose() for advert_position in range(len(my_offers_elements)): # 获取每个广告div的text信息 element_text = my_offers_elements[advert_position].text # 将text信息封装为 my_offers_info = element_text.split('\n') self.log.info("my_offers_info:{}".format(my_offers_info)) # 获取当前广告的支付方式 try: otc_advert_payment_way_mysql = MysqlPool("mysql") get_payment_way = "select distinct EXCHANGE_WAY from otc.tb_otc_advert_payment_way where VALID=1 and ADVERT_ID = %s order by EXCHANGE_WAY;" payment_way = otc_advert_payment_way_mysql.getAll( get_payment_way, (otc_info[advert_position]['ID'], )) self.log.info("支付方式:{}".format(payment_way)) except Exception as e: self.log.info(e) finally: otc_advert_payment_way_mysql.dispose( otc_advert_payment_way_mysql) payment_way_list = [] for payment_way_info in payment_way: payment_way_list.append(payment_way_info['EXCHANGE_WAY']) self.log.info("支付列表:{}".format(payment_way_list)) # 将广告信息与数据库表做断言 # 判断广告方向 if 'Buy offer' in my_offers_info[1]: assert otc_info[advert_position][ 'SIDE'] == 1, "数据库中广告类型:{},页面广告类型:{}".format( otc_info[advert_position]['SIDE'], my_offers_info[1]) elif 'Sell offer' in my_offers_info[1]: assert otc_info[advert_position][ 'SIDE'] == 2, "数据库中广告类型:{},页面广告类型:{}".format( otc_info[advert_position]['SIDE'], my_offers_info[1]) # 判断广告类型 elif '(Float)' in my_offers_info[1]: assert otc_info[advert_position][ 'BID_WAY'] == 1, "数据库中广告类型:{},页面广告类型:{}".format( otc_info[advert_position]['BID_WAY'], my_offers_info[1]) elif '(Fixed)' in my_offers_info[1]: assert otc_info[advert_position][ 'BID_WAY'] == 2, "数据库中广告类型:{},页面广告类型:{}".format( otc_info[advert_position]['BID_WAY'], my_offers_info[1]) # 判断广告价格 if otc_info[advert_position]['OFFLINE_COIN'] == 'USD': assert my_offers_info[2] == str( otc_info[advert_position]['BID_PRICE'].quantize( Decimal('0.0000') )), "页面价格:{},页面价格的数据类型:{},数据库价格:{},数据库价格的数据类型:{}".format( my_offers_info[2], type(my_offers_info[2]), otc_info[advert_position]['BID_PRICE'].quantize( Decimal('0.0000')), type(otc_info[advert_position]['BID_PRICE'].quantize( Decimal('0.0000')))) elif otc_info[advert_position]['OFFLINE_COIN'] == 'HKD': assert my_offers_info[2] == str( otc_info[advert_position]['BID_PRICE'].quantize( Decimal('0.000') )), "页面价格:{},页面价格的数据类型:{},数据库价格:{},数据库价格的数据类型:{}".format( my_offers_info[2], type(my_offers_info[2]), otc_info[advert_position]['BID_PRICE'].quantize( Decimal('0.000')), type(otc_info[advert_position]['BID_PRICE'].quantize( Decimal('0.000')))) else: assert my_offers_info[2] == str( otc_info[advert_position]['BID_PRICE'].quantize( Decimal('0.00') )), "页面价格:{},页面价格的数据类型:{},数据库价格:{},数据库价格的数据类型:{}".format( my_offers_info[2], type(my_offers_info[2]), otc_info[advert_position]['BID_PRICE'].quantize( Decimal('0.00')), type(otc_info[advert_position]['BID_PRICE'].quantize( Decimal('0.00')))) # 判断广告币种 assert "{}/{}".format( otc_info[advert_position]['OFFLINE_COIN'], otc_info[advert_position]['PLATFORM_COIN'] ) == my_offers_info[3], "数据库中交易币种:{},页面交易币种:{}".format( "{}/{}".format(otc_info[advert_position]['OFFLINE_COIN'], otc_info[advert_position]['PLATFORM_COIN']), my_offers_info[3]) # 判断广告限额 assert "{}-{}".format(otc_info[advert_position]['EXCHANGE_MIN_VOLUMN'].quantize(Decimal('0')), otc_info[advert_position]['EXCHANGE_MAX_VOLUMN'].quantize(Decimal('0'))) == \ my_offers_info[4].translate(str.maketrans('', '', ',')), "数据库拼接广告限额:{},页面广告限额:{}".format( "{}-{}".format(otc_info[advert_position]['EXCHANGE_MIN_VOLUMN'].quantize(Decimal('0')), otc_info[advert_position]['EXCHANGE_MAX_VOLUMN'].quantize(Decimal('0'))), my_offers_info[4].translate(str.maketrans('', '', ','))) # 判断支付方式 # 支付方式列表 payment_method = { 1: 'Bank card', 2: 'Alipay', 3: 'WeChat', 4: 'PayPal', 5: 'FPS', 6: 'PayMe', 7: 'Faspay', 8: 'Line Pay', 9: 'Cash' } for i in range(len(payment_way_list)): assert my_offers_info[6 + i] == payment_method[ payment_way_list[i]], "数据库中支付方式:{},页面支付方式:{}".format( payment_way_list[i], my_offers_info[6 + i]) # 判断广告是否开启自动上下架 if my_offers_info[-2] == 'Off': # 判断广告交易时间 assert "{} minutes".format( otc_info[advert_position]['RESPONSE_MIN']) == str( my_offers_info[-5]), "未开启自动上架的交易时间:数据库{},页面{}".format( "{} minutes".format( otc_info[advert_position]['RESPONSE_MIN']), my_offers_info[-5]) self.log.info("交易数:数据库{},页面{}".format( otc_info[advert_position]['TRADE_SUCCESS_COUNT'], my_offers_info[-4])) self.log.info("交易数类型:数据库{},页面{}".format( type(otc_info[advert_position]['TRADE_SUCCESS_COUNT']), type(my_offers_info[-4]))) # 判断广告交易数 assert str( otc_info[advert_position]['TRADE_SUCCESS_COUNT'] ) == my_offers_info[-4], "交易数:数据库{},页面{}".format( otc_info[advert_position]['TRADE_SUCCESS_COUNT'], my_offers_info[-4]) else: # 判断广告交易时间 assert "{} minutes".format( otc_info[advert_position]['RESPONSE_MIN']) == str( my_offers_info[-6]), "自动上架的交易时间:数据库{},页面{}".format( "{} minutes".format( otc_info[advert_position]['RESPONSE_MIN']), my_offers_info[-6]) # 判断广告交易数 assert str( otc_info[advert_position]['TRADE_SUCCESS_COUNT'] ) == my_offers_info[-5], "交易数:数据库{},页面{}".format( otc_info[advert_position]['TRADE_SUCCESS_COUNT'], my_offers_info[-5]) # 判断广告是否开启自动上下架 if my_offers_info[-2] == 'Off': assert otc_info[advert_position][ 'AUTO_UP_OR_DOWN'] == 0, "数据库中广告自动上下架信息为:{}".format( otc_info[advert_position]['AUTO_UP_OR_DOWN']) # 判断广告是否上架 if otc_info[advert_position]['STATE'] == 10: assert my_offers_info[-3] == 'on', "页面广告上架信息为:{}".format( my_offers_info[-3]) elif otc_info[advert_position]['STATE'] == 20: assert my_offers_info[-3] == 'off', "页面广告上架信息为:{}".format( my_offers_info[-3]) else: assert otc_info[advert_position][ 'AUTO_UP_OR_DOWN'] == 1, "数据库中广告自动上下架信息为:{}".format( otc_info[advert_position]['AUTO_UP_OR_DOWN']) assert otc_info[advert_position][ 'JOB_UP_TIME'] in my_offers_info[ -3], "数据库中广告自动上架时间为:{}".format( otc_info[advert_position]['JOB_UP_TIME']) assert otc_info[advert_position][ 'JOB_DOWN_TIME'] in my_offers_info[ -2], "数据库中广告自动下架时间为:{}".format( otc_info[advert_position]['JOB_DOWN_TIME']) # 判断广告是否上架 if otc_info[advert_position]['STATE'] == 10: assert my_offers_info[-4] == 'on', "页面广告上架信息为:{}".format( my_offers_info[-4]) elif otc_info[advert_position]['STATE'] == 20: assert my_offers_info[-4] == 'off', "页面广告上架信息为:{}".format( my_offers_info[-4]) self.driver.refresh() time.sleep(5)
def test_default_info(self, data): """测试页面数据""" self.buy_crypto_driver.click(self.buy_crypto_driver.input_crypto) buy_crypto_elements = self.buy_crypto_driver.find_elements( self.buy_crypto_driver.li_crypto) # 设置广告方向和数字币种 BuyCryptoPage.side_crypto(data, buy_crypto_elements) # 设置法币币种 self.buy_crypto_driver.set_legal_currency(data, self.buy_crypto_driver) # 校验文案 if data['Type'] == 'Buy': assert self.buy_crypto_driver.find_element( self.buy_crypto_driver.h2_buy_crypto).text in ( "Use {} To Buy {}".format(data['Currency'], data['Crypto']), "使用 {} 購買 {}".format(data['Currency'], data['Crypto']), "使用 {} 购买 {}".format(data['Currency'], data['Crypto'])) elif data['Type'] == 'Sell': assert self.buy_crypto_driver.find_element( self.buy_crypto_driver.h2_buy_crypto).text in ( "Sell {} To Get {}".format(data['Crypto'], data['Currency']), "出售 {} 換取 {}".format(data['Crypto'], data['Currency']), "出售 {} 换取 {}".format(data['Crypto'], data['Currency'])) # 校验广告参数 tr_adverts_elements = self.buy_crypto_driver.find_elements( self.buy_crypto_driver.tr_adverts) get_adverts_info_sql = "" try: my_adverts_mysql = MysqlPool("mysql") if data['Type'] == 'Buy': get_adverts_info_sql = "select ID,MEMBER_ID,TITLE,PLATFORM_COIN,OFFLINE_COIN,EXCHANGE_MAX_VOLUMN,EXCHANGE_MIN_VOLUMN,BID_PRICE from otc.tb_otc_advert where side =2 and PLATFORM_COIN=%s and OFFLINE_COIN=%s and STATE=10 order by BID_PRICE;" elif data['Type'] == 'Sell': get_adverts_info_sql = "select ID,MEMBER_ID,TITLE,PLATFORM_COIN,OFFLINE_COIN,EXCHANGE_MAX_VOLUMN,EXCHANGE_MIN_VOLUMN,BID_PRICE from otc.tb_otc_advert where side =1 and PLATFORM_COIN=%s and OFFLINE_COIN=%s and STATE=10 order by BID_PRICE desc;" adverts_info_list = my_adverts_mysql.getAll( get_adverts_info_sql, (data['Crypto'], data['Currency'])) except Exception as e: self.log.info(e) finally: my_adverts_mysql.dispose() if len(tr_adverts_elements) > 1: for tr_adverts_element_position in range(1, len(tr_adverts_elements)): tr_web_adverts_info = tr_adverts_elements[ tr_adverts_element_position].text.split('\n') tr_sql_adverts_info = adverts_info_list[ tr_adverts_element_position - 1] self.log.info(tr_web_adverts_info) self.log.info(tr_sql_adverts_info) try: exchange_way_mysql = MysqlPool("mysql") get_exchange_way_sql = "select distinct (EXCHANGE_WAY) from otc.tb_otc_advert_payment_way where ADVERT_ID =%s order by EXCHANGE_WAY;" exchange_way_list = exchange_way_mysql.getAll( get_exchange_way_sql, (tr_sql_adverts_info['ID'], )) get_member_name_sql = "select member_name from member.tm_member where MEMBER_ID = %s;" member_name = exchange_way_mysql.getOne( get_member_name_sql, (tr_sql_adverts_info['MEMBER_ID'], )) self.log.info(exchange_way_list) self.log.info(member_name) self.buy_crypto_driver.check_data(member_name, exchange_way_list, tr_sql_adverts_info, tr_web_adverts_info) except Exception as e: self.log.info(e) finally: exchange_way_mysql.dispose() else: assert adverts_info_list == False