Ejemplo n.º 1
0
class Action(object):
    def __init__(self, driver):
        self.gate = Gateway()
        self.driver = driver

    def moto(self, test_data=None):
        """
        预授权
        :param test_data: 测试数据 type: dict
        """
        if test_data is None:
            test_data = {}
        test_pay = Sub.SubmitPage(self.driver)
        log.info("----- 页面标题: %s -----" % self.driver.title)
        addr = self.gate.read_val("gateway", "proj_domain") + self.gate.read_val("addr", "moto")
        test_data.update({"提交地址": addr})
        for item in test_data:
            tag_name = test_pay.update_info(item, test_data[item])
            if tag_name is not None:
                if tag_name.lower() == "select":
                    log.info("选择{}".format(item))
                elif tag_name.lower() == "input":
                    log.info("输入{}".format(item))
        log.info("点击 make payment")
        test_pay.click_submit("make payemnt")
Ejemplo n.º 2
0
class Action(object):
    def __init__(self, driver):
        self.gate = Gateway()
        self.driver = driver

    def auth(self, test_data, pay_id, order_num):
        """
        预授权
        :param test_data: 测试数据 type: dict
        :param pay_id: 支付ID type: str
        :param order_num: 商户订单 type: str
        """
        if test_data is None:
            test_data = {}
        test_pay = Sub.SubmitPage(self.driver)
        log.info("----- 页面标题: %s -----" % self.driver.title)
        addr = self.gate.read_val("gateway", "proj_domain") + self.gate.read_val("addr", "auth")
        test_data.update({"提交地址": addr, "支付ID": pay_id, "商户订单": order_num})
        for item in test_data:
            tag_name = test_pay.update_info(item, test_data[item])
            if tag_name is not None:
                if tag_name.lower() == "select":
                    log.info("选择{}".format(item))
                elif tag_name.lower() == "input":
                    log.info("输入{}".format(item))
        log.info("点击确定")
        test_pay.click_submit("确定")
Ejemplo n.º 3
0
class Action(object):
    def __init__(self, driver):
        self.gate = Gateway()
        self.driver = driver

    def put_create(self, test_data=None):
        """
        quick 2方支付, 创建订单
        :meth test_data: 测试数据 type: dict
        :meth quickid: quickpay_id type: str
        :return:
        """
        if test_data is None:
            test_data = {}
        test_pay = Sub.SubmitPage(self.driver)
        log.info("----- 页面标题: %s -----" % self.driver.title)
        addr = self.gate.read_val(
            "gateway", "proj_domain") + self.gate.read_val("addr", "twocre")
        test_data.update({"提交地址": addr, "接口类型": "create", "quickpay_id": ""})
        for item in test_data:
            tag_name = test_pay.update_info(item, test_data[item])
            if tag_name is not None:
                if tag_name.lower() == "select":
                    log.info("选择{}".format(item))
                elif tag_name.lower() == "input":
                    log.info("输入{}".format(item))
        log.info("点击 make payment")
        test_pay.click_submit("make payemnt")

    def put_pay(self, test_data, quick_id):
        """
        quick 2方支付, 支付订单
        :meth test_data: 测试数据 type: dict
        :meth quickid: quickpay_id type: str
        :return:
        """
        test_pay = Sub.SubmitPage(self.driver)
        log.info("----- 页面标题: %s -----" % self.driver.title)
        addr = self.gate.read_val(
            "gateway", "proj_domain") + self.gate.read_val("addr", "twopay")
        test_data.update({
            "提交地址": addr,
            "接口类型": "pay",
            "quickpay_id": quick_id
        })
        for item in test_data:
            tag_name = test_pay.update_info(item, test_data[item])
            if tag_name is not None:
                if tag_name.lower() == "select":
                    log.info("选择{}".format(item))
                elif tag_name.lower() == "input":
                    log.info("输入{}".format(item))
        log.info("点击 make payment")
        test_pay.click_submit("make payemnt")
