Ejemplo n.º 1
0
    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']))
Ejemplo n.º 2
0
    def test_1_buy_goods(self, item):

        global disanfang_province_id, disanfang_city_id, disanfang_area_id, disanfang_personal_id, i, TestResult, Error, reserve_fund, expected_userid, fanhui, expected_changes, expected, sql_data

        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]

        self.driver.get(H5_Login_url)
        self.lg = LoginPage(self.driver)

        buyer_phone = eval(item['data'])['buyer_phone']
        seller_phone = eval(item['data'])['seller_phone']
        self.lg.login(buyer_phone)
        time.sleep(3)

        buyer_identity = item['buyer_identity']
        seller_identity = item['seller_identity']

        if buyer_identity == "公海用户":
            if seller_identity == "个人焕商" or seller_identity == "非焕商且已绑定个人焕商":
                self.driver.find_element(*MyIndex.myIndex).click()
                time.sleep(5)

                # 充值
                WebDriverWait(self.driver, 10).until(
                    EC.visibility_of_element_located(
                        (MyIndex.serviceRecharge))).click()
                time.sleep(3)
                self.driver.find_element(*MyIndex.recharge_amount).click()
                time.sleep(2)
                self.driver.find_element(*MyIndex.input_amount).send_keys(100)
                time.sleep(2)
                self.driver.find_element(*MyIndex.queren).click()
                time.sleep(4)
                WebDriverWait(self.driver, 10).until(
                    EC.visibility_of_element_located(
                        (MyIndex.rechare_now))).click()
                time.sleep(3)
                WebDriverWait(self.driver, 10).until(
                    EC.visibility_of_element_located(
                        (MyIndex.querenzhifu))).click()
                time.sleep(2)

                # 支付按键
                BuyGoods(self.driver).pay()
                time.sleep(2)

                # 写回储备池和充值金额
                user_id = eval(item['data'])["买家"]
                reserve_fund = SQL(ip).reserve_fund(user_id)
                DoExcel.reserve_fund(test_case_path, item['sheet_name'],
                                     item['case_id'], str(reserve_fund))
                # time.sleep(5)

                self.driver.get(H5_home_url)
                time.sleep(2)

        # 选择商品
        self.driver.find_element(*Home.search).click()
        time.sleep(3)
        WebDriverWait(self.driver,
                      10).until(EC.visibility_of_element_located(
                          (Home.input))).send_keys(item['goodsname'])
        time.sleep(2)
        self.driver.find_element(*Home.input).send_keys(Keys.ENTER)
        time.sleep(3)
        # 点击【商品】
        self.driver.find_element(*Home.real_goods).click()
        time.sleep(3)

        # 购买流程
        BuyGoods(self.driver).BuyGood(item['payment_method'])
        time.sleep(3)
        BuyGoods(self.driver).pay()
        time.sleep(2)

        # 卖家操作
        self.driver.get(H5_Login_url)
        lg = LoginPage(self.driver)
        lg.login(seller_phone)
        time.sleep(2)
        self.driver.get(H5_home_url)
        time.sleep(2)
        self.driver.find_element(*MyIndex.myIndex).click()
        time.sleep(2)
        # 滚动至元素【销售订单】可见,点击
        ActionChains(self.driver).move_to_element(
            self.driver.find_element(*MyIndex.saleOrderList)).perform()
        self.driver.execute_script('window.scrollBy(0,500)')
        time.sleep(2)
        self.driver.find_element(*MyIndex.saleOrderList).click()
        time.sleep(5)
        # 确认订单
        WebDriverWait(self.driver, 10).until(
            EC.visibility_of_element_located((MyIndex.confirm_Order))).click()
        time.sleep(6)

        # 根据商品名判断流程
        if item['goodsname'].find('实物商品') != -1:  # 商品名字包含实物商品
            # 发货
            self.driver.find_element(*MyIndex.ship).click()
            time.sleep(2)
            self.driver.find_element(*MyIndex.logistics_company).click()
            time.sleep(3)
            WebDriverWait(self.driver, 10).until(
                EC.visibility_of_element_located((MyIndex.debang))).click()
            time.sleep(2)
            self.driver.find_element(
                *MyIndex.dingdanhao).send_keys("lalalalala")
            time.sleep(2)
            self.driver.find_element(*MyIndex.ship_now).click()
            time.sleep(2)

            # 买家
            self.driver.get(H5_Login_url)
            lg = LoginPage(self.driver)
            lg.login(buyer_phone)
            time.sleep(2)
            # 点击【采购订单】
            self.driver.find_element(*MyIndex.purchase).click()
            time.sleep(4)
            # 收货
            WebDriverWait(self.driver, 10).until(
                EC.visibility_of_element_located((MyIndex.receipt))).click()
            time.sleep(3)

            # 支付按键
            BuyGoods(self.driver).pay()
            time.sleep(2)

        elif item['goodsname'].find('本地生活') != -1:
            # 本地生活
            self.driver.get(H5_Login_url)
            lg = LoginPage(self.driver)
            lg.login(buyer_phone)
            time.sleep(2)
            self.driver.get(H5_home_url)
            time.sleep(2)
            self.driver.find_element(*MyIndex.myIndex).click()
            time.sleep(2)
            # 点击【采购订单】
            self.driver.find_element(*MyIndex.purchase).click()
            time.sleep(4)
            # 点击第一个订单
            self.driver.find_element(*BG.frist_order).click()
            time.sleep(2)
            xuliehao = ReturnTxt(self.driver).xuliehao_txt()
            # print(xuliehao)

            time.sleep(2)

            # 卖家
            self.driver.get(H5_Login_url)
            lg = LoginPage(self.driver)
            lg.login(seller_phone)
            time.sleep(2)
            self.driver.get(H5_home_url)
            time.sleep(2)
            self.driver.find_element(*MyIndex.myIndex).click()
            time.sleep(2)
            # 滚动至元素【销售订单】可见,点击
            ActionChains(self.driver).move_to_element(
                self.driver.find_element(*MyIndex.saleOrderList)).perform()
            self.driver.execute_script('window.scrollBy(0,500)')
            time.sleep(2)
            self.driver.find_element(*MyIndex.saleOrderList).click()
            time.sleep(5)
            # 点击第一个订单
            self.driver.find_element(*BG.frist_order).click()
            time.sleep(2)
            # 输入序列号
            self.driver.find_element(*BG.click_xuliehao).send_keys(xuliehao)
            # 点击确定
            self.driver.find_element(*BG.click_queding).click()
            time.sleep(1)
            self.driver.find_element(*BG.click_queding2).click()
            time.sleep(2)

        elif item['goodsname'].find('商企服务') != -1:
            # 买家
            self.driver.get(H5_Login_url)
            lg = LoginPage(self.driver)
            lg.login(buyer_phone)
            time.sleep(2)
            # 点击【采购订单】
            self.driver.find_element(*MyIndex.purchase).click()
            time.sleep(4)

            # 确认签约
            self.driver.find_element(*BG.qianyue).click()

            # 支付按键
            BuyGoods(self.driver).pay()
            time.sleep(2)

        # 写回订单号
        buyerid = eval(item['data'])['买家']
        order = DoExcel.get_order(ip, test_case_path, item['sheet_name'],
                                  item['case_id'], int(buyerid))
        # time.sleep(5)

        # 获取绑定关系,写回Excel
        if item['payment_method'] in ["易贝", "易贝券"]:
            superior = SuperiorTemplate().superior_template(
                ip, item['payment_method'], item['data'], item['sheet_name'],
                item['case_id'], buyer_phone)

        elif item['payment_method'] in ["抵工资", "家人购"]:
            disanfang_phone = eval(item['data'])['disanfang_phone']
            superior = SuperiorTemplate().superior_template(
                ip, item['payment_method'], item['data'], item['sheet_name'],
                item['case_id'], buyer_phone, disanfang_phone)

        else:
            seller_phone = eval(item['data'])['seller_phone']
            superior = SuperiorTemplate().superior_template(
                ip, item['payment_method'], item['data'], item['sheet_name'],
                item['case_id'], buyer_phone, seller_phone)

        # time.sleep(5)
        # print('shangji',shangji)

        if item['payment_method'] in ["易贝", "易贝券"]:
            buyer_province_id = superior[1]['省代理商']
            buyer_city_id = superior[1]['市代理商']
            buyer_area_id = superior[1]['区代理商']
            buyer_personal_id = superior[0]['个人焕商']
        else:
            buyer_province_id = superior['储备池分佣'][1]['省代理商']
            buyer_city_id = superior['储备池分佣'][1]['市代理商']
            buyer_area_id = superior['储备池分佣'][1]['区代理商']
            buyer_personal_id = superior['储备池分佣'][0]['个人焕商']

            disanfang_province_id = superior['支付服务费分佣'][1]['省代理商']
            disanfang_city_id = superior['支付服务费分佣'][1]['市代理商']
            disanfang_area_id = superior['支付服务费分佣'][1]['区代理商']
            disanfang_personal_id = superior['支付服务费分佣'][0]['个人焕商']

        # print(buyer_province_id,buyer_city_id,buyer_area_id,buyer_personal_id)
        # 获取上级分佣比例,写回Excel
        if item['payment_method'] in ["易贝", "易贝券"]:
            proportion = SuperiorTemplate().fenyong_template(
                ip, item['payment_method'], item['sheet_name'],
                item['case_id'], buyer_province_id, buyer_city_id,
                buyer_area_id, buyer_personal_id)

        elif item['payment_method'] in ["抵工资", "家人购"]:
            proportion = SuperiorTemplate().fenyong_template(
                ip, item['payment_method'], item['sheet_name'],
                item['case_id'], buyer_province_id, buyer_city_id,
                buyer_area_id, buyer_personal_id, disanfang_province_id,
                disanfang_city_id, disanfang_area_id, disanfang_personal_id)

        else:
            proportion = SuperiorTemplate().fenyong_template(
                ip, item['payment_method'], item['sheet_name'],
                item['case_id'], buyer_province_id, buyer_city_id,
                buyer_area_id, buyer_personal_id, disanfang_province_id,
                disanfang_city_id, disanfang_area_id, disanfang_personal_id)

        # time.sleep(5)

        if buyer_identity == "公海用户":
            if seller_identity == "个人焕商" or seller_identity == "非焕商且已绑定个人焕商":
                # 跳回卖家,解除伙伴绑定
                self.driver.get(H5_Login_url)
                lg = LoginPage(self.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)
                self.driver.get(H5_home_url)
                time.sleep(2)
                self.driver.find_element(*MyIndex.myIndex).click()
                time.sleep(2)
                self.driver.find_element(*MyIndex.myPartner).click()
                time.sleep(3)
                if item['surroundings'] == "test":
                    self.driver.find_element(*MyIndex.delete1).click()
                elif item['surroundings'] == "mtest":
                    self.driver.find_element(*MyIndex.delete2).click()
                elif item['surroundings'] == "dev1":
                    self.driver.find_element(*MyIndex.delete3).click()
                time.sleep(2)
                self.driver.find_element(*MyIndex.queren).click()
                time.sleep(5)

        my_logger.info("----------用例{0}执行完毕----------".format(item['case_id']))
        my_logger.info("----------开始进行对比----------")

        try:
            ip = IP[item['surroundings']]

            if item['payment_method'] in ["易贝", "易贝券"]:
                buyer_province_proportion = proportion['省分佣比例']
                buyer_city_proportion = proportion['市分佣比例']
                buyer_area_proportion = proportion['区分佣比例']
                buyer_personal_proportion = proportion['个人分佣比例']
                disanfang_province_proportion = None
                disanfang_city_proportion = None
                disanfang_area_proportion = None
                disanfang_personal_proportion = None
            else:
                buyer_province_proportion = proportion['储备池分佣']['省分佣比例']
                buyer_city_proportion = proportion['储备池分佣']['市分佣比例']
                buyer_area_proportion = proportion['储备池分佣']['区分佣比例']
                buyer_personal_proportion = proportion['储备池分佣']['个人分佣比例']

                disanfang_province_proportion = proportion['支付服务费分佣']['省分佣比例']
                disanfang_city_proportion = proportion['支付服务费分佣']['市分佣比例']
                disanfang_area_proportion = proportion['支付服务费分佣']['区分佣比例']
                disanfang_personal_proportion = proportion['支付服务费分佣']['个人分佣比例']

            if item['buyer_identity'] == "公海用户":
                if item['seller_identity'] == "个人焕商" or item[
                        'seller_identity'] == "非焕商且已绑定个人焕商":
                    charge_amount = reserve_fund['charge_amount']
                    reserve_fund = reserve_fund['reserve_fund']
                else:
                    charge_amount = None
                    reserve_fund = None
            else:
                charge_amount = None
                reserve_fund = None

            # 预期分佣的用户id流水
            expected_userid = GeShiHua(item['buyer_identity'],
                                       item['seller_identity'],
                                       item['member_level'],
                                       item['payment_method'],
                                       order).userid(eval(item['data']),
                                                     superior)
            # print("expected_userid", expected_userid)

            # 计算出来的(商品价格,需要支付的易贝服务费,需要支付的现金服务费)(储备池分佣)(服务费分佣)
            calculation = A(
                item['buyer_identity'],
                item['seller_identity'],
                buyer_province_proportion=buyer_province_proportion,
                buyer_city_proportion=buyer_city_proportion,
                buyer_area_proportion=buyer_area_proportion,
                buyer_personal_proportion=buyer_personal_proportion,
                disanfang_province_proportion=disanfang_province_proportion,
                disanfang_city_proportion=disanfang_city_proportion,
                disanfang_area_proportion=disanfang_area_proportion,
                disanfang_personal_proportion=disanfang_personal_proportion,
            ).transaction(ip, item['member_level'], item['payment_method'],
                          order, charge_amount, reserve_fund)

            # print("calculation", calculation)

            # 预期的变化金额值流水
            expected_changes = GeShiHua(
                item['buyer_identity'], item['seller_identity'],
                item['member_level'], item['payment_method'],
                order).expected_changes(ip,
                                        calculation,
                                        reserve_fund=reserve_fund)
            # print('expected_changes', expected_changes)

            # 预期的流水
            expected = GeShiHua(item['buyer_identity'],
                                item['seller_identity'], item['member_level'],
                                item['payment_method'],
                                order).expected(ip,
                                                calculation,
                                                eval(item['data']),
                                                superior,
                                                reserve_fund=reserve_fund)
            # print("expected", expected)

            # 写回Excel用
            fanhui = GeShiHua(item['buyer_identity'], item['seller_identity'],
                              item['member_level'], item['payment_method'],
                              order).fanhui(ip, superior)

            sql_data = SQL(ip).wallet_detail(order)

            shuju = Title(item['buyer_identity'], item['seller_identity'],
                          item['payment_method']).title(superior)

            for i in range(0, len(shuju)):
                self.assertEqual(expected[i], sql_data[i])

            self.assertEqual(expected, 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(expected_userid), str(fanhui[0]),
                                 str(expected_changes), str(fanhui[2]),
                                 str(expected), str(sql_data), TestResult,
                                 str(Error))

        # time.sleep(2)
        my_logger.info("----------对比结束----------")
Ejemplo n.º 3
0
    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']))