def superior_template(self, ip, payment_method, data, sheet_name, case_id, phone_1, phone_2=None): ''' :param payment_method: 支付方式 :param data: data :param sheet_name: 表单 :param case_id: 用例id :param phone_1: 手机号 易贝 易贝券 :param phone_2: 手机号 其余支付方式 需要考虑卖家/家人/企业 :return: 写回Excel的上级城市焕商/代理商id模板 ''' if payment_method in ["易贝", "易贝券"]: buyer_phone = eval(data)['buyer_phone'] buyer_regional_agent = SQL(ip).regional_agent( buyer_phone) # 查询买家上级 buyer_superior = Superior().superior(ip, buyer_regional_agent, phone_1) b = buyer_superior DoExcel.superior(test_case_path, sheet_name, case_id, str(b)) return b elif payment_method in ["抵工资", "家人购"]: buyer_phone = eval(data)['buyer_phone'] disanfang_phone = eval(data)['disanfang_phone'] buyer_regional_agent = SQL(ip).regional_agent( buyer_phone) # 查询买家上级 disanfang_regional_agent = SQL(ip).regional_agent( disanfang_phone) # 查询企业/家人上级 buyer_superior = Superior().superior(ip, buyer_regional_agent, phone_1) disanfang_superior = Superior().superior(ip, disanfang_regional_agent, phone_2) b = {"储备池分佣": buyer_superior, "支付服务费分佣": disanfang_superior} DoExcel.superior(test_case_path, sheet_name, case_id, str(b)) return b else: # 现金 buyer_phone = eval(data)['buyer_phone'] seller_phone = eval(data)['seller_phone'] buyer_regional_agent = SQL(ip).regional_agent( buyer_phone) # 查询买家上级 seller_regional_agent = SQL(ip).regional_agent( seller_phone) # 查询卖家上级 buyer_superior = Superior().superior(ip, buyer_regional_agent, phone_1) seller_superior = Superior().superior(ip, seller_regional_agent, phone_2) b = {"储备池分佣": buyer_superior, "支付服务费分佣": seller_superior} DoExcel.superior(test_case_path, sheet_name, case_id, str(b)) return b
def test_1_buy_goods(self, item): my_logger.info("----------开始执行用例{0},环境是{1}----------".format( item['case_id'], item['surroundings'])) ip = IP[item['surroundings']] data = eval(item['data']) buyer_phone = data['buyer_phone'] seller_phone = data['seller_phone'] # 获取绑定关系 superior = SuperiorTemplate().superior_template_main( ip, item['payment_method'], item['data'], buyer_phone) # 环境 surroundings = item['surroundings'] # Boss后台运营设置 operational_setting = eval(item['operational_setting']) print("----------开始BOSS后台设置运营分佣比例操作----------") # Boss后台设置运营分佣比例 BossSetting().main(ip, surroundings, item['payment_method'], superior, operational_setting) print("----------BOSS后台运营分佣比例设置完毕----------") buyer_identity = item['buyer_identity'] seller_identity = item['seller_identity'] # 支付密码 payPassword = get_js('runs', item['payPassword']) if buyer_identity == "公海用户": if seller_identity == "个人焕商" or seller_identity == "非焕商且已绑定个人焕商": # 充值 recharge_behavior(surroundings, buyer_phone, payPassword) # 写回储备池和充值金额 user_id = data["买家"] reserve_fund_data = reserve_fund_sql(ip, user_id) DoExcel.write_back_reserve_fund(test_case_path, item['sheet_name'], item['case_id'], str(reserve_fund_data)) if item['payment_method'] == "易贝": payType = 3 elif item['payment_method'] == "易贝券": payType = 4 elif item['payment_method'] == "家人购": payType = 5 elif item['payment_method'] == "抵工资": payType = 6 elif item['payment_method'] == "现金": payType = 7 # 暂不兼容现金支付,不兼容接口传参 # 根据商品名判断流程 if "实物商品" in item['goodsname']: order = bug_entity_goods(surroundings, buyer_phone, seller_phone, item['goodsname'], payType, payPassword) elif "本地生活" in item['goodsname']: order = buy_coupon_goods(surroundings, buyer_phone, seller_phone, item['goodsname'], payType, payPassword) elif "商企服务" in item['goodsname']: order = buy_server_goods(surroundings, buyer_phone, seller_phone, item['goodsname'], payType, payPassword) # 写回订单号 buyerid = data['买家'] DoExcel.get_order(test_case_path, item['sheet_name'], item['case_id'], order) # 获取绑定关系,写回Excel superior = SuperiorTemplate().superior_template_main( ip, item['payment_method'], item['data'], buyer_phone) DoExcel.superior(test_case_path, item['sheet_name'], item['case_id'], str(superior)) # 获取上级分佣比例,写回Excel proportion = SuperiorTemplate().fenyong_template_main( ip, item['payment_method'], superior) DoExcel.fenyong_bili(test_case_path, item['sheet_name'], item['case_id'], str(proportion)) # 解绑 if buyer_identity == "公海用户": if seller_identity == "个人焕商" or seller_identity == "非焕商且已绑定个人焕商": if seller_identity == "个人焕商": delete_partner(surroundings, seller_phone, buyerid) elif seller_identity == "非焕商且已绑定个人焕商": bangding_phone = data['bangding_phone'] delete_partner(surroundings, bangding_phone, buyerid) my_logger.info("----------前端操作执行完毕----------") ip = IP[item['surroundings']] buyer_id = data['买家'] # 查询买家是否绑定销售/业务焕商/TCO if item['payment_method'] in ["易贝", "易贝券"]: # 获取买家绑定的销售/业务焕商/TCO dict bind_buyer_relationship_data = BingRelationshipData( ).bing_relationship_data(ip, item['payment_method'], data, buyer_id) # 把买家上级销售/业务焕商的上级写回Excel DoExcel().bing_sale_id(test_case_path, item['sheet_name'], item['case_id'], str(bind_buyer_relationship_data)) elif item['payment_method'] in ["抵工资", "家人购", "现金"]: bind_relationship_data = BingRelationshipData( ).bing_relationship_data(ip, item['payment_method'], data, buyer_id) bind_buyer_relationship_data = bind_relationship_data[0] bind_payer_relationship_data = bind_relationship_data[1] # 买家上级销售/业务焕商的上级,写回模板 bind_buyer_relationship_id = { "储备金二级分佣对象": bind_buyer_relationship_data, "支付服务费二级分佣对象": bind_payer_relationship_data } DoExcel().bing_sale_id(test_case_path, item['sheet_name'], item['case_id'], str(bind_buyer_relationship_id)) # 获取这笔订单应该【使用】的二级分佣比例 transaction_second_payagent_ratio = TransactionSecondPayagentRatio( ).transaction_second_payagent_ratio(ip, item['payment_method'], superior, data) # 把这笔订单所使用的二级分佣比例写回Excel DoExcel().second_payagent_ratio(test_case_path, item['sheet_name'], item['case_id'], str(transaction_second_payagent_ratio)) my_logger.info("----------开始进行对比----------") ip = IP[item['surroundings']] buyer_identity = item['buyer_identity'] seller_identity = item['seller_identity'] data = eval(item['data']) # reserve_fund_data = eval(item['reserve_fund']) # proportion = eval(item['proportion']) # order = item['order'] # superior = eval(item['superior']) # 这笔订单应该【使用】的二级分佣比例 # transaction_second_payagent_ratio = eval(item['second_payagent_ratio']) # bind_relationship_data = eval(item['bind_relationship_data']) try: if buyer_identity == "公海用户": if seller_identity == "个人焕商" or seller_identity == "非焕商且已绑定个人焕商": charge_amount = reserve_fund_data['charge_amount'] reserve_fund = reserve_fund_data['reserve_fund'] else: charge_amount = None reserve_fund = None else: charge_amount = None reserve_fund = None calculation_data = CalculationData().calculation_data( ip, item['payment_method'], item['member_level'], buyer_identity, seller_identity, proportion, charge_amount, reserve_fund, order) if item['payment_method'] in ["易贝", "易贝券"]: bind_buyer_relationship_data = bind_buyer_relationship_data expected_moban = MoBan(buyer_identity, seller_identity, item['member_level'], item['payment_method'], order).expected_moban( ip, data, superior, reserve_fund, calculation_data, transaction_second_payagent_ratio, bind_buyer_relationship_data) elif item['payment_method'] in ["抵工资", "家人购", "现金"]: bind_buyer_relationship_data = bind_buyer_relationship_id[ '储备金二级分佣对象'] bind_payer_relationship_data = bind_buyer_relationship_id[ '支付服务费二级分佣对象'] expected_moban = MoBan(buyer_identity, seller_identity, item['member_level'], item['payment_method'], order).expected_moban( ip, data, superior, reserve_fund, calculation_data, transaction_second_payagent_ratio, bind_buyer_relationship_data, bind_payer_relationship_data) # 写回Excel用 fanhui = fan_hui(ip, order, expected_moban) sql_data = wallet_detail(ip, order) for i in range(0, len(expected_moban)): self.assertEqual(expected_moban[i], sql_data[i]) self.assertEqual(expected_moban, sql_data) my_logger.info("用例{0}正确!{1}".format(item['case_id'], item['title'])) TestResult = 'Pass' Error = None except AssertionError as e: my_logger.info("用例错误!错误原因是第{0}行,{1}:".format(i + 1, e)) TestResult = 'Failed' Error = "用例错误!错误原因是:第{0}行,{1}:".format(i + 1, e) raise e # 异常处理完后记得抛出 finally: # 不管怎样都得写入Excel DoExcel().write_back(test_case_path, item['sheet_name'], item['case_id'] + 1, str(fanhui[0]), str(fanhui[2]), str(expected_moban), str(sql_data), TestResult, str(Error)) # time.sleep(2) my_logger.info("----------对比结束----------") my_logger.info("----------用例{0}执行完毕----------".format(item['case_id']))
def test_1_buy_goods(self, item): my_logger.info("----------开始执行用例{0},环境是{1}----------".format( item['case_id'], item['surroundings'])) ip = IP[item['surroundings']] H5_Login_url = url(item['surroundings'])[0] H5_home_url = url(item['surroundings'])[1] buyer_phone = eval(item['data'])['buyer_phone'] seller_phone = eval(item['data'])['seller_phone'] # 获取绑定关系 superior = SuperiorTemplate().superior_template_main( ip, item['payment_method'], item['data'], buyer_phone) Boss_login_url = url(item['surroundings'])[2] operational_setting = eval(item['operational_setting']) print("----------开始BOSS后台设置运营分佣比例操作----------") self.driver.get(Boss_login_url) #Boss后台设置运营分佣比例 BossSetting(self.driver).main(ip, item['payment_method'], superior, operational_setting) print("----------BOSS后台运营分佣比例设置完毕----------") self.driver.quit() mobile_emulation = {'deviceName': 'iPhone X'} chrome_options = webdriver.ChromeOptions() chrome_options.add_experimental_option("mobileEmulation", mobile_emulation) driver = webdriver.Chrome(options=chrome_options) driver.get(H5_Login_url) self.lg = H5_LoginPage(driver) self.lg.login(buyer_phone) #定位 time.sleep(5) Location().location(driver) buyer_identity = item['buyer_identity'] seller_identity = item['seller_identity'] if buyer_identity == "公海用户": if seller_identity == "个人焕商" or seller_identity == "非焕商且已绑定个人焕商": driver.find_element(*MyIndex.myIndex).click() time.sleep(6) # # 充值 Recharge().recharge(driver) time.sleep(2) # 支付按键 BuyGoods(driver).pay() time.sleep(2) # 写回储备池和充值金额 user_id = eval(item['data'])["买家"] reserve_fund_data = SQL(ip).reserve_fund_data(user_id) DoExcel.reserve_fund(test_case_path, item['sheet_name'], item['case_id'], str(reserve_fund_data)) # time.sleep(5) driver.get(H5_home_url) time.sleep(2) # 选择商品 Seach_Goods().seach_goods(driver, item['goodsname']) # 购买流程 BuyGoods(driver).BuyGood(item['payment_method']) time.sleep(3) # 卖家操作 driver.get(H5_Login_url) lg = H5_LoginPage(driver) lg.login(seller_phone) time.sleep(2) driver.get(H5_home_url) time.sleep(2) driver.find_element(*MyIndex.myIndex).click() time.sleep(2) # 滚动至元素【销售订单】可见,点击 ActionChains(driver).move_to_element( driver.find_element(*MyIndex.saleOrderList)).perform() driver.execute_script('window.scrollBy(0,500)') time.sleep(2) driver.find_element(*MyIndex.saleOrderList).click() time.sleep(5) # 确认订单 WebDriverWait(driver, 10).until( EC.visibility_of_element_located((MyIndex.confirm_Order))).click() time.sleep(6) # 根据商品名判断流程 if "实物商品" in item['goodsname']: ReceiptDelivery(driver).real_goods(H5_Login_url, buyer_phone) elif "本地服务" in item['goodsname']: ReceiptDelivery(driver).local_life(H5_Login_url, H5_home_url, buyer_phone, seller_phone) elif "商企服务" in item['goodsname']: ReceiptDelivery(driver).local_life(H5_Login_url, H5_home_url, buyer_phone, seller_phone) # 写回订单号 buyerid = eval(item['data'])['买家'] order = DoExcel.get_order(ip, test_case_path, item['sheet_name'], item['case_id'], buyerid) # 获取绑定关系,写回Excel superior = SuperiorTemplate().superior_template_main( ip, item['payment_method'], item['data'], buyer_phone) DoExcel.superior(test_case_path, item['sheet_name'], item['case_id'], str(superior)) # 获取上级分佣比例,写回Excel proportion = SuperiorTemplate().fenyong_template_main( ip, item['payment_method'], superior) DoExcel.fenyong_bili(test_case_path, item['sheet_name'], item['case_id'], str(proportion)) if buyer_identity == "公海用户": if seller_identity == "个人焕商" or seller_identity == "非焕商且已绑定个人焕商": # 跳回卖家,解除伙伴绑定 driver.get(H5_Login_url) lg = H5_LoginPage(driver) if seller_identity == "个人焕商": lg.login(seller_phone) elif seller_identity == "非焕商且已绑定个人焕商": bangding_phone = eval(item['data'])['bangding_phone'] lg.login(bangding_phone) time.sleep(2) driver.get(H5_home_url) time.sleep(2) driver.find_element(*MyIndex.myIndex).click() time.sleep(2) driver.find_element(*MyIndex.myPartner).click() time.sleep(3) # 解绑 UntiePartner().untie_partner(driver, item['surroundings']) my_logger.info("----------前端操作执行完毕----------") ip = IP[item['surroundings']] data = eval(item['data']) buyer_id = data['买家'] # 查询买家是否绑定销售/业务焕商/TCO if item['payment_method'] in ["易贝", "易贝券"]: # 获取买家绑定的销售/业务焕商/TCO dict bind_buyer_relationship_data = BingRelationshipData( ).bing_relationship_data(ip, item['payment_method'], data, buyer_id) # 把买家上级销售/业务焕商的上级写回Excel DoExcel().bing_sale_id(test_case_path, item['sheet_name'], item['case_id'], str(bind_buyer_relationship_data)) elif item['payment_method'] in ["抵工资", "家人购", "现金"]: bind_relationship_data = BingRelationshipData( ).bing_relationship_data(ip, item['payment_method'], data, buyer_id) bind_buyer_relationship_data = bind_relationship_data[0] bind_payer_relationship_data = bind_relationship_data[1] # 买家上级销售/业务焕商的上级,写回模板 bind_buyer_relationship_id = { "储备金二级分佣对象": bind_buyer_relationship_data, "支付服务费二级分佣对象": bind_payer_relationship_data } DoExcel().bing_sale_id(test_case_path, item['sheet_name'], item['case_id'], str(bind_buyer_relationship_id)) # 获取这笔订单应该【使用】的二级分佣比例 transaction_second_payagent_ratio = TransactionSecondPayagentRatio( ).transaction_second_payagent_ratio(ip, item['payment_method'], superior, data) # 把这笔订单所使用的二级分佣比例写回Excel DoExcel().second_payagent_ratio(test_case_path, item['sheet_name'], item['case_id'], str(transaction_second_payagent_ratio)) driver.quit() my_logger.info("----------开始进行对比----------") try: ip = IP[item['surroundings']] if buyer_identity == "公海用户": if seller_identity == "个人焕商" or seller_identity == "非焕商且已绑定个人焕商": charge_amount = reserve_fund_data['charge_amount'] reserve_fund = reserve_fund_data['reserve_fund'] else: charge_amount = None reserve_fund = None else: charge_amount = None reserve_fund = None calculation_data = CalculationData().calculation_data( ip, item['payment_method'], item['member_level'], buyer_identity, seller_identity, proportion, charge_amount, reserve_fund, order) if item['payment_method'] in ["易贝", "易贝券"]: expected_moban = MoBan(buyer_identity, seller_identity, item['member_level'], item['payment_method'], order).expected_moban( ip, data, superior, reserve_fund, calculation_data, transaction_second_payagent_ratio, bind_buyer_relationship_data) elif item['payment_method'] in ["抵工资", "家人购", "现金"]: expected_moban = MoBan(buyer_identity, seller_identity, item['member_level'], item['payment_method'], order).expected_moban( ip, data, superior, reserve_fund, calculation_data, transaction_second_payagent_ratio, bind_buyer_relationship_data, bind_payer_relationship_data) # 写回Excel用 fanhui = FanHui().fan_hui(ip, order, expected_moban) sql_data = SQL(ip).wallet_detail(order) for i in range(0, len(expected_moban)): self.assertEqual(expected_moban[i], sql_data[i]) self.assertEqual(expected_moban, sql_data) my_logger.info("用例{0}正确!{1}".format(item['case_id'], item['title'])) TestResult = 'Pass' Error = None except AssertionError as e: my_logger.info("用例错误!错误原因是第{0}行,{1}:".format(i + 1, e)) TestResult = 'Failed' Error = "用例错误!错误原因是:第{0}行,{1}:".format(i + 1, e) raise e # 异常处理完后记得抛出 finally: # 不管怎样都得写入Excel DoExcel().write_back(test_case_path, item['sheet_name'], item['case_id'] + 1, str(fanhui[0]), str(fanhui[2]), str(expected_moban), str(sql_data), TestResult, str(Error)) # time.sleep(2) my_logger.info("----------对比结束----------") my_logger.info("----------用例{0}执行完毕----------".format(item['case_id']))