class TestGateway(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        # 浏览器驱动
        cls.driver = get_driver()
        log.info("----- 启动浏览器 -----")
        # 浏览器最大化
        cls.driver.maximize_window()
        # 获取支付域名列表数据
        cls.payval = Gateway().read_domain("domain")

    @classmethod
    def tearDownClass(cls):
        log.info("----- 关闭浏览器 -----")
        cls.driver.quit()

    def setUp(self):
        pass

    def tearDown(self):
        pass

    @ddt.data(*Exc(Gateway().read_data("channel"), "ThreePay").read_merged())
    def test_threepay(self, test_data):
        # 进入 3方信用卡
        Home(self.driver).enter_postpage("3方信用卡")
        # 提交 3方支付
        Tp.Action(self.driver).put_three(test_data["ThreePay"],
                                         test_data["PayDomain"], self.payval)
        # 断言:3方信用卡交易成功
        res_dict = test_data["TestResult"]
        for key_val in res_dict:
            self.assertEqual(res_dict[key_val],
                             Res.Result(self.driver).back_val(key_val))
 def setUpClass(cls):
     # 浏览器驱动
     cls.driver = get_driver()
     log.info("----- 启动浏览器 -----")
     # 浏览器最大化
     cls.driver.maximize_window()
     # 获取支付域名列表数据
     cls.payval = Gateway().read_domain("domain")
Ejemplo n.º 6
0
class Action(object):
    def __init__(self, driver):
        self.gate = Gateway()
        self.driver = driver

    def create_trade(self, test_data1=None):
        """
        提交 3方支付
        :meth test_data1: 测试数据, 交易信息 type: dict
        :return:
        """
        if test_data1 is None:
            test_data1 = {}
        test_pay = Sub.SubmitPage(self.driver)
        log.info("----- 页面标题: %s -----" % self.driver.title)
        addr = self.gate.read_val("gateway", "proj_domain") + self.gate.read_val("addr", "thr")
        test_data1.update({"提交地址": addr})
        for item in test_data1:
            tag_name = test_pay.update_info(item, test_data1[item])
            if tag_name is not None:
                if tag_name.lower() == "select":
                    log.info("选择{}: {}".format(item, test_data1[item]))
                elif tag_name.lower() == "input":
                    log.info("输入{}: {}".format(item, test_data1[item]))
        log.info("点击 make payment")
        test_pay.click_submit("make payemnt")

    def pay_trade(self, test_data2, url_val, payval=None):
        """
        根据订单链接进行交易
        :meth test_data2: 测试数据, 信用卡信息 type: dict
        :meth url_val: 订单链接 type: str
        :meth payval: 支付域名列表 type: list
        :return:
        """
        if test_data2 is None:
            test_data2 = {}
        Hg.HomePage(self.driver).open(url_val, "Credit Card Payment")
        # 信用卡支付
        domain = re.findall(r"/\w+/\w+\.", self.driver.current_url)[0].replace(".", "")
        for val in payval:
            for domain_conf in val[1].split(","):
                if domain == domain_conf.strip():
                    getattr(Pa.PayAction(self.driver), val[0])(test_data2)
                    break
class TestGateway(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        # 浏览器驱动
        cls.driver = get_driver()
        log.info("----- 启动浏览器 -----")
        # 浏览器最大化
        cls.driver.maximize_window()
        # 获取支付域名列表数据
        cls.payval = Gateway().read_domain("domain")

    @classmethod
    def tearDownClass(cls):
        log.info("----- 关闭浏览器 -----")
        cls.driver.quit()

    def setUp(self):
        pass

    def tearDown(self):
        pass

    @ddt.data(*Exc(Gateway().read_data("channel"), "Auth").read_merged())
    def test_auth(self, test_data):
        # 进入 3方信用卡
        Home(self.driver).enter_postpage("3方信用卡")
        # 提交 3方支付
        Tp.Action(self.driver).put_three(test_data["ThreePay"],
                                         test_data["PayDomain"], self.payval)
        # 获取订单号
        num = Res.Result(self.driver).back_val("order_number")
        # 获取支付 ID
        pay_id = Res.Result(self.driver).back_val("payment_id")
        # 断言:交易状态
        res_dict = test_data["PayResult"]
        for key_val in res_dict:
            self.assertEqual(res_dict[key_val],
                             Res.Result(self.driver).back_val(key_val),
                             "交易状态错误")
        # 进入预授权
        Home(self.driver).enter_postpage("预授权")
        auth.Action(self.driver).auth(test_data["Auth"], pay_id, num)
        # 断言:预授权成功
        res_dict = test_data["AuthResult"]
        for key_val in res_dict:
            self.assertEqual(res_dict[key_val],
                             Res.Result(self.driver).back_tag_val(key_val),
                             "预授权操作失败")
Ejemplo n.º 8
0
 def __init__(self, driver):
     url = Gateway().read_link()
     self.driver = driver
     log.info("登录支付网关-首页")
     self.home_obj = Hp.HomePage(self.driver)
     self.home_obj.open(url, "支付平台测试")
Ejemplo n.º 9
0
 def __init__(self, driver):
     self.gate = Gateway()
     self.driver = driver
Ejemplo n.º 10
0
class Action(object):
    def __init__(self, driver):
        self.gate = Gateway()
        self.driver = driver

    def put_create(self, test_data1=None, test_data2=None, payval=None):
        """
        quick 3方支付, 创建订单
        :meth test_data1: 测试数据, 交易信息 type: dict
        :meth test_data2: 测试数据, 支付信息 type: dict
        :meth payval: 支付域名列表 type: list
        :return:
        """
        if test_data1 is None:
            test_data1 = {}
        elif test_data2 is None:
            test_data2 = {}
        test_pay = Sub.SubmitPage(self.driver)
        log.info("----- quick 3方支付, 创建订单 -----")
        log.info("----- 页面标题: %s -----" % self.driver.title)
        addr = self.gate.read_val(
            "gateway", "proj_domain") + self.gate.read_val("addr", "thrcre")
        test_data1.update({"提交地址": addr, "接口类型": "create", "quickpay_id": ""})
        for item in test_data1:
            tag_name = test_pay.update_info(item, test_data1[item])
            if tag_name is not None:
                if tag_name.lower() == "select":
                    log.info("选择{}".format(item))
                elif tag_name.lower() == "input":
                    log.info("输入{}".format(item))
        log.info("点击 make payment")
        test_pay.click_submit("make payemnt")
        # 信用卡支付
        domain = re.findall(r"/\w+/\w+\.",
                            self.driver.current_url)[0].replace(".", "")
        for val in payval:
            for domain_conf in val[1].split(","):
                if domain == domain_conf.strip():
                    getattr(Pa.PayAction(self.driver), val[0])(test_data2)
                    break

    def put_pay(self, test_data, quickid):
        """
        quick 3方支付, 支付订单
        :meth test_data: 测试数据 type: dict
        :meth quickid: quickpay_id type: str
        :return:
        """
        test_pay = Sub.SubmitPage(self.driver)
        log.info("----- quick 3方支付, 支付订单 -----")
        log.info("----- 页面标题: %s -----" % self.driver.title)
        addr = self.gate.read_val(
            "gateway", "proj_domain") + self.gate.read_val("addr", "thrpay")
        test_data.update({"提交地址": addr, "接口类型": "pay", "quickpay_id": quickid})
        for item in test_data:
            tag_name = test_pay.update_info(item, test_data[item])
            if tag_name is not None:
                if tag_name.lower() == "select":
                    log.info("选择{}".format(item))
                elif tag_name.lower() == "input":
                    log.info("输入{}".format(item))
        log.info("点击 make payment")
        test_pay.click_submit("make payemnt")
Ejemplo n.º 11
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2018-04-15 09:00:00
# @Author  : Canon
# @Link    : https://www.python.org
# @Version : 3.6.1

from common import basepage
from common import xml_utils
from common.conf_utils import Gateway

# 读取 xml 文件
xml_obj = xml_utils.XmlUtils(Gateway().read_path("xml", "home"))


class HomePage(basepage.Action):
    """
    支付网关首页
    """
    def __init__(self, selenium_driver):
        super().__init__(selenium_driver)
        dict_home = xml_obj.get_attr_by_tag('pageName', 'testpage', 'locator')

        # ----- 定位器,通过元素属性定位元素对象 ----- #
        # 接口名称
        self.link = dict_home['Interface']

    # ----- 页面操作 ----- #
    def open(self, base_url, page_title):
        # 调用page中的_open打开链接
        self._open(base_url, page_title)
Ejemplo n.º 12
0
class TestGateway(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        # 浏览器驱动
        cls.driver = get_driver()
        log.info("----- 启动浏览器 -----")
        # 浏览器最大化
        cls.driver.maximize_window()
        # 获取支付域名列表数据
        cls.payval = Gateway().read_domain("domain")

    @classmethod
    def tearDownClass(cls):
        log.info("----- 关闭浏览器 -----")
        cls.driver.quit()

    def setUp(self):
        pass

    def tearDown(self):
        pass

    @ddt.data(*Exc(Gateway().read_data("pay"), "ThreePay").read_merged())
    def test_threepay(self, test_data):
        # 进入 3方信用卡
        Home(self.driver).enter_postpage("3方信用卡")
        # 提交 3方支付
        Tp.Action(self.driver).put_three(test_data["ThreePay"],
                                         test_data["PayDomain"], self.payval)
        # 断言:3方信用卡交易成功
        res_dict = test_data["TestResult"]
        for key_val in res_dict:
            self.assertEqual(res_dict[key_val],
                             Res.Result(self.driver).back_val(key_val))

    @ddt.data(*Exc(Gateway().read_data("pay"), "ThreeQuick").read_merged())
    def test_threequick(self, test_data):
        # 进入 quick 3方
        Home(self.driver).enter_postpage("quick3方")
        # 创建订单
        Tq.Action(self.driver).put_create(test_data["ThreeQuick"],
                                          test_data["PayDomain"], self.payval)
        # 获取 quickpay_id
        quick_id = Res.Result(self.driver).back_val("quickpay_id")
        # 进入 quick 3方
        Home(self.driver).enter_postpage("quick3方")
        # 支付订单
        Tq.Action(self.driver).put_pay(test_data["ThreeQuick"], quick_id)
        # 断言:quick 3方交易成功
        res_dict = test_data["TestResult"]
        for key_val in res_dict:
            self.assertEqual(res_dict[key_val],
                             Res.Result(self.driver).back_check(key_val))

    @ddt.data(*Exc(Gateway().read_data("pay"), "TwoPay").read_merged())
    def test_two(self, test_data):
        # 进入 2方信用卡
        Home(self.driver).enter_postpage("2方信用卡")
        # 提交 2方支付
        Twp.Action(self.driver).put_two(test_data["TestData"])
        # 断言:2方信用卡交易成功
        res_dict = test_data["TestResult"]
        for key_val in res_dict:
            self.assertEqual(res_dict[key_val],
                             Res.Result(self.driver).back_tag_val(key_val))

    @ddt.data(*Exc(Gateway().read_data("pay"), "TwoQuick").read_merged())
    def test_twoquick(self, test_data):
        # 进入 quick 2方
        Home(self.driver).enter_postpage("quick2方")
        # 创建订单
        Twq.Action(self.driver).put_create(test_data["TestData"])
        # 获取 quickpay_id
        quick_id = Res.Result(self.driver).back_tag_val("quickpay_id")
        self.driver.back()
        # 支付订单
        Twq.Action(self.driver).put_pay(test_data["TestData"], quick_id)
        # 断言:quick 2方交易成功
        res_dict = test_data["TestResult"]
        for key_val in res_dict:
            self.assertEqual(res_dict[key_val],
                             Res.Result(self.driver).back_tag_val(key_val))

    @ddt.data(*Exc(Gateway().read_data("pay"), "TwoHalfPay").read_merged())
    def test_twohalf(self, test_data):
        # 进入 2.5方信用卡
        Home(self.driver).enter_postpage("2.5方支付")
        # 提交 2.5方支付
        Thp.Action(self.driver).put_twohalf(test_data["TestData"])
        # 断言:2.5方信用卡交易成功
        res_dict = test_data["TestResult"]
        for key_val in res_dict:
            self.assertEqual(res_dict[key_val],
                             Res.Result(self.driver).back_val(key_val))

    @unittest.skip("正式环境没有这个接口, 跳过此用例")
    @ddt.data(*Exc(Gateway().read_data("pay"), "TwoHalfQuick").read_merged())
    def test_twohalfquick(self, test_data):
        # 进入 quick 2.5方
        Home(self.driver).enter_postpage("quick2.5方")
        # 创建订单
        Thq.Action(self.driver).put_create(test_data["TestData"])
        # 获取 quickpay_id
        quick_id = Res.Result(self.driver).back_val("quickpay_id")
        self.driver.back()
        # 支付订单
        Thq.Action(self.driver).put_pay(test_data["TestData"], quick_id)
        # 断言:quick 2.5方交易成功
        res_dict = test_data["TestResult"]
        for key_val in res_dict:
            self.assertEqual(res_dict[key_val],
                             Res.Result(self.driver).back_tag_val(key_val))

    @ddt.data(*Exc(Gateway().read_data("moto"), "Moto").read_merged())
    def test_moto(self, test_data):
        # 进入 moto
        Home(self.driver).enter_postpage("MOTO")
        # moto 测试
        Mo.Action(self.driver).moto(test_data["TestData"])
        # 断言:MoTo 交易成功
        res_dict = test_data["TestResult"]
        for key_val in res_dict:
            self.assertEqual(res_dict[key_val],
                             Res.Result(self.driver).back_tag_val(key_val))

    @ddt.data(*Exc(Gateway().read_data("pay"), "SendTrade").read_merged())
    def test_send_trade(self, test_data):
        # 进入创建订单接口
        Home(self.driver).enter_postpage("创建订单接口")
        # 创建订单
        St.Action(self.driver).create_trade(test_data["ThreePay"])
        # 断言:创建订单成功
        res_dict = test_data["CreateResult"]
        for key_val in res_dict:
            self.assertEqual(res_dict[key_val],
                             Res.Result(self.driver).back_tag_val(key_val))
        pay_url = Res.Result(self.driver).back_tag_val("pay_url")
        # 支付订单
        St.Action(self.driver).pay_trade(test_data["PayDomain"], pay_url,
                                         self.payval)
        # 断言:创建订单支付成功
        res_dict = test_data["TestResult"]
        for key_val in res_dict:
            self.assertEqual(res_dict[key_val],
                             Res.Result(self.driver).back_val(key_val))