美文网首页
python selenium ddt 数据驱动测试(八)

python selenium ddt 数据驱动测试(八)

作者: Canon_2020 | 来源:发表于2019-06-06 08:12 被阅读0次

6、测试用例

test_gateway.py

#!/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

import re
import unittest
import ddt
from common.browser import get_driver
from common.excel_utils import ExcelUtils as Exc
from common.logger import Log
from common.conf_utils import Gateway
from action.gateway import pay as Pa
from action.gateway import threepay as Tp
from action.gateway import threequick as Tq
from action.gateway import twopay as Twp
from action.gateway import twoquick as Twq
from action.gateway import twohalfpay as Thp
from action.gateway import twohalfquick as Thq
from action.gateway import result as Res
from action.home.gateway import Home

# 日志
log = Log()


@ddt.ddt
class TestGateway(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        # 浏览器驱动
        cls.driver = get_driver()
        log.info("----- 启动浏览器 -----")
        # 浏览器最大化
        cls.driver.maximize_window()
        # 测试地址
        cls.addr = "http://xxx/test"
        # 接口类型
        cls.create = "3"
        cls.pay = "2"

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

    def setUp(self):
        # 获取支付域名列表数据
        self.payval = Gateway().read_domain("domain")

    def tearDown(self):
        pass

    @ddt.data(*Exc(Gateway().read_path("xlsx", "threepay"), "PayPage").list_in_dict())
    def test_threepay(self, test_data):
        # 进入 测试
        Home(self.driver).enter_three()
        # 提交 3方支付
        addr_thr = self.addr + Gateway().read_val("addr", "thr")
        Tp.Action(self.driver).put_three(addr_thr, test_data["终端ID"][:6], test_data["终端ID"])
        # 信用卡支付
        domain = re.findall(r"/\w+/\w+\.", self.driver.current_url)[0].replace(".", "")
        for val in self.payval:
            for domain_conf in val[1].split(","):
                if domain == domain_conf.strip():
                    getattr(Pa.PayAction(self.driver), val[0])(test_data)
                    break
        # 断言:测试结果与预期结果对比
        self.assertEqual(test_data['payment_details'], Res.Back(self.driver).back_datails())
        self.assertEqual(test_data['payment_status'], Res.Back(self.driver).back_status())


if __name__ == "__main__":
    unittest.main()

7、测试报告

基于 common 公共方法的 HTMLTestRunner.py 生成测试报告

相关文章

网友评论

      本文标题:python selenium ddt 数据驱动测试(八)

      本文链接:https://www.haomeiwen.com/subject/qbuxlqtx.html